Generate validating forms from JSON schemas.
{ errors : Errors
, formats : Dict String Format
}
Customize the generated form.
errors
- A function that turns error values into user readable strings.formats
- A list of custom formats (see Json.Schema.Form.Format
).{ options : Options
, schema : Json.Schema.Definitions.Schema
, form : Form ErrorValue Value
}
The form state.
Form.Msg
Form messages for update
.
init : Options -> Json.Schema.Definitions.Schema -> State
Initialize a form state with options and a schema. Use json-tools/json-schema to parse or build a schema.
update : Msg -> State -> State
Update the form state.
view : State -> Html Msg
The form fields as HTML. Use together with submit
to submit the form.
submit : Msg
Triggers the form to be submitted for validation.
form [ onSubmit Json.Schema.Form.submit ]
[ Json.Schema.Form.view state
, button [] [ text "Submit" ]
]
getOutput : State -> Maybe Value
Get the output value of the form if it validates.
case Json.Schema.Form.getOutput state of
Just value ->
-- The `value` is a tree of all the fields in the form (see the
-- `Json.Schema.Form.Value` module).
-- Use the `Json.Schema.Form.Encode.encode` function to turn
-- it into a JSON value.
Nothing ->
-- If any field in the form is not valid `getOutput` will
-- return `Nothing`.