This module provides the update helpers. Please refer to the
examples for a better understanding
Creates a form message that updates a string Field
Creates a form message that updates a bool Field
This function will update a Form for you. Once you have implemented the
form Msg, use it to update the Form
yourUpdate : YourMsg -> Model -> Model
yourUpdate msg model =
case msg of
SomeForm formMsg ->
{ model
| yourForm = Forms.Update.updateForm formMsg model.yourForm
}
...Sometimes you will need to have more control over a field update/event, that is what the side-effects helpers are for.
Helps defining Cmd on string Field events. You can use this function
to run commands when an event is triggered on a specific string Field.
yourUpdate : YourMsg -> Model -> ( Model, Cmd YourMsg )
yourUpdate msg model =
case msg of
SomeForm formMsg ->
let
newModel =
{ model
| yourForm = updateForm formMsg model.yourForm
}
in
stringFieldCommands newModel formMsg someFormCommands
...
someFormCommands : Model -> String -> String -> ( Model, Cmd YourMsg )
someFormCommands model key value =
case key of
"field-name" ->
( changeOrNotTheModel model
, doSomeCommandsWithTheValue value
)
...
_ ->
( model
, Cmd.none
)Note: this function only defines commands for the stringFieldMsg
Helps defining Cmd on bool Field events. You can use this function
to run commands when an event is triggered on a specific bool Field.
Note: this function only defines commands for the boolFieldMsg
Helps defining Cmd on both string and bool Field events.
formCommands
model
formMsg
yourStringFieldCommands
yourBoolFieldCommands
These are the form
Msg, they help updating aField.You need to implement them in your
Msg,updatefunction and use the helpers in your view events.stringFieldMsgis for stringField(input, select) andboolFieldMsgis for boolField(checkbox)Note: you will want to name your message according to the form it is handling in order to avoid confusion when using multiple forms