Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,22 @@ <h2 class="filter-dialog-title" mat-dialog-title>{{ data.title }}</h2>
<mat-label>Dates</mat-label>
<mat-date-range-input>
<input
[errorStateMatcher]="dateMatcher"
matStartDate
placeholder="mm/dd/yyyy"
[(ngModel)]="range.start"
#startDate="ngModel"
(dateChange)="startDateChanged($event)" />
<input
[errorStateMatcher]="dateMatcher"
matEndDate
placeholder="mm/dd/yyyy"
[(ngModel)]="range.end"
#endDate="ngModel"
(dateChange)="endDateChanged($event)" />
</mat-date-range-input>
<mat-error
*ngIf="
(startDate.invalid && (startDate.dirty || startDate.touched)) ||
(endDate.invalid && (endDate.dirty || endDate.touched))
"
*ngIf="startDate.invalid || endDate.invalid"
role="alert"
aria-live="assertive">
<span>Please, select the correct date range in mm/dd/yyyy format.</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import {
FormBuilder,
FormControl,
FormGroup,
FormGroupDirective,
FormsModule,
NgForm,
NgModel,
ReactiveFormsModule,
} from '@angular/forms';
Expand All @@ -52,7 +54,7 @@ import {
MatDatepickerInputEvent,
MatDatepickerModule,
} from '@angular/material/datepicker';
import { MatNativeDateModule } from '@angular/material/core';
import { ErrorStateMatcher, MatNativeDateModule } from '@angular/material/core';
import {
FilterName,
DateRange as LocalDateRange,
Expand All @@ -64,6 +66,22 @@ import {
} from '../../../../model/testrun-status';
import { DeviceValidators } from '../../../devices/components/device-form/device.validators';

class DateErrorStateMatcher implements ErrorStateMatcher {
isErrorState(
control: FormControl | null,
form: FormGroupDirective | NgForm | null
): boolean {
const isSubmitted = form && form.submitted;
return !!(
control &&
control.errors &&
control.errors['matDatepickerParse'].text.trim().length > 0 &&
control.invalid &&
(control.touched || isSubmitted)
);
}
}

interface DialogData {
trigger: ElementRef;
filter: string;
Expand Down Expand Up @@ -244,6 +262,8 @@ export class FilterDialogComponent
this.dialogRef.close();
}

dateMatcher = new DateErrorStateMatcher();

startDateChanged(event: MatDatepickerInputEvent<Date>) {
const date = event.value;
if (date && date.getFullYear() > this.today.getFullYear()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export interface OpenFilterEvent {

@Component({
selector: 'app-filter-header',

imports: [
MatIconModule,
MatButtonModule,
Expand Down