Datefield addValueChangeListener set to previous value issue

listenertest.zip (500.5 KB)
Hi

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:

  1. Enter new date in field, say 01-01-2001 (addValueChangeListener fires)
  2. Enter new date in field, say 01-01-2002 (addValueChangeListener fires and sets date back to previous value 01-01-2001)
  3. 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());
}
}
}

Any help or thoughts would be appreciated.

Thanks
David

Hi,

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).

39

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.

Regards,
Gleb

Hi Gleb

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.

Thanks
David

What I did according to your description:

  1. Entered 01-01-2001
  2. Changed value to 01-01-2002. As a result, value set back to 01-01-2001
  3. Again, set value to 01-01-2002. As a result, value set back to 01-01-2001
  4. Repeat

Gleb

Hi Gleb

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:

  1. enter initial date
  2. change date (which calls the valuechange listener and changes back to initial value)
  3. enter same value again
  4. value listener does not fire and value in datefield box does not run
  5. on save it does not save the values in the datefield but the initial value

Thanks
David

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.

Regards,
Gleb

Thanks Gleb.