Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker breaks when using one-digit year #6771

Open
gunnarschmid opened this issue Nov 1, 2024 · 5 comments
Open

DatePicker breaks when using one-digit year #6771

gunnarschmid opened this issue Nov 1, 2024 · 5 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation Impact: Low vaadin-date-picker

Comments

@gunnarschmid
Copy link

Description

We use DatePicker also for partial dates, e. g. "end of business year" where only day and month are relevant. We initialize the LocalDate object backing the DatePicker with year = 0, but this breaks the component. The set date format is not applied anymore and no other value can be selected. After some testing it turns out that this happens when the year is set to any one-digit number, but it works if the year is >= 10.

image

Expected outcome

The component is expected to work also with years < 10. It should look like this:

image

Minimal reproducible example

DatePicker dp = new DatePicker("Datum");
dp.setValue(LocalDate.of(0, 3, 1));
dp.setI18n(new DatePicker.DatePickerI18n().setDateFormat("dd.MM."));
add(dp);

Steps to reproduce

Create a DatePicker as described above, check the result in the browser. Try to select a value in the calendar popup.

Environment

Vaadin version(s): 24.5.2
OS: Windows 10 22H2
JDK: OpenJDK 21.0.2

Browsers

Issue is not browser related

@rolfsmeds
Copy link
Contributor

This is not quite the intended or supported usage of the DatePicker – if you only want a month and a day, you probably should not use a field type that works with full dates anyway; a custom input consisting of a month and a date dropdown would probably be more appropriate, both programmatically and in terms of UX (after all, the user hardly has any use for the calendar dropdown in this use case either).

The DatePicker does indeed not support years < 10. This should be noted in the documentation.

@rolfsmeds rolfsmeds added documentation Improvements or additions to documentation and removed bug Something isn't working Severity: Minor Impact: Low labels Nov 14, 2024
@gunnarschmid
Copy link
Author

Then you end up having to consider all the logic if date/month/year in combination are valid, see also #6749

Not supporting years < 10 sounds to me to be a bug rather than a documentation issue.

@rolfsmeds rolfsmeds added bug Something isn't working Impact: Low labels Nov 14, 2024
@rolfsmeds
Copy link
Contributor

Then you end up having to consider all the logic if date/month/year in combination are valid, see also #6749

Yes you do. Regardless, a calendar picker is simply not the appropriate UI component for selecting a month and a date, without a year.

As for y<10 support, let's call it both a bug and a documentation issue.

@gunnarschmid
Copy link
Author

Yes you do. Regardless, a calendar picker is simply not the appropriate UI component for selecting a month and a date, without a year.

I totally agree. That makes it so inconvenient that there is no successor to the old DateField component. We have to migrate ca. 50 applications from Vaadin 8 to 24 and most of them use dates in one or the other way.

@rolfsmeds
Copy link
Contributor

Indeed, the V8 DateField was in some ways much more flexible.

For your migration, I would recommend implementing your own day+month field, e.g. based on two Selects or ComboBoxes wrapped into a CustomField. Checking the validity of the supplied date (e.g. by trying to instantiate a LocalDate from it), and showing a validation error when needed, would be fairly easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation Impact: Low vaadin-date-picker
Projects
None yet
Development

No branches or pull requests

3 participants