hecrj/composable-form/4.0.1

NOTE: the latest version is 8.0.1

Form.Value

This module contains a value type for your form fields.

Definition

type Value a

Represents a form field value.

Constructors

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.

Mappings

map : (a -> b) -> Value a -> Value b

Transform a value.

For instance, this can be useful if you want to use a Form.numberField with a Value Int instead of Value Float:

numberOfApples : Form { r | number : Value Int } Int
numberOfApples =
    Form.numberField
        { parser = round >> Ok
        , value = .number >> Value.map toFloat
        , update =
            \value values ->
                { values | number = Value.map round value }
        , attributes =
            { label = "How many apples do you have?"
            , placeholder = "Type a number"
            , step = 1
            , min = Just 0
            , max = Nothing
            }
        }