jmpavlick/elm-html-form/2.0.0

NOTE: the latest version is 2.0.2

Html.Form.Validation

Validation

type alias When =
InvalidateWhen

Describes when a validation should occur.

{ editingOrBlurred :
( { self : editor
, other : editor
}
-> Result error editor
)
-> Validation error value editor
, blurredAfterEdit :
( { self : editor
, other : editor
}
-> Result error editor
)
-> Validation error value editor
, always :
( { self : editor
, other : editor
}
-> Result error editor
)
-> Validation error value editor
}

Constructor record; you can use the dot operator to select a When value, which returns a function that takes a function that validates the current Field.

In the callback, self represents the current editor, and other represents any other editor. If you don't want to validate a given field against another field, you can ignore this value in your callback.

( { self : editor
, other : editor
}
-> Result error editor
)
-> Validation error value editor
-> Validation error value editor

Provide additional validations sequentially.

For instance: if you only want to show an error that says that user input is bad after the field has been edited - but if you want to show an error that says that the field must be non-empty - you could add the "field must be non-empty" callback with when, and "chain" the "the field must match a given pattern" value with andThen.