elm-pages 3.0.0-beta.27 → 3.0.0-beta.29

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/src/Form.elm CHANGED
@@ -5,7 +5,7 @@ module Form exposing
5
5
  , field, hiddenField, hiddenKind
6
6
  , Context
7
7
  , renderHtml, renderStyledHtml
8
- , FinalForm, withGetMethod, toDynamicTransition, toDynamicFetcher
8
+ , withGetMethod, toDynamicFetcher
9
9
  , Errors, errorsForField
10
10
  , parse, runServerSide, runOneOfServerSide
11
11
  , ServerForms(..)
@@ -176,8 +176,7 @@ 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.toDynamicTransition "login"
180
- |> Form.renderHtml [] Nothing app ()
179
+ |> Form.renderHtml "login" [] Nothing app ()
181
180
  ]
182
181
  }
183
182
 
@@ -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 FinalForm, withGetMethod, toDynamicTransition, toDynamicFetcher
236
+ @docs withGetMethod, toDynamicFetcher
238
237
 
239
238
 
240
239
  ## Showing Errors
@@ -288,16 +287,6 @@ import PagesMsg exposing (PagesMsg)
288
287
  import Path exposing (Path)
289
288
 
290
289
 
291
-
292
- --{-| -}
293
- --type
294
- -- ParseResult error decoded
295
- -- -- TODO parse into both errors AND a decoded value
296
- -- = Success decoded
297
- -- | DecodedWithErrors (Dict String (List error)) decoded
298
- -- | DecodeFailure (Dict String (List error))
299
-
300
-
301
290
  {-| -}
302
291
  initFormState : FormState
303
292
  initFormState =
@@ -316,9 +305,14 @@ type alias Context error data =
316
305
 
317
306
 
318
307
  {-| -}
319
- init : combineAndView -> Form String combineAndView data
308
+ init : combineAndView -> Form String combineAndView data msg
320
309
  init combineAndView =
321
- Form []
310
+ Form
311
+ { submitStrategy = TransitionStrategy
312
+ , method = Post
313
+ , onSubmit = Nothing
314
+ }
315
+ []
322
316
  (\_ _ ->
323
317
  { result = Dict.empty
324
318
  , combineAndView = combineAndView
@@ -338,6 +332,7 @@ dynamic :
338
332
  , view : subView
339
333
  }
340
334
  data
335
+ msg
341
336
  )
342
337
  ->
343
338
  Form
@@ -349,13 +344,20 @@ dynamic :
349
344
  -> combineAndView
350
345
  )
351
346
  data
347
+ msg
352
348
  ->
353
349
  Form
354
350
  error
355
351
  combineAndView
356
352
  data
353
+ msg
357
354
  dynamic forms formBuilder =
358
- Form []
355
+ Form
356
+ { submitStrategy = TransitionStrategy
357
+ , method = Post
358
+ , onSubmit = Nothing
359
+ }
360
+ []
359
361
  (\maybeData formState ->
360
362
  let
361
363
  toParser :
@@ -367,7 +369,7 @@ dynamic forms formBuilder =
367
369
  }
368
370
  toParser decider =
369
371
  case forms decider of
370
- Form _ parseFn _ ->
372
+ Form _ _ parseFn _ ->
371
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?)
372
374
  parseFn maybeData formState
373
375
 
@@ -385,7 +387,7 @@ dynamic forms formBuilder =
385
387
  }
386
388
  newThing =
387
389
  case formBuilder of
388
- Form _ parseFn _ ->
390
+ Form _ _ parseFn _ ->
389
391
  parseFn maybeData formState
390
392
 
391
393
  arg : { combine : decider -> Validation error parsed named constraints1, view : decider -> subView }
@@ -504,10 +506,10 @@ Use [`Form.Field`](Form-Field) to define the field and its validations.
504
506
  field :
505
507
  String
506
508
  -> Field error parsed data kind constraints
