This module contains a value type for your form fields.
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
}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
}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.
Update a value with new data.
Note: You should not need to care about this unless you are creating your own custom fields.
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
}
}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.
Represents a form field value.