I have a valuechangelistener on a datefield that will complete various checks and and if a new correct date value is not entered it will set the datefield back to the previous value.
I am using the datefield.addValueChangeListener(dateValueChangeEvent -> and also a datefield.setvalue function. Everything works fine and as expected however I have identified a problem and I am unsure if it is something I am doing incorrectly or if it is a bug. When using the keypad to enter the date (not the date picker calendar) the addValueChangeListener does not fire in the following circumstances:
Enter new date in field, say 01-01-2001 (addValueChangeListener fires)
Enter new date in field, say 01-01-2002 (addValueChangeListener fires and sets date back to previous value 01-01-2001)
Enter same date (01-01-2002) back into datefield. (addValueChangeListener does not fire)
I have created a sample project and attached, however the code is as follows:
startDateField.addValueChangeListener(dateValueChangeEvent -> {
if (dateValueChangeEvent.isUserOriginated()) {
if (dateValueChangeEvent.getPrevValue() != null) {
startDateField.setValue(dateValueChangeEvent.getPrevValue());
}
}
}
Unfortunately, I can’t reproduce the problem, even in the attached project. The field value is successfully returned to the previous value whatever way is used (keyboard or calendar picker).
As you can see on the pic. two events are generated user originated true (value changed using a keyboard) and false for programmatically setting the field value to the prev. value.
Thank you for your response. Can you confirm that you are manually entering ‘exactly’ the same date twice. 1st entry and then again straight after the valuechange listener has run and reset the value. We have tried it on different machines here and it’s behaviour is consistent with the problem initially described.
I am really confused as this is consistently not working on various development machines here. I’ve also just tried a different platform version to see if there is an issue but I’m still getting the same problem. I’ve uploaded a video to show how this is performing and you can see the following:
enter initial date
change date (which calls the valuechange listener and changes back to initial value)
enter same value again
value listener does not fire and value in datefield box does not run
on save it does not save the values in the datefield but the initial value
Thank you for the video, I found the difference. You try to change a value by focus loss, I used Enter. In your case, I admit that there is a bug, I’ve created a GitHub issue.