507
- -> Form error (Form.Validation.Field error parsed kind -> combineAndView) data
508
- -> Form error combineAndView data
509
- field name (Field fieldParser kind) (Form definitions parseFn toInitialValues) =
510
- 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
511
513
  (( name, RegularField )
512
514
  :: definitions
513
515
  )
@@ -602,10 +604,10 @@ You define the field's validations the same way as for `field`, with the
602
604
  hiddenField :
603
605
  String
604
606
  -> Field error parsed data kind constraints
605
- -> Form error (Form.Validation.Field error parsed Form.FieldView.Hidden -> combineAndView) data
606
- -> Form error combineAndView data
607
- hiddenField name (Field fieldParser _) (Form definitions parseFn toInitialValues) =
608
- 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
609
611
  (( name, HiddenField )
610
612
  :: definitions
611
613
  )
@@ -680,6 +682,7 @@ toServerForm :
680
682
  , view : viewFn
681
683
  }
682
684
  data
685
+ msg
683
686
  ->
684
687
  Form
685
688
  error
@@ -687,7 +690,8 @@ toServerForm :
687
690
  , view : viewFn
688
691
  }
689
692
  data
690
- toServerForm (Form a b c) =
693
+ msg
694
+ toServerForm (Form options a b c) =
691
695
  let
692
696
  mappedB :
693
697
  Maybe data
@@ -715,21 +719,21 @@ toServerForm (Form a b c) =
715
719
  }
716
720
  )
717
721
  in
718
- Form a mappedB c
722
+ Form options a mappedB c
719
723
 
720
724
 
721
725
  {-| -}
722
726
  hiddenKind :
723
727
  ( String, String )
724
728
  -> error
725
- -> Form error combineAndView data
726
- -> Form error combineAndView data
727
- 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) =
728
732
  let
729
733
  (Field fieldParser _) =
730
734
  Field.exactValue value error_
731
735
  in
732
- Form
736
+ Form options
733
737
  (( name, HiddenField )
734
738
  :: definitions
735
739
  )
@@ -847,9 +851,9 @@ parse :
847
851
  String
848
852
  -> AppContext app actionData
849
853
  -> data
850
- -> Form error { info | combine : Form.Validation.Validation error parsed named constraints } data
854
+ -> Form error { info | combine : Form.Validation.Validation error parsed named constraints } data msg
851
855
  -> ( Maybe parsed, Dict String (List error) )
852
- parse formId app data (Form _ parser _) =
856
+ parse formId app data (Form _ _ parser _) =
853
857
  -- TODO Get transition context from `app` so you can check if the current form is being submitted
854
858
  -- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
855
859
  let
@@ -886,9 +890,9 @@ insertIfNonempty key values dict =
886
890
  {-| -}
887
891
  runServerSide :
888
892
  List ( String, String )
889
- -> Form error (Form.Validation.Validation error parsed kind constraints) data
893
+ -> Form error (Form.Validation.Validation error parsed kind constraints) data msg
890
894
  -> ( Bool, ( Maybe parsed, Dict String (List error) ) )
891
- runServerSide rawFormData (Form _ parser _) =
895
+ runServerSide rawFormData (Form _ _ parser _) =
892
896
  let
893
897
  parsed :
