hecrj/composable-form/2.2.2

NOTE: this package is not compatible with Elm 0.19.1

Form.Value

This module contains a value type for your form fields.

Definition

type Value a

Represents a form field value.

Constructors

blank : Value a

A blank value.

Use this to initialize the values of your empty fields:

values : SignupValues
values =
    { email = Value.blank
    , password = Value.blank
    , rememberMe = Value.blank
    }
filled : a -> Value a

Build an already filled value.

Use this when you are using forms to edit existing values:

values : Profile -> ProfileValues
values profile =
    { firstName = Value.filled profile.firstName
    , lastName = Value.filled profile.lastName
    }

Queries

raw : Value a -> Maybe a

Obtain the data inside a Value.

If the value is blank, it returns Nothing, else it returns Just the value.

Note: You should only be using this in meta forms or custom view code.

Updates

update : a -> Value a -> Value a

Update a value with new data.

Note: You should not need to care about this unless you are creating your own custom fields.

Comparisons

newest : (values -> Value a) -> values -> values -> Value a

Select the newest value out of two sets of values.

This is necessary to fix an issue with autocompletion. When a form is autocompleted, many events can get triggered before the view can be rerendered, causing the first autocompleted values to be lost.

newest allows to fix this:

update : Msg -> Model -> Model
update msg values =
    FormChanged newForm ->
        { form |
            values =
                { email = Value.newest .email form.values newForm.values
                , password = Value.newest .password form.values newForm.values
                }
        }

Note: This issue seems fixed in Elm 0.19, thus this function will be removed soon.