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

TimePicker does not raise ErrorMessages of validator #20830

Open
RSM-CWI opened this issue Jan 10, 2025 · 6 comments
Open

TimePicker does not raise ErrorMessages of validator #20830

RSM-CWI opened this issue Jan 10, 2025 · 6 comments

Comments

@RSM-CWI
Copy link

RSM-CWI commented Jan 10, 2025

Description of the bug

The validation.defined Eroormessages are not shown below the timepicker-field anymore.

Expected behavior

The errormessages should be shown below the field as expected, as it works in all other fields an in Vaadin 23.5 an previous

image This shot is from the Vaadin 23 Version of our app.

Minimal reproducible example

@Id("angefangenUmTimePicker")
TimePicker angefangenUmTimePicker;

[..]

    angefangenUmTimePicker.setStep(Duration.ofMinutes(15));
    angefangenUmTimePicker.setMax(DateTimeHelper.getAktuelleUhrzeitMitVollen15Minuten().plusMinutes(30));
    
    binder.forField(angefangenUmTimePicker)
        .asRequired(Message.FIELD_NEEDS_TO_BE_SET.toString())
        .withValidator(localTime -> localTime.getMinute() % 15 == 0,
            "Bitte geben Sie die Uhrzeit in 15-Minuten Schritten ein."
        )
        .withValidator(
            localTime -> isBeginnValid(),
            "Der Beginn darf max. 30 Minuten (+ angebrochene 15 Minuten) in der Zukunft liegen."
        )
        .bind("beginn");        

...and then enter invalid values using the UI.

image

Versions

  • Vaadin / Flow version: 24.6.1
  • Java version: 21
  • OS version: Windows 10
  • Browser version (if applicable): Does not Matter. Chromw, Firefox, Edge... Current versions
  • Application Server (if applicable): SpringBoot 3.4.1
  • IDE (if applicable): IntelliJ Ultimate 24.2.4
@RSM-CWI
Copy link
Author

RSM-CWI commented Jan 10, 2025

I dug deeper into that! It is an issue on the order of the validators!

First case:

        binder.forField(angefangenUmTimePicker)
            .withValidator(
                localTime -> localTime.isBefore(LocalTime.of(11, 00)
                "Just before 11."
            )
            .withValidator(localTime -> localTime.getMinute() % 15 == 0,
                "15 minutes stps please."
            )
            .bind("beginn");

Now enter "12:00" as value into the time picker and the correct error message will be shown.
Now enter "10:11" as value into the time picker, the filed will turn red but NO (!) error message will be shown

Second case with reversed order of the validators:
First case:

        binder.forField(angefangenUmTimePicker)
            .withValidator(localTime -> localTime.getMinute() % 15 == 0,
                "15 minutes stps please."
            )
            .withValidator(
                localTime -> localTime.isBefore(LocalTime.of(11, 00)
                "Just before 11."
            )
            .bind("beginn");

Now enter "12:00" as value into the time picker, the filed will turn red but NO (!) error message will be shown-
Now enter "10:11" as value into the time picker and the correct error message will be shown.

This issue just esists in the time picker component.

@RSM-CWI
Copy link
Author

RSM-CWI commented Jan 10, 2025

Finally found the issue. I's different from described above. Sorry for that.
angefangenUmTimePicker.setMax(LocalTime.of(11, 0))

And even if you enter "12:00" teh validation Message of the respective validator wont be shown.

Sorry for the confusion.
This was a hard one...

In Vaadin 23 the behaviour was different. The validation message has been shown - even setMax hab been set.

@mshabarov
Copy link
Contributor

@vursen do you think this observation could be a consequence of validation behaviour changes that we made in Vaadin 24?

@vursen
Copy link
Contributor

vursen commented Jan 14, 2025

In Vaadin 23 the behaviour was different. The validation message has been shown - even setMax hab been set.

Starting from version 24.0, constraint validation has been enabled by default and runs before any custom Binder validators. However, defining error messages for constraints like setMin, setMax, etc., was not possible until version 24.5, which introduced a way to configure them using i18n objects.

I reviewed the JavaDoc for setMin, and it includes a @see tag referencing TimePickerI18n#setMinErrorMessage. However, this reference seems to be easy to overlook, so we could consider explicitly mentioning it in the documentation text to highlight this better.

@RSM-CWI
Copy link
Author

RSM-CWI commented Jan 14, 2025

Would'nt it be a solution to give the priority to the custom validators?
Anyways we fixed bi turning the default validation off, which should be mentiond in the documentation aswell...

@mshabarov mshabarov moved this from 🔎 Investigation to 🔖 Normal Priority (P2) in Vaadin Flow bugs & maintenance (Vaadin 10+) Jan 14, 2025
@vursen
Copy link
Contributor

vursen commented Jan 15, 2025

Anyways we fixed bi turning the default validation off, which should be mentiond in the documentation aswell...

Thanks for bringing this up. I was quite sure we already had a ticket for updating the Binder documentation, but I couldn't find any. I've created one now: vaadin/docs#4067

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🔖 Normal Priority (P2)
Development

No branches or pull requests

3 participants