Potential Bug - text.setValue() not consistent

Snippet: Code Snippet

If you fill in the textfield and hit enter, it should always clear the field (set the value to ‘’).

This works as expect the first time. However, if you then proceed to fill in the data again and press enter again, nothing will happen. It does reach the .setValue(’’) method (as evidenced by the webix.message) but it doesn’t clear the field. Pressing enter a second time (third time in absolute terms) does clear it.

Every fill after the first requires two enter presses to remove the data.

This is a major issue in an app I’m currently prototyping which uses a barcode scanner. The input field needs to be cleared after each read.

https://webix.com/snippet/9b52ea75 webix.delay usually helps in such situations

Thank you, this fixes it in safari. However, another problem still occurs in chrome. If you input the same string (‘123’, enter, ‘123’, enter), the second enter won’t clear it.

I’ve worked around the issue by having a webix.delay(this.setValue, this, [“1”]); before the webix.delay(this.setValue, this, [""]); and it seems to work, but I doubt this is the best way to fix it.

Hello,

You’ve ran into a conflict between a custom ‘enter’ key handler and the default one. The default logic compares the entered value with the current one (config.value) and applies the new value to the control only in case it differs from the current value.

That’s why such pattern will not work - the inner value is already empty and cannot be reset.

If you input the same string (‘123’, enter, ‘123’, enter), the second enter won’t clear it.

So, to overcome this, you can write the entered value into the config before clearing it:

this.config.value = this.getInputNode().value;
this.setValue("");

Or, if you need to clear the text field both on pressing the enter key and when the focus moves away, you can catch the onChange event:

onChange:function(){
       this.blockEvent('');
       this.setValue('');
       this.unblockEvent('');
}

Check the related snippet, please: https://webix.com/snippet/159adebb

Cheers, that worked perfectly.