894
898
  { result : Dict String (List error)
@@ -981,119 +985,33 @@ runOneOfServerSideHelp rawFormData firstFoundErrors (ServerForms parsers) =
981
985
 
982
986
  {-| -}
983
987
  renderHtml :
984
- List (Html.Attribute (PagesMsg msg))
988
+ String
989
+ -> List (Html.Attribute (PagesMsg msg))
985
990
  -> (actionData -> Maybe (Response error))
986
991
  -> AppContext app actionData
987
- -> data
992
+ -> input
988
993
  ->
989
- FinalForm
994
+ Form
990
995
  error
991
- (Form.Validation.Validation error parsed named constraints)
992
- data
993
- (Context error data
994
- -> List (Html (PagesMsg msg))
995
- )
996
+ { combine : Form.Validation.Validation error parsed named constraints
997
+ , view : Context error input -> List (Html (PagesMsg msg))
998
+ }
999
+ input
996
1000
  msg
997
1001
  -> Html (PagesMsg msg)
998
- renderHtml attrs accessResponse app data (FinalForm options a b c) =
999
- Html.Lazy.lazy6 renderHelper attrs accessResponse options app data (FormInternal a b c)
1000
-
1001
-
1002
- {-| -}
1003
- type FinalForm error parsed data view userMsg
1004
- = FinalForm
1005
- (RenderOptions userMsg)
1006
- (List ( String, FieldDefinition ))
1007
- (Maybe data
1008
- -> FormState
1009
- ->
1010
- { result :
1011
- ( parsed
1012
- , Dict String (List error)
1013
- )
1014
- , isMatchCandidate : Bool
1015
- , view : view
1016
- }
1017
- )
1018
- (data -> List ( String, Maybe String ))
1002
+ renderHtml formId attrs accessResponse app data form =
1003
+ Html.Lazy.lazy6 renderHelper formId attrs accessResponse app data form
1019
1004
 
1020
1005
 
1021
1006
  {-| -}
1022
1007
  toDynamicFetcher :
1023
- String
1024
- ->
1025
- Form
1026
- error
1027
- { combine : Form.Validation.Validation error parsed field constraints
1028
- , view : Context error data -> view
1029
- }
1030
- data
1031
- ->
1032
- FinalForm
1033
- error
1034
- (Form.Validation.Validation error parsed field constraints)
1035
- data
1036
- (Context error data -> view)
1037
- userMsg
1038
- toDynamicFetcher name (Form a b c) =
1039
- let
1040
- options : { submitStrategy : SubmitStrategy, method : Method, name : Maybe String, onSubmit : Maybe a }
1041
- options =
1042
- { submitStrategy = FetcherStrategy
1043
- , method = Post
1044
- , name = Just name
1045
- , onSubmit = Nothing
1046
- }
1047
-
1048
- transformB :
1049
- (Maybe data
1050
- -> FormState
1051
- ->
1052
- { result : Dict String (List error)
1053
- , isMatchCandidate : Bool
1054
- , combineAndView :
1055
- { combine : Validation error parsed field constraints
1056
- , view : Context error data -> view
1057
- }
1058
- }
1059
- )
1060
- ->
1061
- (Maybe data
1062
- -> FormState
1063
- ->
1064
- { result :
1065
- ( Validation error parsed field constraints
1066
- , Dict String (List error)
1067
- )
1068
- , isMatchCandidate : Bool
1069
- , view : Context error data -> view
1070
- }
1071
- )
1072
- transformB rawB =
1073
- \maybeData formState ->
1074
- let
1075
- foo :
1076
- { result : Dict String (List error)
1077
- , isMatchCandidate : Bool
1078
- , combineAndView :
1079
- { combine : Validation error parsed field constraints
1080
- , view : Context error data -> view
1081
- }
1082
- }
1083
- foo =
1084
- rawB maybeData formState
1085
- in
1086
- { result = ( foo.combineAndView.combine, foo.result )
1087
- , view = foo.combineAndView.view
1088
- , isMatchCandidate = foo.isMatchCandidate
1089
- }
1090
- in
1091
- FinalForm options a (transformB b) c
1092
-
1093
-
1094
- {-| -}
1095
- toDynamicTransition :
1096
- String
1008
+ Form
1009
+ error
1010
+ { combine : Form.Validation.Validation error parsed field constraints
1011
+ , view : Context error data -> view
1012
+ }
1013
+ data
1014
+ userMsg
1097
1015
  ->
1098
1016
  Form
1099
1017
  error
@@ -1101,99 +1019,48 @@ toDynamicTransition :
1101
1019
  , view : Context error data -> view
1102
1020
  }
1103
1021
  data
