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

Number input not firing onChange #10370

Closed
ghost opened this issue Aug 3, 2017 · 13 comments
Closed

Number input not firing onChange #10370

ghost opened this issue Aug 3, 2017 · 13 comments

Comments

@ghost
Copy link

ghost commented Aug 3, 2017

I don`t know if it is bug or feature, but since you put into input with type number two minuses it will stop calling onChange callback, but value inside input will change

React 15.4.2
Browser Version 60.0.3112.90 (Official Build) (64-bit)

@jquense
Copy link
Contributor

jquense commented Aug 3, 2017

Can you provide a reproduction in a jsfiddle or other similar tool?

cc @nhunzaker

@jquense jquense changed the title Not firing onChange Number input not firing onChange Aug 3, 2017
@ghost
Copy link
Author

ghost commented Aug 3, 2017

Tried on jsfiddle, but it works there, strange

@ghost
Copy link
Author

ghost commented Aug 3, 2017

<input type="number" 
       className="form-control"
       value={typeof this.state.value !== 'undefined' && this.state.value !== null ? this.state.value : ''}
       onChange={e => this.onChange(e.target.value)} />
onChange(value) {
    const VALUE = parseFloat(value);

    this.setState({ value: VALUE >= 0 && !isNaN(VALUE) ? value : '' });
}

@Fasani
Copy link

Fasani commented Aug 4, 2017

It is odd that it would work with JSFiddle but not for you locally.

type=number may only work with the HTML 5 doctype. Did you specify HTML 5? (This is the only thing I can think without seeing more code.)

@shablenko
Copy link

Yes, i specified HTML 5

@antwan
Copy link

antwan commented Aug 8, 2017

It does the same with <input type=radio> elements.

On this codepen, if you click on "one", then "two", then "one", then "two", only the first two onChange events are fired. Expected behaviour is to have the value changing everytime.

I tested with several HTML elements, but some of them are working (checkboxes for example).

Reproducible since 15.6.0, working with previous versions.
This is kind of a big deal as it's breaking our app, and surely many others.

@jquense
Copy link
Contributor

jquense commented Aug 8, 2017

@Antwan86 yup we are already aware of that issue, it's unrelated to this one though

@antwan
Copy link

antwan commented Aug 8, 2017

My bad just saw the appropriate ticket. Keep up the good work!

@aweary
Copy link
Contributor

aweary commented Aug 8, 2017

This is mostly a duplicate of #6556. Here's an example that can reproduce the issue. If you type -- and then start typing numbers the value appears to change but React isn't firing change events because the value is invalid. This same thing happens with other accepted non-numerical characters like e

@mpelham
Copy link

mpelham commented Aug 9, 2017

@Antwan86 your codepen was a great example of the issue. I made a minor fork of it and pinned it to 15.5.4 to highlight the issue in the hopes that others looking for a solution find this thread.

15.5.4:
https://codepen.io/anon/pen/RZVwYz

15.6.1
https://codepen.io/anon/pen/ayJMvL

@oliviertassinari
Copy link
Contributor

oliviertassinari commented Sep 12, 2017

The issue can be reproduced with @next: https://jsfiddle.net/ugr5sp1q/

@aweary
Copy link
Contributor

aweary commented Sep 15, 2017

Since the root cause is the same, I'm going to close this as a duplicate of #10370.

@oliviertassinari
Copy link
Contributor

oliviertassinari commented Nov 8, 2017

@aweary The issue can be reproduced in the v0.16.0 version: https://jsfiddle.net/d4a52zdk/. The issue can't be a duplicate of itself. You might want to reopen it.

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

7 participants