Elm form - show validation error only after leaving the field and no input was entered - dirty/visited

Viewed 174
1 Answers

You could use the blur event:

input [ on "blur" (Json.Decode.map FieldBlurred targetValue) ] []

This assumes a Msg constructor like this, which will receive the text of the text box on blur:

type Msg
   = ...
   | FieldBlurred String

Then in your update, handle the empty string appropriately:

case msg of
    FieldBlurred "" -> ...  -- invalid! 
    FieldBlurred val -> ... -- ok
Related