Joey12
(Joey Chen)
December 3, 2018, 3:28pm
1
Hi,
I add value change listener, using addValueChangeListener, to a TextField, and I found that the listener was invoked when every key was pressed, instead of a complete value change. Even I set the value change mode to ON_CHANGE, it still behaved abnormally. This failure happens both in v11 and v12. Please kindly advise.
Best regards,
Joey
Diego159
(Diego Sanz Villafruela)
December 12, 2018, 2:19pm
2
As far as I know all the modes work correctly.
The behaviour of the different modes is the following:
EAGER: Syncs the value to the server each time it’s changed on the client. The event that triggers the synchronization is defined by the component.
ON_CHANGE: Syncs the value to the server on change event, i.e. when the component value is committed.
ON_BLUR: Syncs the value to the server on blur event, i.e. when the component looses focus.
You can try the following code to compare the differences between the different modes:
TextField textField1 = new TextField("Eager");
textField1.setValueChangeMode(ValueChangeMode.EAGER);
textField1.addValueChangeListener(event -> {
Notification.show(event.getValue());
});
TextField textField2 = new TextField("On change");
textField2.setValueChangeMode(ValueChangeMode.ON_CHANGE);
textField2.addValueChangeListener(event -> {
Notification.show(event.getValue());
});
TextField textField3 = new TextField("On blur");
textField3.setValueChangeMode(ValueChangeMode.ON_BLUR);
textField3.addValueChangeListener(event -> {
Notification.show(event.getValue());
});
add(textField1,textField2, textField3);