I tried DatePicker and EnhancedDatePicker, but I’m not comfortable with their validation, parsing and reformatting back and I’d like to do them by myself.
Is there a way I can get my hands on the text the user actually enters in a DatePicker or EnhancedDatePicker, whether valid or not? So I can do the validation, parsing and reformatting it back with my own rules.
Note: I’m basically searching for Vaadin14 version of the old .handleUnparsableDateString() method in Vaadin 8.
I think there is no such way in those components. EnhancedDatePicker though has quite good options to customize input formatting, so I would be curious to know why it does not suffice in your case?
Tatu Lund:
EnhancedDatePicker though has quite good options to customize input formatting, so I would be curious to know why it does not suffice in your case?
EnhancedDatePicker is, indeed, quite enhanced
But it has some issues for me:
Like its ancestor DatePicker, it didn’t support dates with year before 100, i.e.: 13/01/84 or 13/01/0084 (January 13th 84, not 1984 or 2084) were parsed as 13/01/1984 (on client-side, while the server would see 13/01/0084).
This however was superseded by following the advices in https://cookbook.vaadin.com/date-picker-pattern and modifying the JavaScript code to initialize the JavaScript Date() passing an ISO-8601-formatted string instead of a (year, month, day) triple.
Which, IMHO, should be the default: https://github.com/vaadin/vaadin-date-picker/issues/792.
The second problem is that I need the parser to be stricter and adhere to all and only the formats I pass to it.
For example, setting “dd/MM/yyyy” as parser also allows “dd/MM/yy”, which is not always the desired behaviour (let alone the bug reported above).
The third problem is that when the input is wrong (i.e.: “th8vbiuhbi” or “30/02/2021”) I want the field to be set to null. And I can’t do that right now, because the field is still filled with the wrong value but internally it seems to keep the old one.