Simple forms made easy: A Dict implementation of the core Json.Decode
API,
with state lifecycle and input helpers for the views.
Form messages for update
.
Input types to determine live validation behaviour.
Form to embed in your model. Type parameters are:
customError
- a custom error type to extend built-in errors (set to ()
if you don't need it)output
- the type of the validation output.{ path : String
, value : Maybe a
, error : Maybe (ErrorValue e)
, liveError : Maybe (ErrorValue e)
, isDirty : Basics.Bool
, isChanged : Basics.Bool
, hasFocus : Basics.Bool
}
Field state containing all necessary data for view and update,
can be retrived with Form.getFieldAsString
or Form.getFieldAsBool
.
path
- qualified path of the field in the form, with dots for nested fields (field.subfield
)value
- a Maybe
of the requested typeerror
- a Maybe
of the field errorliveError
- same but with added logic for live validation
(see getLiveErrorAt
impl)isDirty
- if the field content has been changed since last validationisChanged
- if the field value has changed since last init/resethasFocus
- if the field is currently focusedinitial : List ( String, Field ) -> Validate.Validation e output -> Form e output
Initial form state. See Form.Field
for initial fields, and Form.Validate
for validation.
update : Validate.Validation e output -> Msg -> Form e output -> Form e output
Update form state with the given message
getFieldAsString : String -> Form e o -> FieldState e String
Get field state at path, with value as a String
.
getFieldAsBool : String -> Form e o -> FieldState e Basics.Bool
Get field state at path, with value as a Bool
.
getListIndexes : String -> Form e o -> List Basics.Int
return a list of indexes so one can build qualified names of fields in list.
getFocus : Form e o -> Maybe String
Return currently focused field, if any.
isSubmitted : Form e o -> Basics.Bool
Get form submission state. Useful to show errors on unchanged fields.
getErrors : Form e o -> List ( String, ErrorValue e )
Get list of errors on qualified paths.
getOutput : Form e o -> Maybe o
Get form output, in case of validation success.
getChangedFields : Form e o -> Set String
Get set of changed fields.