elm-pages 3.0.0-beta.3 → 3.0.0-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/codegen/{elm-pages-codegen.js → elm-pages-codegen.cjs} +2864 -2589
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmi +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateData.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/Pages-Review-DeadCodeEliminateDataTest.elmo +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1327 -122
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/Runner.elm.js +15295 -13271
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/dead-code-review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
- package/generator/dead-code-review/elm.json +8 -6
- package/generator/dead-code-review/src/Pages/Review/DeadCodeEliminateData.elm +59 -10
- package/generator/dead-code-review/tests/Pages/Review/DeadCodeEliminateDataTest.elm +52 -36
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/d.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/i.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm-stuff/0.19.1/o.dat +0 -0
- package/generator/review/elm-stuff/tests-0.19.1/elm.json +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/Reporter.elm.js +1327 -122
- package/generator/review/elm-stuff/tests-0.19.1/js/Runner.elm.js +14621 -12637
- package/generator/review/elm-stuff/tests-0.19.1/js/node_runner.js +1 -1
- package/generator/review/elm-stuff/tests-0.19.1/js/node_supervisor.js +4 -4
- package/generator/review/elm.json +8 -8
- package/generator/src/RouteBuilder.elm +113 -107
- package/generator/src/SharedTemplate.elm +3 -2
- package/generator/src/SiteConfig.elm +3 -2
- package/generator/src/basepath-middleware.js +3 -3
- package/generator/src/build.js +123 -87
- package/generator/src/cli.js +256 -77
- package/generator/src/codegen.js +29 -27
- package/generator/src/compatibility-key.js +3 -0
- package/generator/src/compile-elm.js +25 -25
- package/generator/src/config.js +39 -0
- package/generator/src/copy-dir.js +2 -2
- package/generator/src/dev-server.js +150 -133
- package/generator/src/dir-helpers.js +9 -26
- package/generator/src/elm-codegen.js +5 -4
- package/generator/src/elm-file-constants.js +2 -3
- package/generator/src/error-formatter.js +12 -11
- package/generator/src/file-helpers.js +3 -4
- package/generator/src/generate-template-module-connector.js +23 -22
- package/generator/src/init.js +9 -8
- package/generator/src/pre-render-html.js +39 -28
- package/generator/src/render-test.js +109 -0
- package/generator/src/render-worker.js +25 -28
- package/generator/src/render.js +322 -142
- package/generator/src/request-cache.js +252 -163
- package/generator/src/rewrite-client-elm-json.js +5 -5
- package/generator/src/rewrite-elm-json.js +7 -7
- package/generator/src/route-codegen-helpers.js +16 -31
- package/generator/src/seo-renderer.js +12 -7
- package/generator/src/vite-utils.js +77 -0
- package/generator/static-code/hmr.js +79 -13
- package/generator/template/app/Api.elm +6 -5
- package/generator/template/app/Effect.elm +123 -0
- package/generator/template/app/ErrorPage.elm +37 -6
- package/generator/template/app/Route/Index.elm +17 -10
- package/generator/template/app/Shared.elm +24 -47
- package/generator/template/app/Site.elm +19 -6
- package/generator/template/app/View.elm +1 -8
- package/generator/template/elm-tooling.json +0 -3
- package/generator/template/elm.json +34 -25
- package/generator/template/package.json +10 -4
- package/package.json +23 -22
- package/src/ApiRoute.elm +199 -61
- package/src/BackendTask/Custom.elm +325 -0
- package/src/BackendTask/Env.elm +90 -0
- package/src/{DataSource → BackendTask}/File.elm +128 -43
- package/src/{DataSource → BackendTask}/Glob.elm +136 -125
- package/src/BackendTask/Http.elm +673 -0
- package/src/{DataSource → BackendTask}/Internal/Glob.elm +1 -1
- package/src/BackendTask/Internal/Request.elm +28 -0
- package/src/BackendTask/Random.elm +79 -0
- package/src/BackendTask/Time.elm +47 -0
- package/src/BackendTask.elm +537 -0
- package/src/FatalError.elm +89 -0
- package/src/Form/Field.elm +21 -9
- package/src/Form/FieldView.elm +94 -14
- package/src/Form.elm +275 -400
- package/src/Head.elm +237 -7
- package/src/HtmlPrinter.elm +7 -3
- package/src/Internal/ApiRoute.elm +7 -5
- package/src/PageServerResponse.elm +6 -1
- package/src/Pages/FormState.elm +6 -5
- package/src/Pages/GeneratorProgramConfig.elm +15 -0
- package/src/Pages/Internal/FatalError.elm +5 -0
- package/src/Pages/Internal/Form.elm +21 -1
- package/src/Pages/{Msg.elm → Internal/Msg.elm} +26 -16
- package/src/Pages/Internal/Platform/Cli.elm +507 -763
- package/src/Pages/Internal/Platform/CompatibilityKey.elm +6 -0
- package/src/Pages/Internal/Platform/Effect.elm +1 -2
- package/src/Pages/Internal/Platform/GeneratorApplication.elm +373 -0
- package/src/Pages/Internal/Platform/StaticResponses.elm +73 -270
- package/src/Pages/Internal/Platform/ToJsPayload.elm +4 -7
- package/src/Pages/Internal/Platform.elm +215 -102
- package/src/Pages/Internal/Script.elm +17 -0
- package/src/Pages/Internal/StaticHttpBody.elm +35 -1
- package/src/Pages/Manifest.elm +29 -4
- package/src/Pages/PageUrl.elm +23 -9
- package/src/Pages/ProgramConfig.elm +14 -10
- package/src/Pages/Script.elm +109 -0
- package/src/Pages/SiteConfig.elm +3 -2
- package/src/Pages/StaticHttp/Request.elm +2 -2
- package/src/Pages/StaticHttpRequest.elm +23 -98
- package/src/PagesMsg.elm +92 -0
- package/src/Path.elm +16 -19
- package/src/QueryParams.elm +21 -172
- package/src/RequestsAndPending.elm +8 -19
- package/src/Result/Extra.elm +26 -0
- package/src/Scaffold/Form.elm +484 -0
- package/src/Scaffold/Route.elm +1376 -0
- package/src/Server/Request.elm +43 -37
- package/src/Server/Session.elm +34 -34
- package/src/Server/SetCookie.elm +1 -1
- package/src/Test/Html/Internal/ElmHtml/ToString.elm +8 -9
- package/src/DataSource/Env.elm +0 -38
- package/src/DataSource/Http.elm +0 -446
- package/src/DataSource/Internal/Request.elm +0 -20
- package/src/DataSource/Port.elm +0 -90
- package/src/DataSource.elm +0 -538
- package/src/Pages/Generate.elm +0 -800
package/src/Form.elm
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
module Form exposing
|
|
2
2
|
( Form, HtmlForm, StyledHtmlForm, DoneForm
|
|
3
|
-
, Response
|
|
3
|
+
, Response
|
|
4
4
|
, init
|
|
5
5
|
, field, hiddenField, hiddenKind
|
|
6
6
|
, Context
|
|
7
7
|
, renderHtml, renderStyledHtml
|
|
8
|
-
,
|
|
8
|
+
, withGetMethod, toDynamicFetcher
|
|
9
9
|
, Errors, errorsForField
|
|
10
10
|
, parse, runServerSide, runOneOfServerSide
|
|
11
11
|
, ServerForms(..)
|
|
@@ -23,7 +23,7 @@ module Form exposing
|
|
|
23
23
|
- Showing validation errors on the client-side
|
|
24
24
|
- Receiving a form submission on the server-side
|
|
25
25
|
- Using the exact same client-side validations on the server-side
|
|
26
|
-
- Letting you run server-only Validations with
|
|
26
|
+
- Letting you run server-only Validations with BackendTask's (things like checking for a unique username)
|
|
27
27
|
|
|
28
28
|
Because elm-pages is a framework, it has its own internal Model and Msg's. That means you, the user,
|
|
29
29
|
can offload some of the responsibility to elm-pages and build an interactive form with real-time
|
|
@@ -64,7 +64,7 @@ them into a type and/or errors.
|
|
|
64
64
|
|
|
65
65
|
Totally customizable. Uses [`Form.FieldView`](Form-FieldView) to render all of the fields declared.
|
|
66
66
|
|
|
67
|
-
import
|
|
67
|
+
import BackendTask exposing (BackendTask)
|
|
68
68
|
import ErrorPage exposing (ErrorPage)
|
|
69
69
|
import Form
|
|
70
70
|
import Form.Field as Field
|
|
@@ -176,15 +176,14 @@ Totally customizable. Uses [`Form.FieldView`](Form-FieldView) to render all of t
|
|
|
176
176
|
{ title = "Sign Up"
|
|
177
177
|
, body =
|
|
178
178
|
[ form
|
|
179
|
-
|> Form.
|
|
180
|
-
|> Form.renderHtml [] Nothing app ()
|
|
179
|
+
|> Form.renderHtml "login" [] Nothing app ()
|
|
181
180
|
]
|
|
182
181
|
}
|
|
183
182
|
|
|
184
183
|
|
|
185
184
|
### Step 3 - Handle Server-Side Form Submissions
|
|
186
185
|
|
|
187
|
-
action : RouteParams -> Request.Parser (
|
|
186
|
+
action : RouteParams -> Request.Parser (BackendTask (Response ActionData ErrorPage))
|
|
188
187
|
action routeParams =
|
|
189
188
|
Request.formData [ signupForm ]
|
|
190
189
|
|> Request.map
|
|
@@ -192,8 +191,8 @@ Totally customizable. Uses [`Form.FieldView`](Form-FieldView) to render all of t
|
|
|
192
191
|
case signupResult of
|
|
193
192
|
Ok newUser ->
|
|
194
193
|
newUser
|
|
195
|
-
|>
|
|
196
|
-
|>
|
|
194
|
+
|> myCreateUserBackendTask
|
|
195
|
+
|> BackendTask.map
|
|
197
196
|
(\() ->
|
|
198
197
|
-- redirect to the home page
|
|
199
198
|
-- after successful sign-up
|
|
@@ -202,12 +201,12 @@ Totally customizable. Uses [`Form.FieldView`](Form-FieldView) to render all of t
|
|
|
202
201
|
|
|
203
202
|
Err _ ->
|
|
204
203
|
Route.redirectTo Route.Login
|
|
205
|
-
|>
|
|
204
|
+
|> BackendTask.succeed
|
|
206
205
|
)
|
|
207
206
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
myCreateUserBackendTask : BackendTask ()
|
|
208
|
+
myCreateUserBackendTask =
|
|
209
|
+
BackendTask.fail
|
|
211
210
|
"TODO - make a database call to create a new user"
|
|
212
211
|
|
|
213
212
|
|
|
@@ -234,7 +233,7 @@ Totally customizable. Uses [`Form.FieldView`](Form-FieldView) to render all of t
|
|
|
234
233
|
|
|
235
234
|
@docs renderHtml, renderStyledHtml
|
|
236
235
|
|
|
237
|
-
@docs
|
|
236
|
+
@docs withGetMethod, toDynamicFetcher
|
|
238
237
|
|
|
239
238
|
|
|
240
239
|
## Showing Errors
|
|
@@ -267,12 +266,13 @@ Totally customizable. Uses [`Form.FieldView`](Form-FieldView) to render all of t
|
|
|
267
266
|
|
|
268
267
|
-}
|
|
269
268
|
|
|
270
|
-
import
|
|
269
|
+
import BackendTask exposing (BackendTask)
|
|
271
270
|
import Dict exposing (Dict)
|
|
271
|
+
import FatalError exposing (FatalError)
|
|
272
272
|
import Form.Field as Field exposing (Field(..))
|
|
273
273
|
import Form.FieldStatus as FieldStatus exposing (FieldStatus)
|
|
274
274
|
import Form.FieldView
|
|
275
|
-
import Form.Validation
|
|
275
|
+
import Form.Validation exposing (Combined)
|
|
276
276
|
import Html exposing (Html)
|
|
277
277
|
import Html.Attributes as Attr
|
|
278
278
|
import Html.Lazy
|
|
@@ -280,22 +280,13 @@ import Html.Styled
|
|
|
280
280
|
import Html.Styled.Attributes as StyledAttr
|
|
281
281
|
import Html.Styled.Lazy
|
|
282
282
|
import Pages.FormState as Form exposing (FormState)
|
|
283
|
-
import Pages.Internal.Form exposing (Validation(..))
|
|
284
|
-
import Pages.Msg
|
|
283
|
+
import Pages.Internal.Form exposing (Validation(..), unwrapResponse)
|
|
284
|
+
import Pages.Internal.Msg
|
|
285
285
|
import Pages.Transition exposing (Transition(..))
|
|
286
|
+
import PagesMsg exposing (PagesMsg)
|
|
286
287
|
import Path exposing (Path)
|
|
287
288
|
|
|
288
289
|
|
|
289
|
-
|
|
290
|
-
--{-| -}
|
|
291
|
-
--type
|
|
292
|
-
-- ParseResult error decoded
|
|
293
|
-
-- -- TODO parse into both errors AND a decoded value
|
|
294
|
-
-- = Success decoded
|
|
295
|
-
-- | DecodedWithErrors (Dict String (List error)) decoded
|
|
296
|
-
-- | DecodeFailure (Dict String (List error))
|
|
297
|
-
|
|
298
|
-
|
|
299
290
|
{-| -}
|
|
300
291
|
initFormState : FormState
|
|
301
292
|
initFormState =
|
|
@@ -314,9 +305,14 @@ type alias Context error data =
|
|
|
314
305
|
|
|
315
306
|
|
|
316
307
|
{-| -}
|
|
317
|
-
init : combineAndView -> Form String combineAndView data
|
|
308
|
+
init : combineAndView -> Form String combineAndView data msg
|
|
318
309
|
init combineAndView =
|
|
319
|
-
Form
|
|
310
|
+
Form
|
|
311
|
+
{ submitStrategy = TransitionStrategy
|
|
312
|
+
, method = Post
|
|
313
|
+
, onSubmit = Nothing
|
|
314
|
+
}
|
|
315
|
+
[]
|
|
320
316
|
(\_ _ ->
|
|
321
317
|
{ result = Dict.empty
|
|
322
318
|
, combineAndView = combineAndView
|
|
@@ -332,28 +328,36 @@ dynamic :
|
|
|
332
328
|
->
|
|
333
329
|
Form
|
|
334
330
|
error
|
|
335
|
-
{ combine : Validation error parsed named constraints1
|
|
331
|
+
{ combine : Form.Validation.Validation error parsed named constraints1
|
|
336
332
|
, view : subView
|
|
337
333
|
}
|
|
338
334
|
data
|
|
335
|
+
msg
|
|
339
336
|
)
|
|
340
337
|
->
|
|
341
338
|
Form
|
|
342
339
|
error
|
|
343
340
|
--((decider -> Validation error parsed named) -> combined)
|
|
344
|
-
({ combine : decider -> Validation error parsed named constraints1
|
|
341
|
+
({ combine : decider -> Form.Validation.Validation error parsed named constraints1
|
|
345
342
|
, view : decider -> subView
|
|
346
343
|
}
|
|
347
344
|
-> combineAndView
|
|
348
345
|
)
|
|
349
346
|
data
|
|
347
|
+
msg
|
|
350
348
|
->
|
|
351
349
|
Form
|
|
352
350
|
error
|
|
353
351
|
combineAndView
|
|
354
352
|
data
|
|
353
|
+
msg
|
|
355
354
|
dynamic forms formBuilder =
|
|
356
|
-
Form
|
|
355
|
+
Form
|
|
356
|
+
{ submitStrategy = TransitionStrategy
|
|
357
|
+
, method = Post
|
|
358
|
+
, onSubmit = Nothing
|
|
359
|
+
}
|
|
360
|
+
[]
|
|
357
361
|
(\maybeData formState ->
|
|
358
362
|
let
|
|
359
363
|
toParser :
|
|
@@ -365,7 +369,7 @@ dynamic forms formBuilder =
|
|
|
365
369
|
}
|
|
366
370
|
toParser decider =
|
|
367
371
|
case forms decider of
|
|
368
|
-
Form _ parseFn _ ->
|
|
372
|
+
Form _ _ parseFn _ ->
|
|
369
373
|
-- TODO need to include hidden form fields from `definitions` (should they be automatically rendered? Does that mean the view type needs to be hardcoded?)
|
|
370
374
|
parseFn maybeData formState
|
|
371
375
|
|
|
@@ -383,7 +387,7 @@ dynamic forms formBuilder =
|
|
|
383
387
|
}
|
|
384
388
|
newThing =
|
|
385
389
|
case formBuilder of
|
|
386
|
-
Form _ parseFn _ ->
|
|
390
|
+
Form _ _ parseFn _ ->
|
|
387
391
|
parseFn maybeData formState
|
|
388
392
|
|
|
389
393
|
arg : { combine : decider -> Validation error parsed named constraints1, view : decider -> subView }
|
|
@@ -502,10 +506,10 @@ Use [`Form.Field`](Form-Field) to define the field and its validations.
|
|
|
502
506
|
field :
|
|
503
507
|
String
|
|
504
508
|
-> Field error parsed data kind constraints
|
|
505
|
-
-> Form error (Validation.Field error parsed kind -> combineAndView) data
|
|
506
|
-
-> Form error combineAndView data
|
|
507
|
-
field name (Field fieldParser kind) (Form definitions parseFn toInitialValues) =
|
|
508
|
-
Form
|
|
509
|
+
-> Form error (Form.Validation.Field error parsed kind -> combineAndView) data msg
|
|
510
|
+
-> Form error combineAndView data msg
|
|
511
|
+
field name (Field fieldParser kind) (Form renderOptions definitions parseFn toInitialValues) =
|
|
512
|
+
Form renderOptions
|
|
509
513
|
(( name, RegularField )
|
|
510
514
|
:: definitions
|
|
511
515
|
)
|
|
@@ -521,7 +525,7 @@ field name (Field fieldParser kind) (Form definitions parseFn toInitialValues) =
|
|
|
521
525
|
( Just info.value, info.status )
|
|
522
526
|
|
|
523
527
|
Nothing ->
|
|
524
|
-
( Maybe.map2 (|>) maybeData fieldParser.initialValue, FieldStatus.NotVisited )
|
|
528
|
+
( Maybe.map2 (|>) maybeData fieldParser.initialValue |> Maybe.andThen identity, FieldStatus.NotVisited )
|
|
525
529
|
|
|
526
530
|
thing : Pages.Internal.Form.ViewField kind
|
|
527
531
|
thing =
|
|
@@ -530,13 +534,13 @@ field name (Field fieldParser kind) (Form definitions parseFn toInitialValues) =
|
|
|
530
534
|
, kind = ( kind, fieldParser.properties )
|
|
531
535
|
}
|
|
532
536
|
|
|
533
|
-
parsedField : Validation.Field error parsed kind
|
|
537
|
+
parsedField : Form.Validation.Field error parsed kind
|
|
534
538
|
parsedField =
|
|
535
539
|
Pages.Internal.Form.Validation (Just thing) (Just name) ( maybeParsed, Dict.empty )
|
|
536
540
|
|
|
537
541
|
myFn :
|
|
538
542
|
{ result : Dict String (List error)
|
|
539
|
-
, combineAndView : Validation.Field error parsed kind -> combineAndView
|
|
543
|
+
, combineAndView : Form.Validation.Field error parsed kind -> combineAndView
|
|
540
544
|
, isMatchCandidate : Bool
|
|
541
545
|
}
|
|
542
546
|
->
|
|
@@ -546,7 +550,7 @@ field name (Field fieldParser kind) (Form definitions parseFn toInitialValues) =
|
|
|
546
550
|
}
|
|
547
551
|
myFn soFar =
|
|
548
552
|
let
|
|
549
|
-
validationField : Validation.Field error parsed kind
|
|
553
|
+
validationField : Form.Validation.Field error parsed kind
|
|
550
554
|
validationField =
|
|
551
555
|
parsedField
|
|
552
556
|
in
|
|
@@ -600,10 +604,10 @@ You define the field's validations the same way as for `field`, with the
|
|
|
600
604
|
hiddenField :
|
|
601
605
|
String
|
|
602
606
|
-> Field error parsed data kind constraints
|
|
603
|
-
-> Form error (Validation.Field error parsed Form.FieldView.Hidden -> combineAndView) data
|
|
604
|
-
-> Form error combineAndView data
|
|
605
|
-
hiddenField name (Field fieldParser _) (Form definitions parseFn toInitialValues) =
|
|
606
|
-
Form
|
|
607
|
+
-> Form error (Form.Validation.Field error parsed Form.FieldView.Hidden -> combineAndView) data msg
|
|
608
|
+
-> Form error combineAndView data msg
|
|
609
|
+
hiddenField name (Field fieldParser _) (Form options definitions parseFn toInitialValues) =
|
|
610
|
+
Form options
|
|
607
611
|
(( name, HiddenField )
|
|
608
612
|
:: definitions
|
|
609
613
|
)
|
|
@@ -618,7 +622,7 @@ hiddenField name (Field fieldParser _) (Form definitions parseFn toInitialValues
|
|
|
618
622
|
( Just info.value, info.status )
|
|
619
623
|
|
|
620
624
|
Nothing ->
|
|
621
|
-
( Maybe.map2 (|>) maybeData fieldParser.initialValue, FieldStatus.NotVisited )
|
|
625
|
+
( Maybe.map2 (|>) maybeData fieldParser.initialValue |> Maybe.andThen identity, FieldStatus.NotVisited )
|
|
622
626
|
|
|
623
627
|
thing : Pages.Internal.Form.ViewField Form.FieldView.Hidden
|
|
624
628
|
thing =
|
|
@@ -627,13 +631,13 @@ hiddenField name (Field fieldParser _) (Form definitions parseFn toInitialValues
|
|
|
627
631
|
, kind = ( Form.FieldView.Hidden, fieldParser.properties )
|
|
628
632
|
}
|
|
629
633
|
|
|
630
|
-
parsedField : Validation.Field error parsed Form.FieldView.Hidden
|
|
634
|
+
parsedField : Form.Validation.Field error parsed Form.FieldView.Hidden
|
|
631
635
|
parsedField =
|
|
632
636
|
Pages.Internal.Form.Validation (Just thing) (Just name) ( maybeParsed, Dict.empty )
|
|
633
637
|
|
|
634
638
|
myFn :
|
|
635
639
|
{ result : Dict String (List error)
|
|
636
|
-
, combineAndView : Validation.Field error parsed Form.FieldView.Hidden -> combineAndView
|
|
640
|
+
, combineAndView : Form.Validation.Field error parsed Form.FieldView.Hidden -> combineAndView
|
|
637
641
|
, isMatchCandidate : Bool
|
|
638
642
|
}
|
|
639
643
|
->
|
|
@@ -643,7 +647,7 @@ hiddenField name (Field fieldParser _) (Form definitions parseFn toInitialValues
|
|
|
643
647
|
}
|
|
644
648
|
myFn soFar =
|
|
645
649
|
let
|
|
646
|
-
validationField : Validation.Field error parsed Form.FieldView.Hidden
|
|
650
|
+
validationField : Form.Validation.Field error parsed Form.FieldView.Hidden
|
|
647
651
|
validationField =
|
|
648
652
|
parsedField
|
|
649
653
|
in
|
|
@@ -674,18 +678,20 @@ hiddenField name (Field fieldParser _) (Form definitions parseFn toInitialValues
|
|
|
674
678
|
toServerForm :
|
|
675
679
|
Form
|
|
676
680
|
error
|
|
677
|
-
{ combine : Validation error combined kind constraints
|
|
681
|
+
{ combine : Form.Validation.Validation error combined kind constraints
|
|
678
682
|
, view : viewFn
|
|
679
683
|
}
|
|
680
684
|
data
|
|
685
|
+
msg
|
|
681
686
|
->
|
|
682
687
|
Form
|
|
683
688
|
error
|
|
684
|
-
{ combine : Validation error (
|
|
689
|
+
{ combine : Form.Validation.Validation error (BackendTask FatalError (Form.Validation.Validation error combined kind constraints)) kind constraints
|
|
685
690
|
, view : viewFn
|
|
686
691
|
}
|
|
687
692
|
data
|
|
688
|
-
|
|
693
|
+
msg
|
|
694
|
+
toServerForm (Form options a b c) =
|
|
689
695
|
let
|
|
690
696
|
mappedB :
|
|
691
697
|
Maybe data
|
|
@@ -694,7 +700,7 @@ toServerForm (Form a b c) =
|
|
|
694
700
|
{ result : Dict String (List error)
|
|
695
701
|
, isMatchCandidate : Bool
|
|
696
702
|
, combineAndView :
|
|
697
|
-
{ combine : Validation error (
|
|
703
|
+
{ combine : Form.Validation.Validation error (BackendTask FatalError (Form.Validation.Validation error combined kind constraints)) kind constraints
|
|
698
704
|
, view : viewFn
|
|
699
705
|
}
|
|
700
706
|
}
|
|
@@ -705,29 +711,29 @@ toServerForm (Form a b c) =
|
|
|
705
711
|
, combineAndView =
|
|
706
712
|
{ combine =
|
|
707
713
|
thing.combineAndView.combine
|
|
708
|
-
|>
|
|
709
|
-
|> Validation.succeed2
|
|
714
|
+
|> BackendTask.succeed
|
|
715
|
+
|> Form.Validation.succeed2
|
|
710
716
|
, view = thing.combineAndView.view
|
|
711
717
|
}
|
|
712
718
|
, isMatchCandidate = thing.isMatchCandidate
|
|
713
719
|
}
|
|
714
720
|
)
|
|
715
721
|
in
|
|
716
|
-
Form a mappedB c
|
|
722
|
+
Form options a mappedB c
|
|
717
723
|
|
|
718
724
|
|
|
719
725
|
{-| -}
|
|
720
726
|
hiddenKind :
|
|
721
727
|
( String, String )
|
|
722
728
|
-> error
|
|
723
|
-
-> Form error combineAndView data
|
|
724
|
-
-> Form error combineAndView data
|
|
725
|
-
hiddenKind ( name, value ) error_ (Form definitions parseFn toInitialValues) =
|
|
729
|
+
-> Form error combineAndView data msg
|
|
730
|
+
-> Form error combineAndView data msg
|
|
731
|
+
hiddenKind ( name, value ) error_ (Form options definitions parseFn toInitialValues) =
|
|
726
732
|
let
|
|
727
733
|
(Field fieldParser _) =
|
|
728
734
|
Field.exactValue value error_
|
|
729
735
|
in
|
|
730
|
-
Form
|
|
736
|
+
Form options
|
|
731
737
|
(( name, HiddenField )
|
|
732
738
|
:: definitions
|
|
733
739
|
)
|
|
@@ -744,6 +750,7 @@ hiddenKind ( name, value ) error_ (Form definitions parseFn toInitialValues) =
|
|
|
744
750
|
|
|
745
751
|
Nothing ->
|
|
746
752
|
Maybe.map2 (|>) maybeData fieldParser.initialValue
|
|
753
|
+
|> Maybe.andThen identity
|
|
747
754
|
|
|
748
755
|
myFn :
|
|
749
756
|
{ result : Dict String (List error)
|
|
@@ -784,10 +791,10 @@ type Errors error
|
|
|
784
791
|
|
|
785
792
|
|
|
786
793
|
{-| -}
|
|
787
|
-
errorsForField : Validation.Field error parsed kind -> Errors error -> List error
|
|
794
|
+
errorsForField : Form.Validation.Field error parsed kind -> Errors error -> List error
|
|
788
795
|
errorsForField field_ (Errors errorsDict) =
|
|
789
796
|
errorsDict
|
|
790
|
-
|> Dict.get (Validation.fieldName field_)
|
|
797
|
+
|> Dict.get (Form.Validation.fieldName field_)
|
|
791
798
|
|> Maybe.withDefault []
|
|
792
799
|
|
|
793
800
|
|
|
@@ -797,13 +804,13 @@ type alias AppContext app actionData =
|
|
|
797
804
|
| --, sharedData : Shared.Data
|
|
798
805
|
--, routeParams : routeParams
|
|
799
806
|
path : Path
|
|
807
|
+
, action : Maybe actionData
|
|
800
808
|
|
|
801
|
-
--, action : Maybe action
|
|
802
809
|
--, submit :
|
|
803
810
|
-- { fields : List ( String, String ), headers : List ( String, String ) }
|
|
804
811
|
-- -> Pages.Fetcher.Fetcher (Result Http.Error action)
|
|
805
812
|
, transition : Maybe Transition
|
|
806
|
-
, fetchers : Dict String (Pages.Transition.FetcherState actionData)
|
|
813
|
+
, fetchers : Dict String (Pages.Transition.FetcherState (Maybe actionData))
|
|
807
814
|
, pageFormState :
|
|
808
815
|
Dict String { fields : Dict String { value : String, status : FieldStatus }, submitAttempted : Bool }
|
|
809
816
|
}
|
|
@@ -844,9 +851,9 @@ parse :
|
|
|
844
851
|
String
|
|
845
852
|
-> AppContext app actionData
|
|
846
853
|
-> data
|
|
847
|
-
-> Form error { info | combine : Validation error parsed named constraints } data
|
|
854
|
+
-> Form error { info | combine : Form.Validation.Validation error parsed named constraints } data msg
|
|
848
855
|
-> ( Maybe parsed, Dict String (List error) )
|
|
849
|
-
parse formId app data (Form _ parser _) =
|
|
856
|
+
parse formId app data (Form _ _ parser _) =
|
|
850
857
|
-- TODO Get transition context from `app` so you can check if the current form is being submitted
|
|
851
858
|
-- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
|
|
852
859
|
let
|
|
@@ -883,9 +890,9 @@ insertIfNonempty key values dict =
|
|
|
883
890
|
{-| -}
|
|
884
891
|
runServerSide :
|
|
885
892
|
List ( String, String )
|
|
886
|
-
-> Form error (Validation error parsed kind constraints) data
|
|
893
|
+
-> Form error (Form.Validation.Validation error parsed kind constraints) data msg
|
|
887
894
|
-> ( Bool, ( Maybe parsed, Dict String (List error) ) )
|
|
888
|
-
runServerSide rawFormData (Form _ parser _) =
|
|
895
|
+
runServerSide rawFormData (Form _ _ parser _) =
|
|
889
896
|
let
|
|
890
897
|
parsed :
|
|
891
898
|
{ result : Dict String (List error)
|
|
@@ -978,257 +985,112 @@ runOneOfServerSideHelp rawFormData firstFoundErrors (ServerForms parsers) =
|
|
|
978
985
|
|
|
979
986
|
{-| -}
|
|
980
987
|
renderHtml :
|
|
981
|
-
List (Html.Attribute (Pages.Msg.Msg msg))
|
|
982
|
-
->
|
|
983
|
-
Maybe
|
|
984
|
-
{ fields : List ( String, String )
|
|
985
|
-
, errors : Dict String (List error)
|
|
986
|
-
}
|
|
987
|
-
-> AppContext app actionData
|
|
988
|
-
-> data
|
|
989
|
-
->
|
|
990
|
-
FinalForm
|
|
991
|
-
error
|
|
992
|
-
(Validation error parsed named constraints)
|
|
993
|
-
data
|
|
994
|
-
(Context error data
|
|
995
|
-
-> List (Html (Pages.Msg.Msg msg))
|
|
996
|
-
)
|
|
997
|
-
msg
|
|
998
|
-
-> Html (Pages.Msg.Msg msg)
|
|
999
|
-
renderHtml attrs maybe app data (FinalForm options a b c) =
|
|
1000
|
-
Html.Lazy.lazy6 renderHelper attrs maybe options app data (FormInternal a b c)
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
{-| -}
|
|
1004
|
-
type FinalForm error parsed data view userMsg
|
|
1005
|
-
= FinalForm
|
|
1006
|
-
(RenderOptions userMsg)
|
|
1007
|
-
(List ( String, FieldDefinition ))
|
|
1008
|
-
(Maybe data
|
|
1009
|
-
-> FormState
|
|
1010
|
-
->
|
|
1011
|
-
{ result :
|
|
1012
|
-
( parsed
|
|
1013
|
-
, Dict String (List error)
|
|
1014
|
-
)
|
|
1015
|
-
, isMatchCandidate : Bool
|
|
1016
|
-
, view : view
|
|
1017
|
-
}
|
|
1018
|
-
)
|
|
1019
|
-
(data -> List ( String, String ))
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
{-| -}
|
|
1023
|
-
toDynamicFetcher :
|
|
1024
988
|
String
|
|
989
|
+
-> List (Html.Attribute (PagesMsg msg))
|
|
990
|
+
-> (actionData -> Maybe (Response error))
|
|
991
|
+
-> AppContext app actionData
|
|
992
|
+
-> input
|
|
1025
993
|
->
|
|
1026
994
|
Form
|
|
1027
995
|
error
|
|
1028
|
-
{ combine : Validation error parsed
|
|
1029
|
-
, view : Context error
|
|
1030
|
-
}
|
|
1031
|
-
data
|
|
1032
|
-
->
|
|
1033
|
-
FinalForm
|
|
1034
|
-
error
|
|
1035
|
-
(Validation error parsed field constraints)
|
|
1036
|
-
data
|
|
1037
|
-
(Context error data -> view)
|
|
1038
|
-
userMsg
|
|
1039
|
-
toDynamicFetcher name (Form a b c) =
|
|
1040
|
-
let
|
|
1041
|
-
options : { submitStrategy : SubmitStrategy, method : Method, name : Maybe String, onSubmit : Maybe a }
|
|
1042
|
-
options =
|
|
1043
|
-
{ submitStrategy = FetcherStrategy
|
|
1044
|
-
, method = Post
|
|
1045
|
-
, name = Just name
|
|
1046
|
-
, onSubmit = Nothing
|
|
996
|
+
{ combine : Form.Validation.Validation error parsed named constraints
|
|
997
|
+
, view : Context error input -> List (Html (PagesMsg msg))
|
|
1047
998
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
{ result : Dict String (List error)
|
|
1054
|
-
, isMatchCandidate : Bool
|
|
1055
|
-
, combineAndView :
|
|
1056
|
-
{ combine : Validation error parsed field constraints
|
|
1057
|
-
, view : Context error data -> view
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
)
|
|
1061
|
-
->
|
|
1062
|
-
(Maybe data
|
|
1063
|
-
-> FormState
|
|
1064
|
-
->
|
|
1065
|
-
{ result :
|
|
1066
|
-
( Validation error parsed field constraints
|
|
1067
|
-
, Dict String (List error)
|
|
1068
|
-
)
|
|
1069
|
-
, isMatchCandidate : Bool
|
|
1070
|
-
, view : Context error data -> view
|
|
1071
|
-
}
|
|
1072
|
-
)
|
|
1073
|
-
transformB rawB =
|
|
1074
|
-
\maybeData formState ->
|
|
1075
|
-
let
|
|
1076
|
-
foo :
|
|
1077
|
-
{ result : Dict String (List error)
|
|
1078
|
-
, isMatchCandidate : Bool
|
|
1079
|
-
, combineAndView :
|
|
1080
|
-
{ combine : Validation error parsed field constraints
|
|
1081
|
-
, view : Context error data -> view
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
foo =
|
|
1085
|
-
rawB maybeData formState
|
|
1086
|
-
in
|
|
1087
|
-
{ result = ( foo.combineAndView.combine, foo.result )
|
|
1088
|
-
, view = foo.combineAndView.view
|
|
1089
|
-
, isMatchCandidate = foo.isMatchCandidate
|
|
1090
|
-
}
|
|
1091
|
-
in
|
|
1092
|
-
FinalForm options a (transformB b) c
|
|
999
|
+
input
|
|
1000
|
+
msg
|
|
1001
|
+
-> Html (PagesMsg msg)
|
|
1002
|
+
renderHtml formId attrs accessResponse app data form =
|
|
1003
|
+
Html.Lazy.lazy6 renderHelper formId attrs accessResponse app data form
|
|
1093
1004
|
|
|
1094
1005
|
|
|
1095
1006
|
{-| -}
|
|
1096
|
-
|
|
1097
|
-
|
|
1007
|
+
toDynamicFetcher :
|
|
1008
|
+
Form
|
|
1009
|
+
error
|
|
1010
|
+
{ combine : Form.Validation.Validation error parsed field constraints
|
|
1011
|
+
, view : Context error data -> view
|
|
1012
|
+
}
|
|
1013
|
+
data
|
|
1014
|
+
userMsg
|
|
1098
1015
|
->
|
|
1099
1016
|
Form
|
|
1100
1017
|
error
|
|
1101
|
-
{ combine : Validation error parsed field constraints
|
|
1018
|
+
{ combine : Form.Validation.Validation error parsed field constraints
|
|
1102
1019
|
, view : Context error data -> view
|
|
1103
1020
|
}
|
|
1104
1021
|
data
|
|
1105
|
-
->
|
|
1106
|
-
FinalForm
|
|
1107
|
-
error
|
|
1108
|
-
(Validation error parsed field constraints)
|
|
1109
|
-
data
|
|
1110
|
-
(Context error data -> view)
|
|
1111
1022
|
userMsg
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
options : { submitStrategy : SubmitStrategy, method : Method, name : Maybe String, onSubmit : Maybe a }
|
|
1115
|
-
options =
|
|
1116
|
-
{ submitStrategy = TransitionStrategy
|
|
1117
|
-
, method = Post
|
|
1118
|
-
, name = Just name
|
|
1119
|
-
, onSubmit = Nothing
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
transformB :
|
|
1123
|
-
(Maybe data
|
|
1124
|
-
-> FormState
|
|
1125
|
-
->
|
|
1126
|
-
{ result : Dict String (List error)
|
|
1127
|
-
, isMatchCandidate : Bool
|
|
1128
|
-
, combineAndView :
|
|
1129
|
-
{ combine : Validation error parsed field constraints
|
|
1130
|
-
, view : Context error data -> view
|
|
1131
|
-
}
|
|
1132
|
-
}
|
|
1133
|
-
)
|
|
1134
|
-
->
|
|
1135
|
-
(Maybe data
|
|
1136
|
-
-> FormState
|
|
1137
|
-
->
|
|
1138
|
-
{ result :
|
|
1139
|
-
( Validation error parsed field constraints
|
|
1140
|
-
, Dict String (List error)
|
|
1141
|
-
)
|
|
1142
|
-
, isMatchCandidate : Bool
|
|
1143
|
-
, view : Context error data -> view
|
|
1144
|
-
}
|
|
1145
|
-
)
|
|
1146
|
-
transformB rawB =
|
|
1147
|
-
\maybeData formState ->
|
|
1148
|
-
let
|
|
1149
|
-
foo :
|
|
1150
|
-
{ result : Dict String (List error)
|
|
1151
|
-
, isMatchCandidate : Bool
|
|
1152
|
-
, combineAndView :
|
|
1153
|
-
{ combine : Validation error parsed field constraints
|
|
1154
|
-
, view : Context error data -> view
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
foo =
|
|
1158
|
-
rawB maybeData formState
|
|
1159
|
-
in
|
|
1160
|
-
{ result = ( foo.combineAndView.combine, foo.result )
|
|
1161
|
-
, view = foo.combineAndView.view
|
|
1162
|
-
, isMatchCandidate = foo.isMatchCandidate
|
|
1163
|
-
}
|
|
1164
|
-
in
|
|
1165
|
-
FinalForm options a (transformB b) c
|
|
1023
|
+
toDynamicFetcher (Form renderOptions a b c) =
|
|
1024
|
+
Form { renderOptions | submitStrategy = FetcherStrategy } a b c
|
|
1166
1025
|
|
|
1167
1026
|
|
|
1168
1027
|
{-| -}
|
|
1169
|
-
withGetMethod :
|
|
1170
|
-
withGetMethod (
|
|
1171
|
-
|
|
1028
|
+
withGetMethod : Form error combineAndView input userMsg -> Form error combineAndView input userMsg
|
|
1029
|
+
withGetMethod (Form options a b c) =
|
|
1030
|
+
Form { options | method = Get } a b c
|
|
1172
1031
|
|
|
1173
1032
|
|
|
1174
1033
|
{-| -}
|
|
1175
|
-
withOnSubmit : ({ fields : List ( String, String ) } -> userMsg) ->
|
|
1176
|
-
withOnSubmit onSubmit (
|
|
1177
|
-
|
|
1034
|
+
withOnSubmit : ({ fields : List ( String, String ) } -> userMsg) -> Form error combineAndView input oldMsg -> Form error combineAndView input userMsg
|
|
1035
|
+
withOnSubmit onSubmit (Form options a b c) =
|
|
1036
|
+
Form
|
|
1037
|
+
{ onSubmit = Just onSubmit
|
|
1038
|
+
, submitStrategy = options.submitStrategy
|
|
1039
|
+
, method = options.method
|
|
1040
|
+
}
|
|
1041
|
+
a
|
|
1042
|
+
b
|
|
1043
|
+
c
|
|
1178
1044
|
|
|
1179
1045
|
|
|
1180
1046
|
{-| -}
|
|
1181
1047
|
renderStyledHtml :
|
|
1182
|
-
|
|
1183
|
-
->
|
|
1184
|
-
|
|
1185
|
-
{ fields : List ( String, String )
|
|
1186
|
-
, errors : Dict String (List error)
|
|
1187
|
-
}
|
|
1048
|
+
String
|
|
1049
|
+
-> List (Html.Styled.Attribute (PagesMsg msg))
|
|
1050
|
+
-> (actionData -> Maybe (Response error))
|
|
1188
1051
|
-> AppContext app actionData
|
|
1189
|
-
->
|
|
1052
|
+
-> input
|
|
1190
1053
|
->
|
|
1191
|
-
|
|
1054
|
+
Form
|
|
1192
1055
|
error
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
)
|
|
1056
|
+
{ combine : Form.Validation.Validation error parsed field constraints
|
|
1057
|
+
, view : Context error input -> List (Html.Styled.Html (PagesMsg msg))
|
|
1058
|
+
}
|
|
1059
|
+
input
|
|
1198
1060
|
msg
|
|
1199
|
-
-> Html.Styled.Html (
|
|
1200
|
-
renderStyledHtml attrs
|
|
1201
|
-
Html.Styled.Lazy.lazy6 renderStyledHelper attrs
|
|
1061
|
+
-> Html.Styled.Html (PagesMsg msg)
|
|
1062
|
+
renderStyledHtml formId attrs accessResponse app data form =
|
|
1063
|
+
Html.Styled.Lazy.lazy6 renderStyledHelper formId attrs accessResponse app data form
|
|
1202
1064
|
|
|
1203
1065
|
|
|
1204
1066
|
{-| -}
|
|
1205
|
-
type Response error
|
|
1206
|
-
|
|
1207
|
-
{ fields : List ( String, String )
|
|
1208
|
-
, errors : Dict String (List error)
|
|
1209
|
-
}
|
|
1067
|
+
type alias Response error =
|
|
1068
|
+
Pages.Internal.Form.Response error
|
|
1210
1069
|
|
|
1211
1070
|
|
|
1212
1071
|
renderHelper :
|
|
1213
|
-
|
|
1214
|
-
->
|
|
1215
|
-
|
|
1216
|
-
{ fields : List ( String, String )
|
|
1217
|
-
, errors : Dict String (List error)
|
|
1218
|
-
}
|
|
1219
|
-
-> RenderOptions msg
|
|
1072
|
+
String
|
|
1073
|
+
-> List (Html.Attribute (PagesMsg msg))
|
|
1074
|
+
-> (actionData -> Maybe (Response error))
|
|
1220
1075
|
-> AppContext app actionData
|
|
1221
1076
|
-> data
|
|
1222
|
-
->
|
|
1223
|
-
|
|
1224
|
-
|
|
1077
|
+
->
|
|
1078
|
+
Form
|
|
1079
|
+
error
|
|
1080
|
+
{ combine : Form.Validation.Validation error parsed named constraints
|
|
1081
|
+
, view : Context error data -> List (Html (PagesMsg msg))
|
|
1082
|
+
}
|
|
1083
|
+
data
|
|
1084
|
+
msg
|
|
1085
|
+
-> Html (PagesMsg msg)
|
|
1086
|
+
renderHelper formId attrs accessResponse formState data ((Form options _ _ _) as form) =
|
|
1225
1087
|
-- TODO Get transition context from `app` so you can check if the current form is being submitted
|
|
1226
1088
|
-- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
|
|
1227
1089
|
let
|
|
1228
|
-
{
|
|
1229
|
-
helperValues toHiddenInput
|
|
1090
|
+
{ hiddenInputs, children, isValid } =
|
|
1091
|
+
helperValues formId toHiddenInput accessResponse formState data form
|
|
1230
1092
|
|
|
1231
|
-
toHiddenInput : List (Html.Attribute (
|
|
1093
|
+
toHiddenInput : List (Html.Attribute (PagesMsg msg)) -> Html (PagesMsg msg)
|
|
1232
1094
|
toHiddenInput hiddenAttrs =
|
|
1233
1095
|
Html.input hiddenAttrs []
|
|
1234
1096
|
in
|
|
@@ -1241,10 +1103,10 @@ renderHelper attrs maybe options formState data form =
|
|
|
1241
1103
|
, Attr.action (Path.toAbsolute formState.path)
|
|
1242
1104
|
, case options.submitStrategy of
|
|
1243
1105
|
FetcherStrategy ->
|
|
1244
|
-
Pages.Msg.fetcherOnSubmit options.onSubmit formId (\_ -> isValid)
|
|
1106
|
+
Pages.Internal.Msg.fetcherOnSubmit options.onSubmit formId (\_ -> isValid)
|
|
1245
1107
|
|
|
1246
1108
|
TransitionStrategy ->
|
|
1247
|
-
Pages.Msg.submitIfValid formId (\_ -> isValid)
|
|
1109
|
+
Pages.Internal.Msg.submitIfValid options.onSubmit formId (\_ -> isValid)
|
|
1248
1110
|
]
|
|
1249
1111
|
++ attrs
|
|
1250
1112
|
)
|
|
@@ -1252,25 +1114,28 @@ renderHelper attrs maybe options formState data form =
|
|
|
1252
1114
|
|
|
1253
1115
|
|
|
1254
1116
|
renderStyledHelper :
|
|
1255
|
-
|
|
1256
|
-
->
|
|
1257
|
-
|
|
1258
|
-
{ fields : List ( String, String )
|
|
1259
|
-
, errors : Dict String (List error)
|
|
1260
|
-
}
|
|
1261
|
-
-> RenderOptions msg
|
|
1117
|
+
String
|
|
1118
|
+
-> List (Html.Styled.Attribute (PagesMsg msg))
|
|
1119
|
+
-> (actionData -> Maybe (Response error))
|
|
1262
1120
|
-> AppContext app actionData
|
|
1263
1121
|
-> data
|
|
1264
|
-
->
|
|
1265
|
-
|
|
1266
|
-
|
|
1122
|
+
->
|
|
1123
|
+
Form
|
|
1124
|
+
error
|
|
1125
|
+
{ combine : Form.Validation.Validation error parsed field constraints
|
|
1126
|
+
, view : Context error data -> List (Html.Styled.Html (PagesMsg msg))
|
|
1127
|
+
}
|
|
1128
|
+
data
|
|
1129
|
+
msg
|
|
1130
|
+
-> Html.Styled.Html (PagesMsg msg)
|
|
1131
|
+
renderStyledHelper formId attrs accessResponse formState data ((Form options _ _ _) as form) =
|
|
1267
1132
|
-- TODO Get transition context from `app` so you can check if the current form is being submitted
|
|
1268
1133
|
-- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
|
|
1269
1134
|
let
|
|
1270
|
-
{
|
|
1271
|
-
helperValues toHiddenInput
|
|
1135
|
+
{ hiddenInputs, children, isValid } =
|
|
1136
|
+
helperValues formId toHiddenInput accessResponse formState data form
|
|
1272
1137
|
|
|
1273
|
-
toHiddenInput : List (Html.Attribute (
|
|
1138
|
+
toHiddenInput : List (Html.Attribute (PagesMsg msg)) -> Html.Styled.Html (PagesMsg msg)
|
|
1274
1139
|
toHiddenInput hiddenAttrs =
|
|
1275
1140
|
Html.Styled.input (hiddenAttrs |> List.map StyledAttr.fromUnstyled) []
|
|
1276
1141
|
in
|
|
@@ -1282,11 +1147,11 @@ renderStyledHelper attrs maybe options formState data form =
|
|
|
1282
1147
|
, case options.submitStrategy of
|
|
1283
1148
|
FetcherStrategy ->
|
|
1284
1149
|
StyledAttr.fromUnstyled <|
|
|
1285
|
-
Pages.Msg.fetcherOnSubmit options.onSubmit formId (\_ -> isValid)
|
|
1150
|
+
Pages.Internal.Msg.fetcherOnSubmit options.onSubmit formId (\_ -> isValid)
|
|
1286
1151
|
|
|
1287
1152
|
TransitionStrategy ->
|
|
1288
1153
|
StyledAttr.fromUnstyled <|
|
|
1289
|
-
Pages.Msg.submitIfValid formId (\_ -> isValid)
|
|
1154
|
+
Pages.Internal.Msg.submitIfValid options.onSubmit formId (\_ -> isValid)
|
|
1290
1155
|
]
|
|
1291
1156
|
++ attrs
|
|
1292
1157
|
)
|
|
@@ -1294,28 +1159,33 @@ renderStyledHelper attrs maybe options formState data form =
|
|
|
1294
1159
|
|
|
1295
1160
|
|
|
1296
1161
|
helperValues :
|
|
1297
|
-
|
|
1298
|
-
->
|
|
1299
|
-
|
|
1300
|
-
{ fields : List ( String, String )
|
|
1301
|
-
, errors : Dict String (List error)
|
|
1302
|
-
}
|
|
1303
|
-
-> RenderOptions msg
|
|
1162
|
+
String
|
|
1163
|
+
-> (List (Html.Attribute (PagesMsg msg)) -> view)
|
|
1164
|
+
-> (actionData -> Maybe (Response error))
|
|
1304
1165
|
-> AppContext app actionData
|
|
1305
1166
|
-> data
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1167
|
+
->
|
|
1168
|
+
Form
|
|
1169
|
+
error
|
|
1170
|
+
{ combine : Form.Validation.Validation error parsed field constraints
|
|
1171
|
+
, view : Context error data -> List view
|
|
1172
|
+
}
|
|
1173
|
+
data
|
|
1174
|
+
msg
|
|
1175
|
+
-> { hiddenInputs : List view, children : List view, isValid : Bool }
|
|
1176
|
+
helperValues formId toHiddenInput accessResponse formState data (Form _ fieldDefinitions parser toInitialValues) =
|
|
1310
1177
|
let
|
|
1311
|
-
formId : String
|
|
1312
|
-
formId =
|
|
1313
|
-
options.name |> Maybe.withDefault ""
|
|
1314
|
-
|
|
1315
1178
|
initialValues : Dict String Form.FieldState
|
|
1316
1179
|
initialValues =
|
|
1317
1180
|
toInitialValues data
|
|
1318
|
-
|> List.
|
|
1181
|
+
|> List.filterMap
|
|
1182
|
+
(\( key, maybeValue ) ->
|
|
1183
|
+
maybeValue
|
|
1184
|
+
|> Maybe.map
|
|
1185
|
+
(\value ->
|
|
1186
|
+
( key, { value = value, status = FieldStatus.NotVisited } )
|
|
1187
|
+
)
|
|
1188
|
+
)
|
|
1319
1189
|
|> Dict.fromList
|
|
1320
1190
|
|
|
1321
1191
|
part2 : Dict String Form.FieldState
|
|
@@ -1323,7 +1193,8 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
|
|
1323
1193
|
formState.pageFormState
|
|
1324
1194
|
|> Dict.get formId
|
|
1325
1195
|
|> Maybe.withDefault
|
|
1326
|
-
(
|
|
1196
|
+
(formState.action
|
|
1197
|
+
|> Maybe.andThen (accessResponse >> Maybe.map unwrapResponse)
|
|
1327
1198
|
|> Maybe.map
|
|
1328
1199
|
(\{ fields } ->
|
|
1329
1200
|
{ fields =
|
|
@@ -1343,18 +1214,29 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
|
|
1343
1214
|
|> Dict.union part2
|
|
1344
1215
|
|
|
1345
1216
|
parsed :
|
|
1346
|
-
{ result : ( Validation error parsed
|
|
1217
|
+
{ result : ( Form.Validation.Validation error parsed field constraints, Dict String (List error) )
|
|
1347
1218
|
, isMatchCandidate : Bool
|
|
1348
1219
|
, view : Context error data -> List view
|
|
1349
1220
|
}
|
|
1350
1221
|
parsed =
|
|
1222
|
+
{ isMatchCandidate = parsed1.isMatchCandidate
|
|
1223
|
+
, view = parsed1.combineAndView.view
|
|
1224
|
+
, result = ( parsed1.combineAndView.combine, parsed1.result )
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
parsed1 :
|
|
1228
|
+
{ result : Dict String (List error)
|
|
1229
|
+
, isMatchCandidate : Bool
|
|
1230
|
+
, combineAndView : { combine : Form.Validation.Validation error parsed field constraints, view : Context error data -> List view }
|
|
1231
|
+
}
|
|
1232
|
+
parsed1 =
|
|
1351
1233
|
parser (Just data) thisFormState
|
|
1352
1234
|
|
|
1353
|
-
withoutServerErrors : Validation error parsed named constraints
|
|
1235
|
+
withoutServerErrors : Form.Validation.Validation error parsed named constraints
|
|
1354
1236
|
withoutServerErrors =
|
|
1355
1237
|
parsed |> mergeResults
|
|
1356
1238
|
|
|
1357
|
-
withServerErrors : Validation error parsed named constraints
|
|
1239
|
+
withServerErrors : Form.Validation.Validation error parsed named constraints
|
|
1358
1240
|
withServerErrors =
|
|
1359
1241
|
mergeResults
|
|
1360
1242
|
{ parsed
|
|
@@ -1363,8 +1245,8 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
|
|
1363
1245
|
|> Tuple.mapSecond
|
|
1364
1246
|
(\errors1 ->
|
|
1365
1247
|
mergeErrors errors1
|
|
1366
|
-
(
|
|
1367
|
-
|> Maybe.map .errors
|
|
1248
|
+
(formState.action
|
|
1249
|
+
|> Maybe.andThen (accessResponse >> Maybe.map (unwrapResponse >> .errors))
|
|
1368
1250
|
|> Maybe.withDefault Dict.empty
|
|
1369
1251
|
)
|
|
1370
1252
|
)
|
|
@@ -1375,7 +1257,8 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
|
|
1375
1257
|
formState.pageFormState
|
|
1376
1258
|
|> Dict.get formId
|
|
1377
1259
|
|> Maybe.withDefault
|
|
1378
|
-
(
|
|
1260
|
+
(formState.action
|
|
1261
|
+
|> Maybe.andThen (accessResponse >> Maybe.map unwrapResponse)
|
|
1379
1262
|
|> Maybe.map
|
|
1380
1263
|
(\{ fields } ->
|
|
1381
1264
|
{ fields =
|
|
@@ -1398,7 +1281,21 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
|
|
1398
1281
|
|> Errors
|
|
1399
1282
|
, isTransitioning =
|
|
1400
1283
|
-- TODO instead of isTransitioning : Bool, it would be useful to get a custom type with the exact state
|
|
1401
|
-
(formState.fetchers |> Dict.
|
|
1284
|
+
(case formState.fetchers |> Dict.get formId of
|
|
1285
|
+
Just { status } ->
|
|
1286
|
+
case status of
|
|
1287
|
+
Pages.Transition.FetcherComplete _ ->
|
|
1288
|
+
False
|
|
1289
|
+
|
|
1290
|
+
Pages.Transition.FetcherSubmitting ->
|
|
1291
|
+
True
|
|
1292
|
+
|
|
1293
|
+
Pages.Transition.FetcherReloading _ ->
|
|
1294
|
+
True
|
|
1295
|
+
|
|
1296
|
+
Nothing ->
|
|
1297
|
+
False
|
|
1298
|
+
)
|
|
1402
1299
|
|| (case formState.transition of
|
|
1403
1300
|
Just (Submitting formData) ->
|
|
1404
1301
|
formData.id == Just formId
|
|
@@ -1452,21 +1349,21 @@ helperValues toHiddenInput maybe options formState data (FormInternal fieldDefin
|
|
|
1452
1349
|
_ ->
|
|
1453
1350
|
False
|
|
1454
1351
|
in
|
|
1455
|
-
{
|
|
1456
|
-
, hiddenInputs = hiddenInputs
|
|
1352
|
+
{ hiddenInputs = hiddenInputs
|
|
1457
1353
|
, children = children
|
|
1458
1354
|
, isValid = isValid
|
|
1459
1355
|
}
|
|
1460
1356
|
|
|
1461
1357
|
|
|
1462
1358
|
{-| -}
|
|
1463
|
-
type alias DoneForm error parsed data view =
|
|
1359
|
+
type alias DoneForm error parsed data view msg =
|
|
1464
1360
|
Form
|
|
1465
1361
|
error
|
|
1466
1362
|
{ combine : Combined error parsed
|
|
1467
1363
|
, view : Context error data -> view
|
|
1468
1364
|
}
|
|
1469
1365
|
data
|
|
1366
|
+
msg
|
|
1470
1367
|
|
|
1471
1368
|
|
|
1472
1369
|
{-| -}
|
|
@@ -1474,9 +1371,10 @@ type alias HtmlForm error parsed input msg =
|
|
|
1474
1371
|
Form
|
|
1475
1372
|
error
|
|
1476
1373
|
{ combine : Combined error parsed
|
|
1477
|
-
, view : Context error input -> List (Html (
|
|
1374
|
+
, view : Context error input -> List (Html (PagesMsg msg))
|
|
1478
1375
|
}
|
|
1479
1376
|
input
|
|
1377
|
+
msg
|
|
1480
1378
|
|
|
1481
1379
|
|
|
1482
1380
|
{-| -}
|
|
@@ -1487,6 +1385,7 @@ type ServerForms error parsed
|
|
|
1487
1385
|
error
|
|
1488
1386
|
(Combined error parsed)
|
|
1489
1387
|
Never
|
|
1388
|
+
Never
|
|
1490
1389
|
)
|
|
1491
1390
|
)
|
|
1492
1391
|
|
|
@@ -1498,31 +1397,42 @@ initCombined :
|
|
|
1498
1397
|
Form
|
|
1499
1398
|
error
|
|
1500
1399
|
{ combineAndView
|
|
1501
|
-
| combine : Validation error parsed kind constraints
|
|
1400
|
+
| combine : Form.Validation.Validation error parsed kind constraints
|
|
1502
1401
|
}
|
|
1503
1402
|
input
|
|
1403
|
+
msg
|
|
1504
1404
|
-> ServerForms error combined
|
|
1505
|
-
initCombined mapFn
|
|
1506
|
-
ServerForms
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1405
|
+
initCombined mapFn form =
|
|
1406
|
+
ServerForms [ normalizeServerForm mapFn form ]
|
|
1407
|
+
|
|
1408
|
+
|
|
1409
|
+
normalizeServerForm :
|
|
1410
|
+
(parsed -> combined)
|
|
1411
|
+
-> Form error { combineAndView | combine : Form.Validation.Validation error parsed kind constraints } input msg
|
|
1412
|
+
-> Form error (Combined error combined) Never Never
|
|
1413
|
+
normalizeServerForm mapFn (Form options _ parseFn _) =
|
|
1414
|
+
Form
|
|
1415
|
+
{ onSubmit = Nothing
|
|
1416
|
+
, submitStrategy = options.submitStrategy
|
|
1417
|
+
, method = options.method
|
|
1418
|
+
}
|
|
1419
|
+
[]
|
|
1420
|
+
(\_ formState ->
|
|
1421
|
+
let
|
|
1422
|
+
parsed :
|
|
1423
|
+
{ result : Dict String (List error)
|
|
1424
|
+
, isMatchCandidate : Bool
|
|
1425
|
+
, combineAndView : { combineAndView | combine : Form.Validation.Validation error parsed kind constraints }
|
|
1426
|
+
}
|
|
1427
|
+
parsed =
|
|
1428
|
+
parseFn Nothing formState
|
|
1429
|
+
in
|
|
1430
|
+
{ result = parsed.result
|
|
1431
|
+
, combineAndView = parsed.combineAndView.combine |> Form.Validation.mapWithNever mapFn
|
|
1432
|
+
, isMatchCandidate = parsed.isMatchCandidate
|
|
1433
|
+
}
|
|
1434
|
+
)
|
|
1435
|
+
(\_ -> [])
|
|
1526
1436
|
|
|
1527
1437
|
|
|
1528
1438
|
{-| -}
|
|
@@ -1532,33 +1442,14 @@ combine :
|
|
|
1532
1442
|
Form
|
|
1533
1443
|
error
|
|
1534
1444
|
{ combineAndView
|
|
1535
|
-
| combine : Validation error parsed kind constraints
|
|
1445
|
+
| combine : Form.Validation.Validation error parsed kind constraints
|
|
1536
1446
|
}
|
|
1537
1447
|
input
|
|
1448
|
+
msg
|
|
1538
1449
|
-> ServerForms error combined
|
|
1539
1450
|
-> ServerForms error combined
|
|
1540
|
-
combine mapFn
|
|
1541
|
-
ServerForms
|
|
1542
|
-
(serverForms
|
|
1543
|
-
++ [ Form []
|
|
1544
|
-
(\_ formState ->
|
|
1545
|
-
let
|
|
1546
|
-
foo :
|
|
1547
|
-
{ result : Dict String (List error)
|
|
1548
|
-
, isMatchCandidate : Bool
|
|
1549
|
-
, combineAndView : { combineAndView | combine : Validation error parsed kind constraints }
|
|
1550
|
-
}
|
|
1551
|
-
foo =
|
|
1552
|
-
parseFn Nothing formState
|
|
1553
|
-
in
|
|
1554
|
-
{ result = foo.result
|
|
1555
|
-
, combineAndView = foo.combineAndView.combine |> Validation.mapWithNever mapFn
|
|
1556
|
-
, isMatchCandidate = foo.isMatchCandidate
|
|
1557
|
-
}
|
|
1558
|
-
)
|
|
1559
|
-
(\_ -> [])
|
|
1560
|
-
]
|
|
1561
|
-
)
|
|
1451
|
+
combine mapFn form (ServerForms serverForms) =
|
|
1452
|
+
ServerForms (serverForms ++ [ normalizeServerForm mapFn form ])
|
|
1562
1453
|
|
|
1563
1454
|
|
|
1564
1455
|
{-| -}
|
|
@@ -1568,12 +1459,13 @@ initCombinedServer :
|
|
|
1568
1459
|
Form
|
|
1569
1460
|
error
|
|
1570
1461
|
{ combineAndView
|
|
1571
|
-
| combine : Combined error (
|
|
1462
|
+
| combine : Combined error (BackendTask backendTaskError (Form.Validation.Validation error parsed kind constraints))
|
|
1572
1463
|
}
|
|
1573
1464
|
input
|
|
1574
|
-
|
|
1465
|
+
msg
|
|
1466
|
+
-> ServerForms error (BackendTask backendTaskError (Form.Validation.Validation error combined kind constraints))
|
|
1575
1467
|
initCombinedServer mapFn serverForms =
|
|
1576
|
-
initCombined (
|
|
1468
|
+
initCombined (BackendTask.map (Form.Validation.map mapFn)) serverForms
|
|
1577
1469
|
|
|
1578
1470
|
|
|
1579
1471
|
{-| -}
|
|
@@ -1584,13 +1476,14 @@ combineServer :
|
|
|
1584
1476
|
error
|
|
1585
1477
|
{ combineAndView
|
|
1586
1478
|
| combine :
|
|
1587
|
-
Combined error (
|
|
1479
|
+
Combined error (BackendTask backendTaskError (Form.Validation.Validation error parsed kind constraints))
|
|
1588
1480
|
}
|
|
1589
1481
|
input
|
|
1590
|
-
|
|
1591
|
-
-> ServerForms error (
|
|
1482
|
+
msg
|
|
1483
|
+
-> ServerForms error (BackendTask backendTaskError (Form.Validation.Validation error combined kind constraints))
|
|
1484
|
+
-> ServerForms error (BackendTask backendTaskError (Form.Validation.Validation error combined kind constraints))
|
|
1592
1485
|
combineServer mapFn a b =
|
|
1593
|
-
combine (
|
|
1486
|
+
combine (BackendTask.map (Form.Validation.map mapFn)) a b
|
|
1594
1487
|
|
|
1595
1488
|
|
|
1596
1489
|
{-| -}
|
|
@@ -1598,33 +1491,16 @@ type alias StyledHtmlForm error parsed data msg =
|
|
|
1598
1491
|
Form
|
|
1599
1492
|
error
|
|
1600
1493
|
{ combine : Combined error parsed
|
|
1601
|
-
, view : Context error data -> List (Html.Styled.Html (
|
|
1494
|
+
, view : Context error data -> List (Html.Styled.Html (PagesMsg msg))
|
|
1602
1495
|
}
|
|
1603
1496
|
data
|
|
1497
|
+
msg
|
|
1604
1498
|
|
|
1605
1499
|
|
|
1606
1500
|
{-| -}
|
|
1607
|
-
type
|
|
1608
|
-
= FormInternal
|
|
1609
|
-
-- TODO for renderCustom, pass them as an argument with all hidden fields that the user must render
|
|
1610
|
-
(List ( String, FieldDefinition ))
|
|
1611
|
-
(Maybe data
|
|
1612
|
-
-> FormState
|
|
1613
|
-
->
|
|
1614
|
-
{ result :
|
|
1615
|
-
( parsed
|
|
1616
|
-
, Dict String (List error)
|
|
1617
|
-
)
|
|
1618
|
-
, isMatchCandidate : Bool
|
|
1619
|
-
, view : view
|
|
1620
|
-
}
|
|
1621
|
-
)
|
|
1622
|
-
(data -> List ( String, String ))
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
{-| -}
|
|
1626
|
-
type Form error combineAndView input
|
|
1501
|
+
type Form error combineAndView input userMsg
|
|
1627
1502
|
= Form
|
|
1503
|
+
(RenderOptions userMsg)
|
|
1628
1504
|
(List ( String, FieldDefinition ))
|
|
1629
1505
|
(Maybe input
|
|
1630
1506
|
-> FormState
|
|
@@ -1634,13 +1510,12 @@ type Form error combineAndView input
|
|
|
1634
1510
|
, combineAndView : combineAndView
|
|
1635
1511
|
}
|
|
1636
1512
|
)
|
|
1637
|
-
(input -> List ( String, String ))
|
|
1513
|
+
(input -> List ( String, Maybe String ))
|
|
1638
1514
|
|
|
1639
1515
|
|
|
1640
1516
|
type alias RenderOptions userMsg =
|
|
1641
1517
|
{ submitStrategy : SubmitStrategy
|
|
1642
1518
|
, method : Method
|
|
1643
|
-
, name : Maybe String
|
|
1644
1519
|
, onSubmit : Maybe ({ fields : List ( String, String ) } -> userMsg)
|
|
1645
1520
|
}
|
|
1646
1521
|
|