Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting the value of number input elements #205

Open
ursi opened this issue Jan 17, 2020 · 0 comments
Open

Setting the value of number input elements #205

ursi opened this issue Jan 17, 2020 · 0 comments

Comments

@ursi
Copy link

ursi commented Jan 17, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant