This module contains a type that represents a generic form field.
Note: You should not need to care about this unless you are creating your own custom fields or writing custom view code.
{ value : value
, update : value -> values
, attributes : attributes
}
Represents a form field.
It contains:
value
of the fieldupdate
function that takes a new field value and returns updated
form valuesattributes
of the fieldThese record fields are normally used in view code to set up the value
and onInput
attributes. For example, you could render a TextField
like this:
view : (values -> msg) -> Form values output -> values -> Html output
view onChange form values =
let
{ fields, result } =
Form.fill form values
fieldsHtml =
List.map (viewField onChange) fields
-- ...
in
Html.form
[-- ...
]
[ Html.div [] fieldsHtml
, submitButton
]
viewField : (values -> msg) -> ( Form.Field values, Maybe Error ) -> Html msg
viewField onChange ( field, maybeError ) =
case field of
Form.Text TextField.Raw { value, update, attributes } ->
Html.input
[ Attributes.type_ "text"
, Attributes.value value
, Attributes.onInput (update >> onChange)
, Attributes.placeholder attributes.placeholder
]
[]
_ ->
-- ...
mapValues : (a -> b) -> Field attributes value a -> Field attributes value b
Transform the values
of a Field
.
It can be useful to build your own Form.mapValues
function.