1104
- ->
1105
- FinalForm
1106
- error
1107
- (Form.Validation.Validation error parsed field constraints)
1108
- data
1109
- (Context error data -> view)
1110
1022
  userMsg
1111
- toDynamicTransition name (Form a b c) =
1112
- let
1113
- options : { submitStrategy : SubmitStrategy, method : Method, name : Maybe String, onSubmit : Maybe a }
1114
- options =
1115
- { submitStrategy = TransitionStrategy
1116
- , method = Post
1117
- , name = Just name
1118
- , onSubmit = Nothing
1119
- }
1120
-
1121
- transformB :
1122
- (Maybe data
1123
- -> FormState
1124
- ->
1125
- { result : Dict String (List error)
1126
- , isMatchCandidate : Bool
1127
- , combineAndView :
1128
- { combine : Form.Validation.Validation error parsed field constraints
1129
- , view : Context error data -> view
1130
- }
1131
- }
1132
- )
1133
- ->
1134
- (Maybe data
1135
- -> FormState
1136
- ->
1137
- { result :
1138
- ( Form.Validation.Validation error parsed field constraints
1139
- , Dict String (List error)
1140
- )
1141
- , isMatchCandidate : Bool
1142
- , view : Context error data -> view
1143
- }
1144
- )
1145
- transformB rawB =
1146
- \maybeData formState ->
1147
- let
1148
- foo :
1149
- { result : Dict String (List error)
1150
- , isMatchCandidate : Bool
1151
- , combineAndView :
1152
- { combine : Form.Validation.Validation error parsed field constraints
1153
- , view : Context error data -> view
1154
- }
1155
- }
1156
- foo =
1157
- rawB maybeData formState
1158
- in
1159
- { result = ( foo.combineAndView.combine, foo.result )
1160
- , view = foo.combineAndView.view
1161
- , isMatchCandidate = foo.isMatchCandidate
1162
- }
1163
- in
1164
- FinalForm options a (transformB b) c
1023
+ toDynamicFetcher (Form renderOptions a b c) =
1024
+ Form { renderOptions | submitStrategy = FetcherStrategy } a b c
1165
1025
 
1166
1026
 
1167
1027
  {-| -}
1168
- withGetMethod : FinalForm error parsed data view userMsg -> FinalForm error parsed data view userMsg
1169
- withGetMethod (FinalForm options a b c) =
1170
- FinalForm { options | method = Get } a b c
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
1171
1031
 
1172
1032
 
1173
1033
  {-| -}
1174
- withOnSubmit : ({ fields : List ( String, String ) } -> userMsg) -> FinalForm error parsed data view userMsg -> FinalForm error parsed data view userMsg
1175
- withOnSubmit onSubmit (FinalForm options a b c) =
1176
- FinalForm { options | onSubmit = Just onSubmit } a b c
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
1177
1044
 
1178
1045
 
1179
1046
  {-| -}
1180
1047
  renderStyledHtml :
1181
- List (Html.Styled.Attribute (PagesMsg msg))
1048
+ String
1049
+ -> List (Html.Styled.Attribute (PagesMsg msg))
1182
1050
  -> (actionData -> Maybe (Response error))
1183
1051
  -> AppContext app actionData
1184
- -> data
1052
+ -> input
1185
1053
  ->
1186
- FinalForm
1054
+ Form
1187
1055
  error
1188
- (Form.Validation.Validation error parsed named constraints)
1189
- data
1190
- (Context error data
1191
- -> List (Html.Styled.Html (PagesMsg msg))
1192
- )
1056
+ { combine : Form.Validation.Validation error parsed field constraints
1057
+ , view : Context error input -> List (Html.Styled.Html (PagesMsg msg))
1058
+ }
1059
+ input
1193
1060
  msg
1194
1061
  -> Html.Styled.Html (PagesMsg msg)
