choonkeat/formdata/1.0.0

NOTE: the latest version is 2.1.0

FormData

Parse, don't validate form data.

State

Before submitting, we should try to obtain a value (and a list of errors) from our FormData

( maybeUser, errors ) =
    FormData.parse parseDontValidate model.userForm

If 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 ""
    ]