riek icon indicating copy to clipboard operation
riek copied to clipboard

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

Open Em-Ant opened this issue 7 years ago • 2 comments

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 ?

Em-Ant avatar Mar 09 '17 15:03 Em-Ant

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.

kaivi avatar Jun 01 '17 18:06 kaivi

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.

FizzyGalacticus avatar Mar 08 '18 21:03 FizzyGalacticus