Reason for the "Elm way" of retrieving HTML input values?

It is more of an intentional decision and it is related to how Elm views state.

The Html functions are conceptually pure. Of course, the actual nodes that they produce are still stateful due to the underlying implementation but as far as Elm is concerned, they are considered stateless.

So, input [] [], from Elm’s perspective, is an empty input field that is always empty.

getValue myInput makes not sense (conceptually) in Elm since you give myInput the value that it holds (conceptually).

Note that for :

input [] [],
button [] [text "Submit"]

you can still extract the value of the input using decoders and the fact that it is the previousSibling of the button BUT that is not advisable. It would be the equivalent of breaking encapsulation and relying on some internal representation that might change.

6 Likes