Link HTML inputs to model values?

In some examples (“An Introduction to Elm”) the input values are not tied back to the model values, while in other programs, they are:

view model =
    input [ onInput Name ] []

view model =
    input [ onInput Name, value model.name ] []

What are the reasons to link or not link the value to the stored model value?

value attribute can behave strangely.

see this tracking issue for more information.

2 Likes

By binding the value to your model, you are making it display whatever is in there, irrespective of where it was updated from.
In your 2 examples, the first one will only trigger the Name message and you will be able to do whatever you want with it in your update function. The second one will do that, but also initialize and keep updated the value with whatever is in model.name, and if you change it, it will be reflected in your input.

2 Likes

One thing I have noticed with debois/elm-mdl is that if you use floating labels and you do not set value model.name then the label does not float it stays on top of the input.