1195
- renderStyledHtml attrs accessResponse app data (FinalForm options a b c) =
1196
- Html.Styled.Lazy.lazy6 renderStyledHelper attrs accessResponse options app data (FormInternal a b c)
1062
+ renderStyledHtml formId attrs accessResponse app data form =
1063
+ Html.Styled.Lazy.lazy6 renderStyledHelper formId attrs accessResponse app data form
1197
1064
 
1198
1065
 
1199
1066
  {-| -}
@@ -1202,19 +1069,26 @@ type alias Response error =
1202
1069
 
1203
1070
 
1204
1071
  renderHelper :
1205
- List (Html.Attribute (PagesMsg msg))
1072
+ String
1073
+ -> List (Html.Attribute (PagesMsg msg))
1206
1074
  -> (actionData -> Maybe (Response error))
1207
- -> RenderOptions msg
1208
1075
  -> AppContext app actionData
1209
1076
  -> data
1210
- -> FormInternal error (Form.Validation.Validation error parsed named constraints) data (Context error data -> List (Html (PagesMsg msg)))
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
1211
1085
  -> Html (PagesMsg msg)
1212
- renderHelper attrs accessResponse options formState data form =
1086
+ renderHelper formId attrs accessResponse formState data ((Form options _ _ _) as form) =
1213
1087
  -- TODO Get transition context from `app` so you can check if the current form is being submitted
1214
1088
  -- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
1215
1089
  let
1216
- { formId, hiddenInputs, children, isValid } =
1217
- helperValues toHiddenInput accessResponse options formState data form
1090
+ { hiddenInputs, children, isValid } =
1091
+ helperValues formId toHiddenInput accessResponse formState data form
1218
1092
 
1219
1093
  toHiddenInput : List (Html.Attribute (PagesMsg msg)) -> Html (PagesMsg msg)
1220
1094
  toHiddenInput hiddenAttrs =
@@ -1240,19 +1114,26 @@ renderHelper attrs accessResponse options formState data form =
1240
1114
 
1241
1115
 
1242
1116
  renderStyledHelper :
1243
- List (Html.Styled.Attribute (PagesMsg msg))
1117
+ String
1118
+ -> List (Html.Styled.Attribute (PagesMsg msg))
1244
1119
  -> (actionData -> Maybe (Response error))
1245
- -> RenderOptions msg
1246
1120
  -> AppContext app actionData
1247
1121
  -> data
1248
- -> FormInternal error (Form.Validation.Validation error parsed named constraints) data (Context error data -> List (Html.Styled.Html (PagesMsg msg)))
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
1249
1130
  -> Html.Styled.Html (PagesMsg msg)
1250
- renderStyledHelper attrs accessResponse options formState data form =
1131
+ renderStyledHelper formId attrs accessResponse formState data ((Form options _ _ _) as form) =
1251
1132
  -- TODO Get transition context from `app` so you can check if the current form is being submitted
1252
1133
  -- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
1253
1134
  let
1254
- { formId, hiddenInputs, children, isValid } =
1255
- helperValues toHiddenInput accessResponse options formState data form
1135
+ { hiddenInputs, children, isValid } =
1136
+ helperValues formId toHiddenInput accessResponse formState data form
1256
1137
 
1257
1138
  toHiddenInput : List (Html.Attribute (PagesMsg msg)) -> Html.Styled.Html (PagesMsg msg)
1258
1139
  toHiddenInput hiddenAttrs =
@@ -1278,20 +1159,22 @@ renderStyledHelper attrs accessResponse options formState data form =
1278
1159
 
1279
1160
 
1280
1161
  helperValues :
1281
- (List (Html.Attribute (PagesMsg msg)) -> view)
1162
+ String
1163
+ -> (List (Html.Attribute (PagesMsg msg)) -> view)
1282
1164
  -> (actionData -> Maybe (Response error))
1283
- -> RenderOptions msg
1284
1165
  -> AppContext app actionData
1285
1166
  -> data
