elm / html

Use HTML in Elm!
https://package.elm-lang.org/packages/elm/html/latest/
BSD 3-Clause "New" or "Revised" License
395 stars 99 forks source link

Setting the value of number input elements #205

Open ursi opened 4 years ago

ursi commented 4 years ago

If you have an input element of type number that has an invalid input. Trying to set that input back to nothing via the Elm equivalent of numberInput.value = "" does not work.

Here is an Ellie to demonstrate what I'm talking about.

If you try to type in a number, nothing will show up. This is what you'd expect, as value is constantly being set to "". However, if you type something invalid, such as some combination of e, E, ., and -, you'll notice that you're allowed to type this.

Turns out that if a number input is invalid, its value property will return "". That being said, if you set the value of it to "" explicitly, it will change the input to be nothing.

My guess here is that Elm's virtual DOM is checking the value of the input with .value, seeing that it equals "", and then concluding that nothing needs to be changed.

It doesn't seem like there's any way to get the true value out of a number input, so it would seem like the only fix for this (assuming my diff hypothesis is correct) is to just always execute numberInput = "" regardless of the diff.