jmpavlick / elm-html-form / Html.Form.Validation

Validation


type alias When =
Internals.InvalidateWhen

Describes when a validation should occur.

when : { 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.

andThen : ({ 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.