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

String values for input[type='number'] & input[type='range'] #1425

Closed
sudodoki opened this issue Apr 18, 2014 · 5 comments
Closed

String values for input[type='number'] & input[type='range'] #1425

sudodoki opened this issue Apr 18, 2014 · 5 comments

Comments

@sudodoki
Copy link

Enhancement proposal: create numberLink or make e.target.value return value of type number for input with types range & number.
Reasoning:

  • if you have input type number, you would expect it's value to be string (duh thing that might have been historical attainment?)
  • LinkedValueUtils seems to have some different handling for handling string & boolean values
  • if you init your state with number & use valueLink, it will initialize input properly but second you change input value it will change to string (and possibly explode something, say, child property depending on it to be of type number)

Partial work around would be using

handleChange: function(newValue) {
    this.setState({
        value: parseInt(newValue, 10)
    })
},
...
render: function() {
    var valueLink = {
        value = thist.state.value, requestChange: this.handleChange
    }
    return <input type = 'number' valueLink = {valueLink} />
}

According to docs.
Demonstration of number & range inputs for React & vanilla js in jsbin.

@syranide
Copy link
Contributor

syranide commented May 1, 2014

Seems like a :+1 if it can be reasonably solved, I'm curious though, is it possible to somehow cause those inputs to give anything BUT numbers? Say if you were to manually enter text into them or clear them?

@syranide
Copy link
Contributor

Reporting value '' of type="number" as 0 is not a good idea and it's probably not a good idea to report it as NaN either, but that could make sense though... but probably not.

@nhunzaker
Copy link
Contributor

ReactNative's Input has an onChangeText property. Providing something similar for how to deal with number input values could be a really nice addition (though some would argue this should happen in user land).

We'd probably need to figure out:

  1. What to do about bad input
  2. How to handle the empty case (where numbers report '')
  3. Probably something else

Is this feature worth considering, or are we comfortable pushing this to the community?

@aweary
Copy link
Contributor

aweary commented Jul 12, 2017

@nhunzaker I think it's reasonable to push this to the community. There doesn't seem to be a high demand for this in React core, so let's defer to user-land and close this out 👍

@aweary aweary closed this as completed Jul 12, 2017
@SamsonChoo
Copy link

May I ask why was this closed and what is the solution? Intuitively I would think that a number type input would return a number type value, right?

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

5 participants