niho/json-schema-form/1.0.0

NOTE: the latest version is 3.0.0

Json.Schema.Form

Generate validating forms from JSON schemas.

Types

type alias Options =
{ errors : Errors
, formats : Formats
}

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).
type alias State =
{ options : Options
, schema : Schema
, form : Form ErrorValue Value
}

The form state.

type alias Msg =
Msg

Form messages for update.

Init/update lifecycle

init : Options -> Schema -> State

Initialize a form state with options and a schema.

update : Msg -> State -> State

Update the form state.

View

view : State -> Html Msg

The form fields as HTML. Use together with onSubmit to submit the form.

onSubmit : Attribute Msg

Triggers the form to be submitted for validation.

form [ Json.Schema.Form.onSubmit ]
    [ Json.Schema.Form.view state
    , button [] [ test "Submit" ]
    ]