This is pretty cool!
It reminds me quite a bit of
stoeffel/elm-verify which is conceptually similar: turn one datastructure into another, while collecting errors when things go wrong.
Thanks very much for reading and also valuable information.
I’ll add “Related work” section on package README, and reffer it.
This looks great! I wonder if it is possible to validate fields independently of each other. What would the model look like?
My use case is validating a field as soon as the focus leaves the input.
Thanks for interested in.
Is your use case differ from my real world example?
(It shows error immediately if you input some invalid value like “foo” in age field and leave focus.)
Oh! It actually works as expected. Somehow I switched the focus without typing anything into the field, and expected an error because the field was required. Then I assumed that there was no validation on blur.
Okay, so only you have to do is just running decoders for fields:
ageError : RegistrationForm -> Html msg ageError form = div [ class "error-field" ] <| List.map (\err -> p [ class "error-text" ] [ text err ]) <| Decoder.errors age_ form
FYI, my sample form does not warn till pressing register button for EFO, but you could warn required field when blur by handling blur event.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.