Parse, don't validate form data.
Before submitting, we should try to obtain a value (and a list of errors) from our FormData
( maybeUser, errors ) =
FormData.parse parseDontValidate model.userFormIf we get Nothing, disable the submit button. Otherwise, wire up the onSubmit handler
button
[ case maybeUser of
Just user ->
onSubmit (Save user)
Nothing ->
disabled True
]
[ text "Submit" ]If there's an error, show it
div [ input [ onInput (OnInput Name), type_ "text", placeholder "Name" ] []
, case List.head (List.filter (\( k, v ) -> k == Just Name) errors) of
Just ( _, err ) ->
p [] [ small [] [ text err ] ]
Nothing ->
text ""
]