1286
- ---> Form error parsed data view
1287
- -> FormInternal error (Form.Validation.Validation error parsed named constraints) data (Context error data -> List view)
1288
- -> { formId : String, hiddenInputs : List view, children : List view, isValid : Bool }
1289
- helperValues toHiddenInput accessResponse options formState data (FormInternal fieldDefinitions parser toInitialValues) =
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) =
1290
1177
  let
1291
- formId : String
1292
- formId =
1293
- options.name |> Maybe.withDefault ""
1294
-
1295
1178
  initialValues : Dict String Form.FieldState
1296
1179
  initialValues =
1297
1180
  toInitialValues data
@@ -1331,11 +1214,22 @@ helperValues toHiddenInput accessResponse options formState data (FormInternal f
1331
1214
  |> Dict.union part2
1332
1215
 
1333
1216
  parsed :
1334
- { result : ( Form.Validation.Validation error parsed named constraints, Dict String (List error) )
1217
+ { result : ( Form.Validation.Validation error parsed field constraints, Dict String (List error) )
1335
1218
  , isMatchCandidate : Bool
1336
1219
  , view : Context error data -> List view
1337
1220
  }
1338
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 =
1339
1233
  parser (Just data) thisFormState
1340
1234
 
1341
1235
  withoutServerErrors : Form.Validation.Validation error parsed named constraints
@@ -1455,21 +1349,21 @@ helperValues toHiddenInput accessResponse options formState data (FormInternal f
1455
1349
  _ ->
1456
1350
  False
1457
1351
  in
1458
- { formId = formId
1459
- , hiddenInputs = hiddenInputs
1352
+ { hiddenInputs = hiddenInputs
1460
1353
  , children = children
1461
1354
  , isValid = isValid
1462
1355
  }
1463
1356
 
1464
1357
 
1465
1358
  {-| -}
1466
- type alias DoneForm error parsed data view =
1359
+ type alias DoneForm error parsed data view msg =
1467
1360
  Form
1468
1361
  error
1469
1362
  { combine : Combined error parsed
1470
1363
  , view : Context error data -> view
1471
1364
  }
1472
1365
  data
1366
+ msg
1473
1367
 
1474
1368
 
1475
1369
  {-| -}
@@ -1480,6 +1374,7 @@ type alias HtmlForm error parsed input msg =
1480
1374
  , view : Context error input -> List (Html (PagesMsg msg))
1481
1375
  }
1482
1376
  input
1377
+ msg
1483
1378
 
1484
1379
 
1485
1380
  {-| -}
@@ -1490,6 +1385,7 @@ type ServerForms error parsed
1490
1385
  error
1491
1386
  (Combined error parsed)
1492
1387
  Never
1388
+ Never
1493
1389
  )
1494
1390
  )
1495
1391
 
@@ -1504,28 +1400,39 @@ initCombined :
1504
1400
  | combine : Form.Validation.Validation error parsed kind constraints
1505
1401
  }
1506
1402
  input
1403
+ msg
1507
1404
  -> ServerForms error combined
1508
- initCombined mapFn (Form _ parseFn _) =
1509
- ServerForms
1510
- [ Form
1511
- []
1512
- (\_ formState ->
1513
- let
1514
- foo :
1515
- { result : Dict String (List error)
1516
- , isMatchCandidate : Bool
1517
- , combineAndView : { combineAndView | combine : Form.Validation.Validation error parsed kind constraints }
1518
- }
1519
- foo =
1520
- parseFn Nothing formState
1521
- in
1522
- { result = foo.result
1523
- , combineAndView = foo.combineAndView.combine |> Form.Validation.mapWithNever mapFn
1524
- , isMatchCandidate = foo.isMatchCandidate
1525
- }
1526
- )
1527
- (\_ -> [])
1528
- ]
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
+ (\_ -> [])
1529
1436
 
1530
1437
 
1531
1438
  {-| -}
@@ -1538,30 +1445,11 @@ combine :
1538
1445
  | combine : Form.Validation.Validation error parsed kind constraints
