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

bug(COMPONENT): TimePicker does not show mat-error #30180

Open
1 task
Klausmd5 opened this issue Dec 13, 2024 · 5 comments
Open
1 task

bug(COMPONENT): TimePicker does not show mat-error #30180

Klausmd5 opened this issue Dec 13, 2024 · 5 comments
Labels
needs triage This issue needs to be triaged by the team

Comments

@Klausmd5
Copy link

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

Using Angular 19 with Material 19

When trying to display a mat-error - even without form validation - it does not show.
When replacing the mat-error with mat-hint it does show correctly.

If i add mat-hint before adding mat-error, both messages show correctly.

Here is my example code:

    <mat-form-field>
        <mat-label>Checkin bis</mat-label>
        <input matInput [formControl]="checkInBisControl" [matTimepicker]="toHoursPicker"
          [(ngModel)]="placeData().checkInBis" />
        <mat-timepicker-toggle matIconSuffix [for]="toHoursPicker" />
        <mat-timepicker interval="1h" #toHoursPicker />

        @if(platzForm.hasError('checkInTimeInvalid')) {
        <mat-hint>
          <strong>Checkin-Zeit 'von' muss vor der Checkin-Zeit 'bis' liegen.</strong>
        </mat-hint>
        
        <mat-error>
          <strong>Checkin-Zeit 'von' muss vor der Checkin-Zeit 'bis' liegen.</strong>
        </mat-error>
        }
    </mat-form-field>

Reproduction

Stacklitz has some issues with angular material 19 - at least i am unable to do that

Expected Behavior

Show the error-message under the timepicker

Actual Behavior

Does only show if switched to mat-hint

Environment

  • Angular: 19.0.0
  • CDK/Material: 19.0.0
  • Browser(s): Chrome
  • Operating System (Windows 11):
@Klausmd5 Klausmd5 added the needs triage This issue needs to be triaged by the team label Dec 13, 2024
@crisbeto
Copy link
Member

It looks like you're using both ngModel and formControl on the same element which isn't supported. Have you tried removing one of them?

@Klausmd5
Copy link
Author

Yeah, I've removed ngModel, but it still does not work.

@crisbeto
Copy link
Member

What validators do you have set up?

@Klausmd5
Copy link
Author

What validators do you have set up?

This here. It definitley does return the right value. Even if I remove the if, the mat-error does not show up.

static checkInTimeValidator(): ValidatorFn {
        return (control: AbstractControl): ValidationErrors | null => {
            const checkInVon = control.get('checkInVon')?.value;
            const checkInBis = control.get('checkInBis')?.value;

            // Validation fails only if both times are defined and checkInVon is greater than or equal to checkInBis
            if (checkInVon && checkInBis && checkInVon >= checkInBis) {
                return { checkInTimeInvalid: true };
            }

            return null; // Kein Fehler, wenn die Zeiten korrekt sind oder eines der Felder leer ist
        };
    }

@crisbeto
Copy link
Member

It's a bit hard to say what might be going on here. We have similar examples in our docs that work fine. Can you post a Stackblitz showing the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue needs to be triaged by the team
Projects
None yet
Development

No branches or pull requests

2 participants