yoghurt-x86 / easy-forms / Form.Html

This is where you compose your forms! This particular form package is compatible with elm/html.

Definition


type alias SimpleForm value =
FormT value value value ()

Simplest form shape


type alias Form value validated context =
FormT value value validated context

Expanded form shape


type FormT value valid validated context

Original Form type used internally

Using a form:

viewSimple : SimpleForm value -> List (Html (SimpleForm value))

View function for the form

This returns a list of Html. Each item in the list corresponds to a field in the form.

You can easily put the list of fields in a div or another html elements:

div []
    (view () form)

view : context -> Form value validated context -> List (Html (Form value validated context))

Render a form that requires a context

get : Form value validated context -> value

Get the current input value

isValid : context -> Form value validated context -> Result (Form value validated context) validated

Check if all fields pass all hints and parse to their resulting type.

Composing forms:

append : Form.Field.Field valid a state msg error context localCtx (Html (Form.Field.FieldMsg msg)) -> FormT (a -> value) valid (a -> value) context -> FormT value valid value context

Append another field in your form pipeline!

succeed : value -> validated -> FormT value valid validated context

Start of the pipeline

You can compose a new a form in the following fashion:

Form.succeed Input Input
    |> Form.append text
    |> Form.append textArea
    |> Form.append password
    |> Form.append select
    |> Form.append color
    |> Form.append date
    |> Form.append number
    |> Form.append checkBox
    |> Form.append file

hardcoded : a -> FormT (a -> value) valid (a -> value) context -> FormT value valid value context

Append a hardcoded value in your form pipeline!

Form.succeed Input Input
    |> Form.append text
    |> Form.hardcoded "name"

appendParsed : Form.Field.Parser valid b error -> Form.Field.Field valid a state msg error context localCtx (Html (Form.Field.FieldMsg msg)) -> FormT (a -> value) valid (b -> validated) context -> FormT value valid validated context

Append another field in your form pipeline.

This time adding a parser step.

hardcodedParsed : Form.Field.Parser valid b error -> a -> FormT (a -> value) valid (b -> validated) context -> FormT value valid validated context

Append a hardcoded value in your form pipeline!

This time adding a parser step.