1539
1446
  }
1540
1447
  input
1448
+ msg
1541
1449
  -> ServerForms error combined
1542
1450
  -> ServerForms error combined
1543
- combine mapFn (Form _ parseFn _) (ServerForms serverForms) =
1544
- ServerForms
1545
- (serverForms
1546
- ++ [ Form []
1547
- (\_ formState ->
1548
- let
1549
- foo :
1550
- { result : Dict String (List error)
1551
- , isMatchCandidate : Bool
1552
- , combineAndView : { combineAndView | combine : Form.Validation.Validation error parsed kind constraints }
1553
- }
1554
- foo =
1555
- parseFn Nothing formState
1556
- in
1557
- { result = foo.result
1558
- , combineAndView = foo.combineAndView.combine |> Form.Validation.mapWithNever mapFn
1559
- , isMatchCandidate = foo.isMatchCandidate
1560
- }
1561
- )
1562
- (\_ -> [])
1563
- ]
1564
- )
1451
+ combine mapFn form (ServerForms serverForms) =
1452
+ ServerForms (serverForms ++ [ normalizeServerForm mapFn form ])
1565
1453
 
1566
1454
 
1567
1455
  {-| -}
@@ -1574,6 +1462,7 @@ initCombinedServer :
1574
1462
  | combine : Combined error (BackendTask backendTaskError (Form.Validation.Validation error parsed kind constraints))
1575
1463
  }
1576
1464
  input
1465
+ msg
1577
1466
  -> ServerForms error (BackendTask backendTaskError (Form.Validation.Validation error combined kind constraints))
1578
1467
  initCombinedServer mapFn serverForms =
1579
1468
  initCombined (BackendTask.map (Form.Validation.map mapFn)) serverForms
@@ -1590,6 +1479,7 @@ combineServer :
1590
1479
  Combined error (BackendTask backendTaskError (Form.Validation.Validation error parsed kind constraints))
1591
1480
  }
1592
1481
  input
1482
+ msg
1593
1483
  -> ServerForms error (BackendTask backendTaskError (Form.Validation.Validation error combined kind constraints))
1594
1484
  -> ServerForms error (BackendTask backendTaskError (Form.Validation.Validation error combined kind constraints))
1595
1485
  combineServer mapFn a b =
@@ -1604,30 +1494,13 @@ type alias StyledHtmlForm error parsed data msg =
1604
1494
  , view : Context error data -> List (Html.Styled.Html (PagesMsg msg))
1605
1495
  }
1606
1496
  data
1497
+ msg
1607
1498
 
1608
1499
 
1609
1500
  {-| -}
1610
- type FormInternal error parsed data view
1611
- = FormInternal
1612
- -- TODO for renderCustom, pass them as an argument with all hidden fields that the user must render
1613
- (List ( String, FieldDefinition ))
1614
- (Maybe data
1615
- -> FormState
1616
- ->
1617
- { result :
1618
- ( parsed
1619
- , Dict String (List error)
1620
- )
1621
- , isMatchCandidate : Bool
1622
- , view : view
1623
- }
1624
- )
1625
- (data -> List ( String, Maybe String ))
1626
-
1627
-
1628
- {-| -}
1629
- type Form error combineAndView input
1501
+ type Form error combineAndView input userMsg
1630
1502
  = Form
1503
+ (RenderOptions userMsg)
1631
1504
  (List ( String, FieldDefinition ))
1632
1505
  (Maybe input
1633
1506
  -> FormState
@@ -1643,7 +1516,6 @@ type Form error combineAndView input
1643
1516
  type alias RenderOptions userMsg =
1644
1517
  { submitStrategy : SubmitStrategy
1645
1518
  , method : Method
1646
- , name : Maybe String
1647
1519
  , onSubmit : Maybe ({ fields : List ( String, String ) } -> userMsg)
1648
1520
  }
1649
1521