mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-23 14:15:33 +03:00
Rename functions.
This commit is contained in:
parent
94b6649271
commit
c37eb3668e
@ -160,7 +160,7 @@ greet =
|
||||
ApiRoute.succeed
|
||||
(Request.oneOf
|
||||
[ Request.formDataWithoutServerValidation2
|
||||
[ Form.init2
|
||||
[ Form.init
|
||||
(\bar ->
|
||||
{ combine =
|
||||
Validation.succeed identity
|
||||
@ -169,7 +169,7 @@ greet =
|
||||
\_ -> ()
|
||||
}
|
||||
)
|
||||
|> Form.field2 "first" (Field.text |> Field.required "Required")
|
||||
|> Form.field "first" (Field.text |> Field.required "Required")
|
||||
]
|
||||
|> Request.andThen
|
||||
(\result ->
|
||||
|
@ -67,7 +67,7 @@ defaultUser =
|
||||
|
||||
form : Form.HtmlForm String User User Msg
|
||||
form =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\first last username email dob check ->
|
||||
{ combine =
|
||||
Validation.succeed User
|
||||
@ -82,7 +82,7 @@ form =
|
||||
let
|
||||
errors field =
|
||||
formState.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|
||||
errorsView field =
|
||||
case ( formState.submitAttempted, field |> errors ) of
|
||||
@ -130,17 +130,17 @@ form =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "first"
|
||||
|> Form.field "first"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (.first >> Form.Value.string)
|
||||
)
|
||||
|> Form.field2 "last"
|
||||
|> Form.field "last"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (.last >> Form.Value.string)
|
||||
)
|
||||
|> Form.field2 "username"
|
||||
|> Form.field "username"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (.username >> Form.Value.string)
|
||||
@ -153,12 +153,12 @@ form =
|
||||
-- DataSource.succeed []
|
||||
-- )
|
||||
)
|
||||
|> Form.field2 "email"
|
||||
|> Form.field "email"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (.email >> Form.Value.string)
|
||||
)
|
||||
|> Form.field2 "dob"
|
||||
|> Form.field "dob"
|
||||
(Field.date
|
||||
{ invalid = \_ -> "Invalid date"
|
||||
}
|
||||
@ -167,7 +167,7 @@ form =
|
||||
--|> Field.withMin (Date.fromCalendarDate 1900 Time.Jan 1 |> Form.Value.date)
|
||||
--|> Field.withMax (Date.fromCalendarDate 2022 Time.Jan 1 |> Form.Value.date)
|
||||
)
|
||||
|> Form.field2 "checkbox" Field.checkbox
|
||||
|> Form.field "checkbox" Field.checkbox
|
||||
|
||||
|
||||
route : StatelessRoute RouteParams Data ActionData
|
||||
@ -259,7 +259,7 @@ view maybeUrl sharedModel static =
|
||||
[]
|
||||
[ Html.text <| "Edit profile " ++ user.first ++ " " ++ user.last ]
|
||||
, form
|
||||
|> Form.toDynamicTransitionNew "user-form"
|
||||
|> Form.toDynamicTransition "user-form"
|
||||
|> Form.renderHtml
|
||||
[ Attr.style "display" "flex"
|
||||
, Attr.style "flex-direction" "column"
|
||||
|
@ -56,7 +56,7 @@ type alias Data =
|
||||
|
||||
|
||||
form =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\bar ->
|
||||
{ combine =
|
||||
Validation.succeed identity
|
||||
@ -64,7 +64,7 @@ form =
|
||||
, view = \info -> ()
|
||||
}
|
||||
)
|
||||
|> Form.field2 "name" (Field.text |> Field.required "Required")
|
||||
|> Form.field "name" (Field.text |> Field.required "Required")
|
||||
|
||||
|
||||
data : RouteParams -> Request.Parser (DataSource (Response Data ErrorPage))
|
||||
|
@ -65,7 +65,7 @@ defaultUser =
|
||||
|
||||
form : Form.HtmlForm String User User Msg
|
||||
form =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\firstName lastName username email dob check ->
|
||||
{ combine =
|
||||
Validation.succeed User
|
||||
@ -80,7 +80,7 @@ form =
|
||||
let
|
||||
errors field =
|
||||
formState.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|
||||
errorsView field =
|
||||
case
|
||||
@ -132,17 +132,17 @@ form =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "first"
|
||||
|> Form.field "first"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (.first >> Form.Value.string)
|
||||
)
|
||||
|> Form.field2 "last"
|
||||
|> Form.field "last"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (.last >> Form.Value.string)
|
||||
)
|
||||
|> Form.field2 "username"
|
||||
|> Form.field "username"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (.username >> Form.Value.string)
|
||||
@ -155,12 +155,12 @@ form =
|
||||
-- DataSource.succeed []
|
||||
-- )
|
||||
)
|
||||
|> Form.field2 "email"
|
||||
|> Form.field "email"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (.email >> Form.Value.string)
|
||||
)
|
||||
|> Form.field2 "dob"
|
||||
|> Form.field "dob"
|
||||
(Field.date
|
||||
{ invalid = \_ -> "Invalid date"
|
||||
}
|
||||
@ -169,7 +169,7 @@ form =
|
||||
--|> Field.withMin (Date.fromCalendarDate 1900 Time.Jan 1 |> Form.Value.date)
|
||||
--|> Field.withMax (Date.fromCalendarDate 2022 Time.Jan 1 |> Form.Value.date)
|
||||
)
|
||||
|> Form.field2 "checkbox" Field.checkbox
|
||||
|> Form.field "checkbox" Field.checkbox
|
||||
|
||||
|
||||
route : StatelessRoute RouteParams Data ActionData
|
||||
@ -274,7 +274,7 @@ view maybeUrl sharedModel app =
|
||||
[]
|
||||
[ Html.text <| "Edit profile " ++ user.first ++ " " ++ user.last ]
|
||||
, form
|
||||
|> Form.toDynamicTransitionNew "test1"
|
||||
|> Form.toDynamicTransition "test1"
|
||||
|> Form.renderHtml
|
||||
[ Attr.style "display" "flex"
|
||||
, Attr.style "flex-direction" "column"
|
||||
|
@ -56,7 +56,7 @@ type alias Data =
|
||||
|
||||
|
||||
form =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\bar ->
|
||||
{ combine =
|
||||
Validation.succeed identity
|
||||
@ -64,7 +64,7 @@ form =
|
||||
, view = ()
|
||||
}
|
||||
)
|
||||
|> Form.field2 "name" (Field.text |> Field.required "Required")
|
||||
|> Form.field "name" (Field.text |> Field.required "Required")
|
||||
|
||||
|
||||
data : RouteParams -> Request.Parser (DataSource (Response Data ErrorPage))
|
||||
|
@ -118,7 +118,7 @@ data routeParams =
|
||||
|
||||
form : Form.HtmlForm String String () Msg
|
||||
form =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\query ->
|
||||
{ combine =
|
||||
Validation.succeed identity
|
||||
@ -130,7 +130,7 @@ form =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "q" (Field.text |> Field.required "Required")
|
||||
|> Form.field "q" (Field.text |> Field.required "Required")
|
||||
|
||||
|
||||
fieldView :
|
||||
@ -152,7 +152,7 @@ errorsForField : Form.Context String data -> Validation String parsed kind -> Ht
|
||||
errorsForField formState field =
|
||||
(if True then
|
||||
formState.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|> List.map (\error -> Html.li [] [ Html.text error ])
|
||||
|
||||
else
|
||||
@ -197,7 +197,7 @@ view maybeUrl sharedModel model static =
|
||||
, body =
|
||||
[ Html.h2 [] [ Html.text "Search" ]
|
||||
, form
|
||||
|> Form.toDynamicTransitionNew "test1"
|
||||
|> Form.toDynamicTransition "test1"
|
||||
|> Form.withGetMethod
|
||||
|> Form.renderHtml []
|
||||
-- TODO pass in server data
|
||||
|
@ -142,7 +142,7 @@ errorsForField : Form.Context String data -> Validation String parsed kind -> Ht
|
||||
errorsForField formState field =
|
||||
(if True then
|
||||
formState.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|> List.map (\error -> Html.li [] [ Html.text error ])
|
||||
|
||||
else
|
||||
@ -153,7 +153,7 @@ errorsForField formState field =
|
||||
|
||||
form : Form.HtmlForm String ( String, String ) data msg
|
||||
form =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\first email ->
|
||||
{ combine =
|
||||
Validation.succeed Tuple.pair
|
||||
@ -167,8 +167,8 @@ form =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "first" (Field.text |> required |> Field.withInitialValue (\_ -> Form.Value.string "Jane"))
|
||||
|> Form.field2 "email" (Field.text |> required |> Field.withInitialValue (\_ -> Form.Value.string "jane@example.com"))
|
||||
|> Form.field "first" (Field.text |> required |> Field.withInitialValue (\_ -> Form.Value.string "Jane"))
|
||||
|> Form.field "email" (Field.text |> required |> Field.withInitialValue (\_ -> Form.Value.string "jane@example.com"))
|
||||
|
||||
|
||||
required field =
|
||||
@ -266,7 +266,7 @@ view maybeUrl sharedModel model static =
|
||||
]
|
||||
, flashView static.data.flashMessage
|
||||
, form
|
||||
|> Form.toDynamicTransitionNew "test1"
|
||||
|> Form.toDynamicTransition "test1"
|
||||
|> Form.renderHtml []
|
||||
-- TODO pass in server data
|
||||
Nothing
|
||||
|
@ -191,7 +191,7 @@ usernameInput formState field =
|
||||
, Tw.pointer_events_none
|
||||
]
|
||||
]
|
||||
[ if formState.errors |> Form.errorsForField2 field |> List.isEmpty then
|
||||
[ if formState.errors |> Form.errorsForField field |> List.isEmpty then
|
||||
Html.text ""
|
||||
|
||||
else
|
||||
@ -215,7 +215,7 @@ validateCapitalized string =
|
||||
|
||||
form : Form.StyledHtmlForm String User data msg
|
||||
form =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\first last username email dob checkin checkout rating password passwordConfirmation comments candidates offers pushNotifications acceptTerms ->
|
||||
{ combine =
|
||||
Validation.succeed User
|
||||
@ -310,19 +310,19 @@ form =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "first"
|
||||
|> Form.field "first"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (always defaultUser.first >> Form.Value.string)
|
||||
|> Field.withClientValidation validateCapitalized
|
||||
)
|
||||
|> Form.field2 "last"
|
||||
|> Form.field "last"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (always defaultUser.last >> Form.Value.string)
|
||||
|> Field.withClientValidation validateCapitalized
|
||||
)
|
||||
|> Form.field2 "username"
|
||||
|> Form.field "username"
|
||||
(Field.text
|
||||
|> Field.withInitialValue (always defaultUser.username >> Form.Value.string)
|
||||
|> Field.required "Required"
|
||||
@ -365,13 +365,13 @@ form =
|
||||
DataSource.succeed []
|
||||
)
|
||||
)
|
||||
|> Form.field2 "email"
|
||||
|> Form.field "email"
|
||||
(Field.text
|
||||
|> Field.withInitialValue (always defaultUser.email >> Form.Value.string)
|
||||
|> Field.email
|
||||
|> Field.required "Required"
|
||||
)
|
||||
|> Form.field2 "dob"
|
||||
|> Form.field "dob"
|
||||
(Field.date
|
||||
{ invalid = \_ -> "Invalid date" }
|
||||
|> Field.required "Required"
|
||||
@ -387,19 +387,19 @@ form =
|
||||
DataSource.succeed []
|
||||
)
|
||||
)
|
||||
|> Form.field2 "checkin"
|
||||
|> Form.field "checkin"
|
||||
(Field.date
|
||||
{ invalid = \_ -> "Invalid date" }
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (always defaultUser.checkIn >> Form.Value.date)
|
||||
)
|
||||
|> Form.field2 "checkout"
|
||||
|> Form.field "checkout"
|
||||
(Field.date
|
||||
{ invalid = \_ -> "Invalid date" }
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (always defaultUser.checkOut >> Form.Value.date)
|
||||
)
|
||||
|> Form.field2 "rating"
|
||||
|> Form.field "rating"
|
||||
(Field.int { invalid = \_ -> "Invalid number" }
|
||||
|> Field.range
|
||||
{ missing = "Required"
|
||||
@ -409,17 +409,17 @@ form =
|
||||
, max = Form.Value.int 5
|
||||
}
|
||||
)
|
||||
|> Form.field2 "password"
|
||||
|> Form.field "password"
|
||||
(Field.text |> Field.password |> Field.required "Required")
|
||||
|> Form.field2 "password-confirmation"
|
||||
|> Form.field "password-confirmation"
|
||||
(Field.text |> Field.password |> Field.required "Required")
|
||||
|> Form.field2 "comments"
|
||||
|> Form.field "comments"
|
||||
Field.checkbox
|
||||
|> Form.field2 "candidates"
|
||||
|> Form.field "candidates"
|
||||
Field.checkbox
|
||||
|> Form.field2 "offers"
|
||||
|> Form.field "offers"
|
||||
Field.checkbox
|
||||
|> Form.field2
|
||||
|> Form.field
|
||||
"push-notifications"
|
||||
(Field.select
|
||||
[ ( "PushAll", PushAll )
|
||||
@ -429,7 +429,7 @@ form =
|
||||
(\_ -> "Invalid option")
|
||||
|> Field.required "Please select your notification preference."
|
||||
)
|
||||
|> Form.field2 "acceptTerms"
|
||||
|> Form.field "acceptTerms"
|
||||
(Field.checkbox
|
||||
|> Field.withClientValidation
|
||||
(\checked ->
|
||||
@ -709,7 +709,7 @@ view maybeUrl sharedModel model static =
|
||||
|> Debug.toString
|
||||
)
|
||||
, form
|
||||
|> Form.toDynamicTransitionNew "test"
|
||||
|> Form.toDynamicTransition "test"
|
||||
|> Form.renderStyledHtml []
|
||||
(static.action
|
||||
|> Maybe.andThen .formResponse
|
||||
@ -848,7 +848,7 @@ errorsView formState field =
|
||||
]
|
||||
(if showErrors then
|
||||
formState.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|> List.map
|
||||
(\error ->
|
||||
Html.li
|
||||
|
@ -189,7 +189,7 @@ type Action
|
||||
|
||||
deleteForm : Form.HtmlForm String Action String msg
|
||||
deleteForm =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\id ->
|
||||
{ combine =
|
||||
Validation.succeed (\i -> Delete { id = i })
|
||||
@ -200,12 +200,12 @@ deleteForm =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.hiddenField2 "id" (Field.text |> Field.required "Required" |> Field.withInitialValue Form.Value.string)
|
||||
|> Form.hiddenField "id" (Field.text |> Field.required "Required" |> Field.withInitialValue Form.Value.string)
|
||||
|
||||
|
||||
createForm : Form.HtmlForm String Action data msg
|
||||
createForm =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\query ->
|
||||
{ combine =
|
||||
Validation.succeed (\d -> Create { description = d })
|
||||
@ -225,7 +225,7 @@ createForm =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "q" (Field.text |> Field.required "Required")
|
||||
|> Form.field "q" (Field.text |> Field.required "Required")
|
||||
|
||||
|
||||
descriptionFieldView :
|
||||
@ -246,7 +246,7 @@ errorsForField : Form.Context String data -> Validation String parsed kind -> Ht
|
||||
errorsForField formState field =
|
||||
(if True then
|
||||
formState.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|> List.map (\error -> Html.li [] [ Html.text error ])
|
||||
|
||||
else
|
||||
@ -340,7 +340,7 @@ view maybeUrl sharedModel model static =
|
||||
)
|
||||
[ Html.text item.description
|
||||
, deleteForm
|
||||
|> Form.toDynamicTransitionNew "test1"
|
||||
|> Form.toDynamicTransition "test1"
|
||||
|> Form.renderHtml
|
||||
[ Attr.style "display" "inline"
|
||||
, Attr.style "padding-left" "6px"
|
||||
@ -366,7 +366,7 @@ view maybeUrl sharedModel model static =
|
||||
)
|
||||
)
|
||||
, createForm
|
||||
|> Form.toDynamicTransitionNew "test2"
|
||||
|> Form.toDynamicTransition "test2"
|
||||
|> Form.renderHtml []
|
||||
-- TODO pass in server data
|
||||
Nothing
|
||||
|
@ -126,7 +126,7 @@ view maybeUrl sharedModel model app =
|
||||
{ title = "Create Group"
|
||||
, body =
|
||||
[ postForm
|
||||
|> Form.toDynamicTransitionNew "create-group"
|
||||
|> Form.toDynamicTransition "create-group"
|
||||
|> Form.renderHtml []
|
||||
-- TODO pass in form response from ActionData
|
||||
Nothing
|
||||
@ -150,7 +150,7 @@ type GroupVisibility
|
||||
|
||||
postForm : Form.HtmlForm String GroupFormValidated data Msg
|
||||
postForm =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\name description visibility ->
|
||||
{ combine =
|
||||
Validation.succeed GroupFormValidated
|
||||
@ -196,7 +196,7 @@ postForm =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "name"
|
||||
|> Form.field "name"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withClientValidation
|
||||
@ -219,7 +219,7 @@ postForm =
|
||||
|> fromResult
|
||||
)
|
||||
)
|
||||
|> Form.field2 "description"
|
||||
|> Form.field "description"
|
||||
(Field.text
|
||||
|> Field.textarea
|
||||
|> Field.withClientValidation
|
||||
@ -231,7 +231,7 @@ postForm =
|
||||
|> fromResult
|
||||
)
|
||||
)
|
||||
|> Form.field2 "visibility"
|
||||
|> Form.field "visibility"
|
||||
(Field.select
|
||||
[ ( "unlisted", UnlistedGroup )
|
||||
, ( "public", PublicGroup )
|
||||
@ -260,7 +260,7 @@ errorsForField : Form.Context String data -> Validation String parsed kind -> Ht
|
||||
errorsForField formState field =
|
||||
(if formState.submitAttempted then
|
||||
formState.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|> List.map (\error -> Html.li [] [ Html.text error ])
|
||||
|
||||
else
|
||||
|
@ -129,7 +129,7 @@ view maybeUrl sharedModel model app =
|
||||
, body =
|
||||
[ Html.h2 [] [ Html.text "Example" ]
|
||||
, dependentParser
|
||||
|> Form.toDynamicTransitionNew "dependent-example"
|
||||
|> Form.toDynamicTransition "dependent-example"
|
||||
|> Form.renderHtml []
|
||||
-- TODO pass in form response from ActionData
|
||||
Nothing
|
||||
@ -150,7 +150,7 @@ type alias PostInfo =
|
||||
|
||||
linkForm : Form.HtmlForm String PostAction data Msg
|
||||
linkForm =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\url ->
|
||||
{ combine =
|
||||
Validation.succeed ParsedLink
|
||||
@ -162,7 +162,7 @@ linkForm =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "url"
|
||||
|> Form.field "url"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.url
|
||||
@ -171,7 +171,7 @@ linkForm =
|
||||
|
||||
postForm : Form.HtmlForm String PostAction data Msg
|
||||
postForm =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\title body ->
|
||||
{ combine =
|
||||
Validation.succeed PostInfo
|
||||
@ -186,13 +186,13 @@ postForm =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "title" (Field.text |> Field.required "Required")
|
||||
|> Form.field2 "body" Field.text
|
||||
|> Form.field "title" (Field.text |> Field.required "Required")
|
||||
|> Form.field "body" Field.text
|
||||
|
||||
|
||||
dependentParser : Form.HtmlForm String PostAction data Msg
|
||||
dependentParser =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\kind postForm_ ->
|
||||
{ combine =
|
||||
kind
|
||||
@ -226,7 +226,7 @@ dependentParser =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "kind"
|
||||
|> Form.field "kind"
|
||||
(Field.select
|
||||
[ ( "link", Link )
|
||||
, ( "post", Post )
|
||||
@ -234,7 +234,7 @@ dependentParser =
|
||||
(\_ -> "Invalid")
|
||||
|> Field.required "Required"
|
||||
)
|
||||
|> Form.dynamic2
|
||||
|> Form.dynamic
|
||||
(\parsedKind ->
|
||||
case parsedKind of
|
||||
Link ->
|
||||
@ -256,7 +256,7 @@ fieldView formState label field =
|
||||
errorsView =
|
||||
(if formState.submitAttempted || True then
|
||||
formState.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|> List.map (\error -> Html.li [] [ Html.text error ])
|
||||
|
||||
else
|
||||
|
@ -126,19 +126,19 @@ type Action
|
||||
|
||||
signoutForm : Form.HtmlForm String Action input Msg
|
||||
signoutForm =
|
||||
Form.init2
|
||||
Form.init
|
||||
{ combine = Validation.succeed Signout
|
||||
, view =
|
||||
\formState ->
|
||||
[ Html.button [] [ Html.text "Sign out" ]
|
||||
]
|
||||
}
|
||||
|> Form.hiddenKind2 ( "kind", "signout" ) "Expected signout"
|
||||
|> Form.hiddenKind ( "kind", "signout" ) "Expected signout"
|
||||
|
||||
|
||||
setQuantityForm : Form.HtmlForm String Action ( Int, QuantityChange, Smoothie ) Msg
|
||||
setQuantityForm =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\uuid quantity ->
|
||||
{ combine =
|
||||
Validation.succeed SetQuantity
|
||||
@ -158,13 +158,13 @@ setQuantityForm =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.hiddenKind2 ( "kind", "setQuantity" ) "Expected setQuantity"
|
||||
|> Form.hiddenField2 "itemId"
|
||||
|> Form.hiddenKind ( "kind", "setQuantity" ) "Expected setQuantity"
|
||||
|> Form.hiddenField "itemId"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (\( _, _, item ) -> Form.Value.string (uuidToString item.id))
|
||||
)
|
||||
|> Form.hiddenField2 "quantity"
|
||||
|> Form.hiddenField "quantity"
|
||||
(Field.int { invalid = \_ -> "Expected int" }
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue
|
||||
@ -231,7 +231,7 @@ view maybeUrl sharedModel model app =
|
||||
app.fetchers
|
||||
|> List.filterMap
|
||||
(\pending ->
|
||||
case Form.runOneOfServerSide2 pending.payload.fields oneOfParsers of
|
||||
case Form.runOneOfServerSide pending.payload.fields oneOfParsers of
|
||||
( Just (SetQuantity itemId addAmount), _ ) ->
|
||||
Just ( uuidToString itemId, addAmount )
|
||||
|
||||
@ -271,7 +271,7 @@ view maybeUrl sharedModel model app =
|
||||
, Html.p []
|
||||
[ Html.text <| "Welcome " ++ app.data.user.name ++ "!"
|
||||
, signoutForm
|
||||
|> Form.toDynamicFetcherNew "signout"
|
||||
|> Form.toDynamicFetcher "signout"
|
||||
|> Form.renderHtml [] Nothing app ()
|
||||
]
|
||||
, cartView totals
|
||||
@ -324,11 +324,11 @@ productView app cart item =
|
||||
[]
|
||||
[ setQuantityForm
|
||||
-- TODO should this be toStaticFetcher (don't need the formId here because there is no client-side state, only hidden form fields
|
||||
|> Form.toDynamicFetcherNew "increment-quantity"
|
||||
|> Form.toDynamicFetcher "increment-quantity"
|
||||
|> Form.renderHtml [] Nothing app ( quantityInCart, Decrement, item )
|
||||
, Html.p [] [ quantityInCart |> String.fromInt |> Html.text ]
|
||||
, setQuantityForm
|
||||
|> Form.toDynamicFetcherNew "decrement-quantity"
|
||||
|> Form.toDynamicFetcher "decrement-quantity"
|
||||
|> Form.renderHtml [] Nothing app ( quantityInCart, Increment, item )
|
||||
]
|
||||
, Html.div []
|
||||
|
@ -90,7 +90,7 @@ route =
|
||||
|
||||
form : Form.HtmlForm String String data Msg
|
||||
form =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\username ->
|
||||
{ combine =
|
||||
Validation.succeed identity
|
||||
@ -110,7 +110,7 @@ form =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "username" (Field.text |> Field.required "Required")
|
||||
|> Form.field "username" (Field.text |> Field.required "Required")
|
||||
|
||||
|
||||
fieldView :
|
||||
@ -132,7 +132,7 @@ errorsForField : Form.Context String data -> Validation String parsed kind -> Ht
|
||||
errorsForField formState field =
|
||||
(if formState.submitAttempted then
|
||||
formState.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|> List.map (\error -> Html.li [] [ Html.text error ])
|
||||
|
||||
else
|
||||
@ -219,7 +219,7 @@ view maybeUrl sharedModel app =
|
||||
)
|
||||
]
|
||||
, form
|
||||
|> Form.toDynamicTransitionNew "login"
|
||||
|> Form.toDynamicTransition "login"
|
||||
|> Form.renderHtml [] Nothing app ()
|
||||
]
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ head static =
|
||||
|
||||
form : Form.HtmlForm String NewItem Data Msg
|
||||
form =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\name description price imageUrl ->
|
||||
{ combine =
|
||||
Validation.succeed NewItem
|
||||
@ -141,7 +141,7 @@ form =
|
||||
let
|
||||
errors field =
|
||||
info.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|
||||
errorsView field =
|
||||
(--if field.status == Pages.FormState.Blurred then
|
||||
@ -172,8 +172,8 @@ form =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "name" (Field.text |> Field.required "Required")
|
||||
|> Form.field2 "description"
|
||||
|> Form.field "name" (Field.text |> Field.required "Required")
|
||||
|> Form.field "description"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withClientValidation
|
||||
@ -188,8 +188,8 @@ form =
|
||||
)
|
||||
)
|
||||
)
|
||||
|> Form.field2 "price" (Field.int { invalid = \_ -> "Invalid int" } |> Field.required "Required")
|
||||
|> Form.field2 "imageUrl" (Field.text |> Field.required "Required")
|
||||
|> Form.field "price" (Field.int { invalid = \_ -> "Invalid int" } |> Field.required "Required")
|
||||
|> Form.field "imageUrl" (Field.text |> Field.required "Required")
|
||||
|
||||
|
||||
view :
|
||||
@ -203,14 +203,14 @@ view maybeUrl sharedModel model app =
|
||||
pendingCreation : Result (Form.FieldErrors String) NewItem
|
||||
pendingCreation =
|
||||
form
|
||||
|> Form.parse2 app app.data
|
||||
|> Form.parse app app.data
|
||||
|> parseIgnoreErrors
|
||||
in
|
||||
{ title = "New Item"
|
||||
, body =
|
||||
[ Html.h2 [] [ Html.text "New item" ]
|
||||
, form
|
||||
|> Form.toDynamicTransitionNew "form"
|
||||
|> Form.toDynamicTransition "form"
|
||||
|> Form.renderHtml
|
||||
[ Attr.style "display" "flex"
|
||||
, Attr.style "flex-direction" "column"
|
||||
|
@ -120,7 +120,7 @@ view maybeUrl sharedModel model app =
|
||||
, body =
|
||||
[ Html.h2 [] [ Html.text "Example" ]
|
||||
, dependentParser
|
||||
|> Form.toDynamicTransitionNew "form"
|
||||
|> Form.toDynamicTransition "form"
|
||||
|> Form.renderHtml []
|
||||
-- TODO pass in form response from ActionData
|
||||
Nothing
|
||||
@ -141,7 +141,7 @@ type alias Validated =
|
||||
|
||||
dependentParser : Form.HtmlForm String { username : String, password : String } data Msg
|
||||
dependentParser =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\username password passwordConfirmation ->
|
||||
{ combine =
|
||||
username
|
||||
@ -167,9 +167,9 @@ dependentParser =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "username" (Field.text |> Field.required "Required")
|
||||
|> Form.field2 "password" (Field.text |> Field.password |> Field.required "Required")
|
||||
|> Form.field2 "password-confirmation" (Field.text |> Field.password |> Field.required "Required")
|
||||
|> Form.field "username" (Field.text |> Field.required "Required")
|
||||
|> Form.field "password" (Field.text |> Field.password |> Field.required "Required")
|
||||
|> Form.field "password-confirmation" (Field.text |> Field.password |> Field.required "Required")
|
||||
|
||||
|
||||
fieldView :
|
||||
@ -183,7 +183,7 @@ fieldView formState label field =
|
||||
errorsView =
|
||||
(if formState.submitAttempted || True then
|
||||
formState.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|> List.map (\error -> Html.li [] [ Html.text error ])
|
||||
|
||||
else
|
||||
|
@ -121,7 +121,7 @@ type alias Action =
|
||||
|
||||
formParser : Form.HtmlForm String Action Data msg
|
||||
formParser =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\username name ->
|
||||
{ combine =
|
||||
Validation.succeed Action
|
||||
@ -132,14 +132,14 @@ formParser =
|
||||
let
|
||||
errors field =
|
||||
info.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|
||||
errorsView field =
|
||||
(-- TODO
|
||||
--if field.status == Pages.FormState.Blurred then
|
||||
if True then
|
||||
info.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|> List.map (\error -> Html.li [] [ Html.text error ])
|
||||
|
||||
else
|
||||
@ -167,7 +167,7 @@ formParser =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "username"
|
||||
|> Form.field "username"
|
||||
(Field.text
|
||||
|> Field.required "Username is required"
|
||||
|> Field.withClientValidation validateUsername
|
||||
@ -183,7 +183,7 @@ formParser =
|
||||
)
|
||||
|> Field.withInitialValue (\{ user } -> Form.Value.string user.username)
|
||||
)
|
||||
|> Form.field2 "name"
|
||||
|> Form.field "name"
|
||||
(Field.text
|
||||
|> Field.required "Name is required"
|
||||
|> Field.withInitialValue (\{ user } -> Form.Value.string user.name)
|
||||
@ -269,7 +269,7 @@ view maybeUrl sharedModel model app =
|
||||
_ ->
|
||||
Html.text "No errors"
|
||||
, formParser
|
||||
|> Form.toDynamicTransitionNew "edit-form"
|
||||
|> Form.toDynamicTransition "edit-form"
|
||||
|> Form.renderHtml
|
||||
[ Attr.style "display" "flex"
|
||||
, Attr.style "flex-direction" "column"
|
||||
|
@ -175,7 +175,7 @@ type alias EditInfo =
|
||||
|
||||
deleteForm : Form.HtmlForm String Action data Msg
|
||||
deleteForm =
|
||||
Form.init2
|
||||
Form.init
|
||||
{ combine = Validation.succeed Delete
|
||||
, view =
|
||||
\formState ->
|
||||
@ -185,12 +185,12 @@ deleteForm =
|
||||
[ Html.text "Delete" ]
|
||||
]
|
||||
}
|
||||
|> Form.hiddenKind2 ( "kind", "delete" ) "Required"
|
||||
|> Form.hiddenKind ( "kind", "delete" ) "Required"
|
||||
|
||||
|
||||
form : Form.HtmlForm String Action Data Msg
|
||||
form =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\name description price imageUrl media ->
|
||||
{ combine =
|
||||
Validation.succeed EditInfo
|
||||
@ -205,7 +205,7 @@ form =
|
||||
errorsView field =
|
||||
(if formState.submitAttempted || True then
|
||||
formState.errors
|
||||
|> Form.errorsForField2 field
|
||||
|> Form.errorsForField field
|
||||
|> List.map (\error -> Html.li [] [ Html.text error ])
|
||||
|
||||
else
|
||||
@ -256,28 +256,28 @@ form =
|
||||
]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "name"
|
||||
|> Form.field "name"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (\{ smoothie } -> Form.Value.string smoothie.name)
|
||||
)
|
||||
|> Form.field2 "description"
|
||||
|> Form.field "description"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (\{ smoothie } -> Form.Value.string smoothie.description)
|
||||
)
|
||||
|> Form.field2 "price"
|
||||
|> Form.field "price"
|
||||
(Field.int { invalid = \_ -> "Invalid int" }
|
||||
|> Field.required "Required"
|
||||
|> Field.withMin (Form.Value.int 1) "Price must be at least $1"
|
||||
|> Field.withInitialValue (\{ smoothie } -> Form.Value.int smoothie.price)
|
||||
)
|
||||
|> Form.field2 "imageUrl"
|
||||
|> Form.field "imageUrl"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.withInitialValue (\{ smoothie } -> Form.Value.string smoothie.unsplashImage)
|
||||
)
|
||||
|> Form.field2 "media"
|
||||
|> Form.field "media"
|
||||
(Field.select
|
||||
[ ( "article", Article )
|
||||
, ( "book", Book )
|
||||
@ -285,7 +285,7 @@ form =
|
||||
]
|
||||
(\option -> "Invalid option " ++ option)
|
||||
)
|
||||
|> Form.hiddenKind2 ( "kind", "edit" ) "Required"
|
||||
|> Form.hiddenKind ( "kind", "edit" ) "Required"
|
||||
|
||||
|
||||
type Media
|
||||
@ -315,7 +315,7 @@ view maybeUrl sharedModel model app =
|
||||
pendingCreation : Maybe NewItem
|
||||
pendingCreation =
|
||||
form
|
||||
|> Form.parse2 app app.data
|
||||
|> Form.parse app app.data
|
||||
|> parseIgnoreErrors
|
||||
|> Result.toMaybe
|
||||
|> Maybe.andThen
|
||||
@ -332,7 +332,7 @@ view maybeUrl sharedModel model app =
|
||||
, body =
|
||||
[ Html.h2 [] [ Html.text "Update item" ]
|
||||
, form
|
||||
|> Form.toDynamicTransitionNew "form"
|
||||
|> Form.toDynamicTransition "form"
|
||||
|> Form.renderHtml
|
||||
[ Attr.style "display" "flex"
|
||||
, Attr.style "flex-direction" "column"
|
||||
@ -346,7 +346,7 @@ view maybeUrl sharedModel model app =
|
||||
|> Maybe.map pendingView
|
||||
|> Maybe.withDefault (Html.div [] [])
|
||||
, deleteForm
|
||||
|> Form.toDynamicTransitionNew "delete-form"
|
||||
|> Form.toDynamicTransition "delete-form"
|
||||
|> Form.renderHtml []
|
||||
-- TODO
|
||||
Nothing
|
||||
|
74
src/Form.elm
74
src/Form.elm
@ -1,27 +1,19 @@
|
||||
module Form exposing
|
||||
( Form(..), FieldErrors, HtmlForm, StyledHtmlForm
|
||||
, init
|
||||
, field, hiddenField, hiddenKind
|
||||
, andThen
|
||||
, Context
|
||||
, renderHtml, renderStyledHtml
|
||||
, FinalForm, withGetMethod
|
||||
, Errors
|
||||
, FinalForm, withGetMethod, toDynamicTransition, toDynamicFetcher
|
||||
, Errors, errorsForField
|
||||
, parse, runOneOfServerSide
|
||||
, dynamic
|
||||
, runOneOfServerSideWithServerValidations
|
||||
, AppContext
|
||||
, FieldDefinition(..)
|
||||
, dynamic2
|
||||
, errorsForField2
|
||||
, field2
|
||||
, hiddenField2
|
||||
, hiddenKind2
|
||||
, init2
|
||||
, parse2
|
||||
, runOneOfServerSide2
|
||||
, runOneOfServerSideWithServerValidations2
|
||||
, runServerSide3
|
||||
, runServerSide4
|
||||
, toDynamicFetcherNew
|
||||
, toDynamicTransitionNew
|
||||
-- subGroup
|
||||
|
||||
, runServerSide3, runServerSide4
|
||||
-- subGroup
|
||||
)
|
||||
|
||||
{-|
|
||||
@ -137,8 +129,8 @@ type alias Context error data =
|
||||
|
||||
|
||||
{-| -}
|
||||
init2 : parsedAndView -> Form String parsedAndView data
|
||||
init2 parsedAndView =
|
||||
init : parsedAndView -> Form String parsedAndView data
|
||||
init parsedAndView =
|
||||
FormNew []
|
||||
(\_ _ ->
|
||||
{ result = Dict.empty
|
||||
@ -150,7 +142,7 @@ init2 parsedAndView =
|
||||
|
||||
|
||||
{-| -}
|
||||
dynamic2 :
|
||||
dynamic :
|
||||
(decider
|
||||
->
|
||||
Form
|
||||
@ -175,7 +167,7 @@ dynamic2 :
|
||||
error
|
||||
parsedAndView
|
||||
data
|
||||
dynamic2 forms formBuilder =
|
||||
dynamic forms formBuilder =
|
||||
FormNew []
|
||||
(\maybeData formState ->
|
||||
let
|
||||
@ -318,12 +310,12 @@ andThen andThenFn ( maybe, fieldErrors ) =
|
||||
|
||||
|
||||
{-| -}
|
||||
field2 :
|
||||
field :
|
||||
String
|
||||
-> Field error parsed data kind constraints
|
||||
-> Form error (Validation error parsed kind -> parsedAndView) data
|
||||
-> Form error parsedAndView data
|
||||
field2 name (Field fieldParser kind) (FormNew definitions parseFn toInitialValues) =
|
||||
field name (Field fieldParser kind) (FormNew definitions parseFn toInitialValues) =
|
||||
FormNew
|
||||
(( name, RegularField )
|
||||
:: definitions
|
||||
@ -400,12 +392,12 @@ field2 name (Field fieldParser kind) (FormNew definitions parseFn toInitialValue
|
||||
|
||||
|
||||
{-| -}
|
||||
hiddenField2 :
|
||||
hiddenField :
|
||||
String
|
||||
-> Field error parsed data kind constraints
|
||||
-> Form error (Validation error parsed Form.FieldView.Hidden -> parsedAndView) data
|
||||
-> Form error parsedAndView data
|
||||
hiddenField2 name (Field fieldParser _) (FormNew definitions parseFn toInitialValues) =
|
||||
hiddenField name (Field fieldParser _) (FormNew definitions parseFn toInitialValues) =
|
||||
FormNew
|
||||
(( name, HiddenField )
|
||||
:: definitions
|
||||
@ -482,12 +474,12 @@ hiddenField2 name (Field fieldParser _) (FormNew definitions parseFn toInitialVa
|
||||
|
||||
|
||||
{-| -}
|
||||
hiddenKind2 :
|
||||
hiddenKind :
|
||||
( String, String )
|
||||
-> error
|
||||
-> Form error parsedAndView data
|
||||
-> Form error parsedAndView data
|
||||
hiddenKind2 ( name, value ) error_ (FormNew definitions parseFn toInitialValues) =
|
||||
hiddenKind ( name, value ) error_ (FormNew definitions parseFn toInitialValues) =
|
||||
let
|
||||
(Field fieldParser _) =
|
||||
Field.exactValue value error_
|
||||
@ -558,8 +550,8 @@ type Errors error
|
||||
|
||||
|
||||
{-| -}
|
||||
errorsForField2 : Validation error parsed kind -> Errors error -> List error
|
||||
errorsForField2 field_ (Errors errorsDict) =
|
||||
errorsForField : Validation error parsed kind -> Errors error -> List error
|
||||
errorsForField field_ (Errors errorsDict) =
|
||||
errorsDict
|
||||
|> Dict.get (Validation.fieldName field_)
|
||||
|> Maybe.withDefault []
|
||||
@ -673,12 +665,12 @@ mergeErrors errors1 errors2 =
|
||||
|
||||
|
||||
{-| -}
|
||||
parse2 :
|
||||
parse :
|
||||
AppContext app
|
||||
-> data
|
||||
-> Form error { info | combine : Validation error parsed named } data
|
||||
-> ( Maybe parsed, FieldErrors error )
|
||||
parse2 app data (FormNew _ parser _) =
|
||||
parse app data (FormNew _ parser _) =
|
||||
-- TODO Get transition context from `app` so you can check if the current form is being submitted
|
||||
-- TODO either as a transition or a fetcher? Should be easy enough to check for the `id` on either of those?
|
||||
let
|
||||
@ -795,7 +787,7 @@ unwrapValidation (Pages.Internal.Form.Validation viewField name ( maybeParsed, e
|
||||
|
||||
|
||||
{-| -}
|
||||
runOneOfServerSide2 :
|
||||
runOneOfServerSide :
|
||||
List ( String, String )
|
||||
->
|
||||
List
|
||||
@ -805,7 +797,7 @@ runOneOfServerSide2 :
|
||||
data
|
||||
)
|
||||
-> ( Maybe parsed, FieldErrors error )
|
||||
runOneOfServerSide2 rawFormData parsers =
|
||||
runOneOfServerSide rawFormData parsers =
|
||||
case parsers of
|
||||
firstParser :: remainingParsers ->
|
||||
let
|
||||
@ -824,7 +816,7 @@ runOneOfServerSide2 rawFormData parsers =
|
||||
( Just parsed, Dict.empty )
|
||||
|
||||
_ ->
|
||||
runOneOfServerSide2 rawFormData remainingParsers
|
||||
runOneOfServerSide rawFormData remainingParsers
|
||||
|
||||
[] ->
|
||||
-- TODO need to pass errors
|
||||
@ -832,7 +824,7 @@ runOneOfServerSide2 rawFormData parsers =
|
||||
|
||||
|
||||
{-| -}
|
||||
runOneOfServerSideWithServerValidations2 :
|
||||
runOneOfServerSideWithServerValidations :
|
||||
List ( String, String )
|
||||
->
|
||||
List
|
||||
@ -842,7 +834,7 @@ runOneOfServerSideWithServerValidations2 :
|
||||
data
|
||||
)
|
||||
-> ( Maybe parsed, DataSource (FieldErrors error) )
|
||||
runOneOfServerSideWithServerValidations2 rawFormData parsers =
|
||||
runOneOfServerSideWithServerValidations rawFormData parsers =
|
||||
case parsers of
|
||||
firstParser :: remainingParsers ->
|
||||
let
|
||||
@ -856,7 +848,7 @@ runOneOfServerSideWithServerValidations2 rawFormData parsers =
|
||||
thing
|
||||
|
||||
_ ->
|
||||
runOneOfServerSideWithServerValidations2 rawFormData remainingParsers
|
||||
runOneOfServerSideWithServerValidations rawFormData remainingParsers
|
||||
|
||||
[] ->
|
||||
-- TODO need to pass errors
|
||||
@ -921,7 +913,7 @@ toStatic (FormInternal a b c) =
|
||||
|
||||
|
||||
{-| -}
|
||||
toDynamicFetcherNew :
|
||||
toDynamicFetcher :
|
||||
String
|
||||
->
|
||||
Form
|
||||
@ -936,7 +928,7 @@ toDynamicFetcherNew :
|
||||
(Validation error parsed field)
|
||||
data
|
||||
(Context error data -> view)
|
||||
toDynamicFetcherNew name (FormNew a b c) =
|
||||
toDynamicFetcher name (FormNew a b c) =
|
||||
let
|
||||
options =
|
||||
{ submitStrategy = FetcherStrategy
|
||||
@ -991,7 +983,7 @@ toDynamicFetcherNew name (FormNew a b c) =
|
||||
|
||||
|
||||
{-| -}
|
||||
toDynamicTransitionNew :
|
||||
toDynamicTransition :
|
||||
String
|
||||
->
|
||||
Form
|
||||
@ -1006,7 +998,7 @@ toDynamicTransitionNew :
|
||||
(Validation error parsed field)
|
||||
data
|
||||
(Context error data -> view)
|
||||
toDynamicTransitionNew name (FormNew a b c) =
|
||||
toDynamicTransition name (FormNew a b c) =
|
||||
let
|
||||
options =
|
||||
{ submitStrategy = TransitionStrategy
|
||||
|
@ -897,7 +897,7 @@ formDataWithoutServerValidation2 formParsers =
|
||||
(\rawFormData_ ->
|
||||
let
|
||||
( maybeDecoded, errors ) =
|
||||
Form.runOneOfServerSide2
|
||||
Form.runOneOfServerSide
|
||||
rawFormData_
|
||||
formParsers
|
||||
in
|
||||
@ -933,7 +933,7 @@ formData2 formParsers =
|
||||
(\rawFormData_ ->
|
||||
let
|
||||
( maybeDecoded, errorsDataSource ) =
|
||||
Form.runOneOfServerSideWithServerValidations2
|
||||
Form.runOneOfServerSideWithServerValidations
|
||||
rawFormData_
|
||||
formParsers
|
||||
in
|
||||
|
@ -23,7 +23,7 @@ all =
|
||||
describe "Form Parser" <|
|
||||
let
|
||||
passwordConfirmationParser =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\password passwordConfirmation ->
|
||||
{ combine =
|
||||
Validation.succeed
|
||||
@ -39,8 +39,8 @@ all =
|
||||
, view = \info -> Div
|
||||
}
|
||||
)
|
||||
|> Form.field2 "password" (Field.text |> Field.required "Password is required")
|
||||
|> Form.field2 "password-confirmation" (Field.text |> Field.required "Password confirmation is required")
|
||||
|> Form.field "password" (Field.text |> Field.required "Password is required")
|
||||
|> Form.field "password-confirmation" (Field.text |> Field.required "Password confirmation is required")
|
||||
in
|
||||
[ test "matching password" <|
|
||||
\() ->
|
||||
@ -71,14 +71,14 @@ all =
|
||||
, describe "oneOf" <|
|
||||
let
|
||||
oneOfParsers =
|
||||
[ Form.init2
|
||||
[ Form.init
|
||||
(\_ ->
|
||||
{ combine = Validation.succeed Signout
|
||||
, view = \_ -> Div
|
||||
}
|
||||
)
|
||||
|> Form.hiddenField2 "kind" (Field.exactValue "signout" "Expected signout")
|
||||
, Form.init2
|
||||
|> Form.hiddenField "kind" (Field.exactValue "signout" "Expected signout")
|
||||
, Form.init
|
||||
(\_ uuid quantity ->
|
||||
{ combine =
|
||||
Validation.succeed SetQuantity
|
||||
@ -88,14 +88,14 @@ all =
|
||||
\_ -> Div
|
||||
}
|
||||
)
|
||||
|> Form.hiddenField2 "kind" (Field.exactValue "setQuantity" "Expected setQuantity")
|
||||
|> Form.hiddenField2 "uuid" (Field.text |> Field.required "Required")
|
||||
|> Form.field2 "quantity" (Field.int { invalid = \_ -> "Expected int" } |> Field.required "Required")
|
||||
|> Form.hiddenField "kind" (Field.exactValue "setQuantity" "Expected setQuantity")
|
||||
|> Form.hiddenField "uuid" (Field.text |> Field.required "Required")
|
||||
|> Form.field "quantity" (Field.int { invalid = \_ -> "Expected int" } |> Field.required "Required")
|
||||
]
|
||||
in
|
||||
[ test "first branch" <|
|
||||
\() ->
|
||||
Form.runOneOfServerSide2
|
||||
Form.runOneOfServerSide
|
||||
(fields
|
||||
[ ( "kind", "signout" )
|
||||
]
|
||||
@ -107,7 +107,7 @@ all =
|
||||
)
|
||||
, test "second branch" <|
|
||||
\() ->
|
||||
Form.runOneOfServerSide2
|
||||
Form.runOneOfServerSide
|
||||
(fields
|
||||
[ ( "kind", "setQuantity" )
|
||||
, ( "uuid", "123" )
|
||||
@ -132,14 +132,14 @@ all =
|
||||
, describe "select" <|
|
||||
let
|
||||
selectParser =
|
||||
[ Form.init2
|
||||
[ Form.init
|
||||
(\media ->
|
||||
{ combine = media
|
||||
, view =
|
||||
\_ -> Div
|
||||
}
|
||||
)
|
||||
|> Form.field2 "media"
|
||||
|> Form.field "media"
|
||||
(Field.select
|
||||
[ ( "book", Book )
|
||||
, ( "article", Article )
|
||||
@ -151,7 +151,7 @@ all =
|
||||
in
|
||||
[ test "example" <|
|
||||
\() ->
|
||||
Form.runOneOfServerSide2
|
||||
Form.runOneOfServerSide
|
||||
(fields
|
||||
[ ( "media", "book" )
|
||||
]
|
||||
@ -170,7 +170,7 @@ all =
|
||||
{ combine : Validation String ( Date, Date ) Never, view : a -> MyView }
|
||||
data
|
||||
checkinFormParser =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\checkin checkout ->
|
||||
{ combine =
|
||||
Validation.succeed
|
||||
@ -190,14 +190,14 @@ all =
|
||||
\_ -> Div
|
||||
}
|
||||
)
|
||||
|> Form.field2 "checkin"
|
||||
|> Form.field "checkin"
|
||||
(Field.date { invalid = \_ -> "Invalid" } |> Field.required "Required")
|
||||
|> Form.field2 "checkout"
|
||||
|> Form.field "checkout"
|
||||
(Field.date { invalid = \_ -> "Invalid" } |> Field.required "Required")
|
||||
in
|
||||
[ test "checkin must be before checkout" <|
|
||||
\() ->
|
||||
Form.runOneOfServerSide2
|
||||
Form.runOneOfServerSide
|
||||
(fields
|
||||
[ ( "checkin", "2022-01-01" )
|
||||
, ( "checkout", "2022-01-03" )
|
||||
@ -231,7 +231,7 @@ all =
|
||||
, ( "password-confirmation", "doesnt-match" )
|
||||
]
|
||||
)
|
||||
(Form.init2
|
||||
(Form.init
|
||||
(\postForm_ ->
|
||||
{ combine =
|
||||
postForm_.combine ()
|
||||
@ -239,9 +239,9 @@ all =
|
||||
\_ -> ( [], [ Div ] )
|
||||
}
|
||||
)
|
||||
|> Form.dynamic2
|
||||
|> Form.dynamic
|
||||
(\() ->
|
||||
Form.init2
|
||||
Form.init
|
||||
(\password passwordConfirmation ->
|
||||
{ combine =
|
||||
Validation.succeed
|
||||
@ -258,8 +258,8 @@ all =
|
||||
, view = [ Div ]
|
||||
}
|
||||
)
|
||||
|> Form.field2 "password" (Field.text |> Field.password |> Field.required "Required")
|
||||
|> Form.field2 "password-confirmation" (Field.text |> Field.password |> Field.required "Required")
|
||||
|> Form.field "password" (Field.text |> Field.password |> Field.required "Required")
|
||||
|> Form.field "password-confirmation" (Field.text |> Field.password |> Field.required "Required")
|
||||
)
|
||||
)
|
||||
|> Expect.equal
|
||||
@ -274,7 +274,7 @@ all =
|
||||
let
|
||||
linkForm : Form String { combine : Validation String PostAction Never, view : Form.Context String data -> MyView } data
|
||||
linkForm =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\url ->
|
||||
{ combine =
|
||||
Validation.succeed ParsedLink
|
||||
@ -283,7 +283,7 @@ all =
|
||||
\_ -> Div
|
||||
}
|
||||
)
|
||||
|> Form.field2 "url"
|
||||
|> Form.field "url"
|
||||
(Field.text
|
||||
|> Field.required "Required"
|
||||
|> Field.url
|
||||
@ -291,7 +291,7 @@ all =
|
||||
|
||||
postForm : Form String { combine : Validation String PostAction Never, view : Form.Context String data -> MyView } data
|
||||
postForm =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\title body ->
|
||||
{ combine =
|
||||
Validation.succeed
|
||||
@ -306,12 +306,12 @@ all =
|
||||
, view = \_ -> Div
|
||||
}
|
||||
)
|
||||
|> Form.field2 "title" (Field.text |> Field.required "Required")
|
||||
|> Form.field2 "body" Field.text
|
||||
|> Form.field "title" (Field.text |> Field.required "Required")
|
||||
|> Form.field "body" Field.text
|
||||
|
||||
dependentParser : Form String { combine : Validation String PostAction Never, view : Form.Context String data -> MyView } data
|
||||
dependentParser =
|
||||
Form.init2
|
||||
Form.init
|
||||
(\kind postForm_ ->
|
||||
{ combine =
|
||||
kind
|
||||
@ -319,7 +319,7 @@ all =
|
||||
, view = \_ -> Div
|
||||
}
|
||||
)
|
||||
|> Form.field2 "kind"
|
||||
|> Form.field "kind"
|
||||
(Field.select
|
||||
[ ( "link", Link )
|
||||
, ( "post", Post )
|
||||
@ -327,7 +327,7 @@ all =
|
||||
(\_ -> "Invalid")
|
||||
|> Field.required "Required"
|
||||
)
|
||||
|> Form.dynamic2
|
||||
|> Form.dynamic
|
||||
(\parsedKind ->
|
||||
case parsedKind of
|
||||
Link ->
|
||||
@ -339,7 +339,7 @@ all =
|
||||
in
|
||||
[ test "parses link" <|
|
||||
\() ->
|
||||
Form.runOneOfServerSide2
|
||||
Form.runOneOfServerSide
|
||||
(fields
|
||||
[ ( "kind", "link" )
|
||||
, ( "url", "https://elm-radio.com/episode/wrap-early-unwrap-late" )
|
||||
|
@ -63,7 +63,7 @@ all =
|
||||
, test "tries multiple form post formats" <|
|
||||
\() ->
|
||||
Request.formDataWithoutServerValidation2
|
||||
[ Form.init2
|
||||
[ Form.init
|
||||
(\bar ->
|
||||
{ combine =
|
||||
Validation.succeed identity
|
||||
@ -72,8 +72,8 @@ all =
|
||||
\_ -> ()
|
||||
}
|
||||
)
|
||||
|> Form.field2 "bar" Field.text
|
||||
, Form.init2
|
||||
|> Form.field "bar" Field.text
|
||||
, Form.init
|
||||
(\bar ->
|
||||
{ combine =
|
||||
Validation.succeed identity
|
||||
@ -82,7 +82,7 @@ all =
|
||||
\_ -> ()
|
||||
}
|
||||
)
|
||||
|> Form.field2 "foo" Field.text
|
||||
|> Form.field "foo" Field.text
|
||||
]
|
||||
|> expectMatch
|
||||
{ method = Request.Post
|
||||
@ -99,7 +99,7 @@ all =
|
||||
, test "expectFormPost with missing content-type" <|
|
||||
\() ->
|
||||
Request.formDataWithoutServerValidation2
|
||||
[ Form.init2
|
||||
[ Form.init
|
||||
(\bar ->
|
||||
{ combine =
|
||||
Validation.succeed identity
|
||||
@ -108,7 +108,7 @@ all =
|
||||
\_ -> ()
|
||||
}
|
||||
)
|
||||
|> Form.field2 "bar" Field.text
|
||||
|> Form.field "bar" Field.text
|
||||
]
|
||||
|> expectNoMatch
|
||||
{ method = Request.Post
|
||||
|
Loading…
Reference in New Issue
Block a user