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

'change' is called when the input looses focus, even if the value is not changed #33

Open
Em-Ant opened this issue Mar 9, 2017 · 2 comments

Comments

@Em-Ant
Copy link

Em-Ant commented Mar 9, 2017

The change function is called even if the field value is not changed, when the input field loses its focus. If I execute async db requests when the change event occurs, this will not be efficient. IMHO the change event should only be fired if the input field value is actually changed. What do you think ?

@kaivi
Copy link
Owner

kaivi commented Jun 1, 2017

Tested it a bit. Indeed it does trigger change(), but only once on first focus and only on RIENumber. Will get back to it when I'm using the lib again.

@FizzyGalacticus
Copy link

This happens because of the comparison taking place in RIEStatefulBase:

if(result && this.props.value !== newValue)
    this.commit(newValue);

It's using the !== comparator, which compares types of the objects as well. Since the initial value is presumably a number, but the new value becomes a string, they are treated as different.

Changing comparison to != automatically converts both to the same type, and the validation checks out.

I'm not sure if this is the best way to do it, although I don't see anything inherently wrong with this, since we're just dealing with text/numbers.

I'll submit a PR.

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

No branches or pull requests

3 participants