riek
riek copied to clipboard
'change' is called when the input looses focus, even if the value is not changed
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 ?
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.
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.