OpenSlides/client/src/app/shared/parent-error-state-matcher.ts
Maximilian Krambach 5c1092b537 implement settings
Whats still missing, but has not a high priority:
- DateTimePicker. Entering dates through the popup works (but only with
a hack in the config-field.component update() method). Displaying values
from the server does not work. Also the localisation is missing. See
attempts to fix it in the sheared module.
- Errors, if the server cannot be reached. Should be solved in another
PR fixing the datasendservice and make generic error messages.
- Custom translations are missing
2018-10-09 13:06:44 +02:00

23 lines
943 B
TypeScript

import { ErrorStateMatcher } from '@angular/material';
import { FormControl, FormGroupDirective, NgForm } from '@angular/forms';
/**
* Custom state matcher for mat-errors. Enables the error for an input, if one has set the error
* with `setError` on the parent element.
*/
export class ParentErrorStateMatcher implements ErrorStateMatcher {
public isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const isSubmitted = !!(form && form.submitted);
const controlTouched = !!(control && (control.dirty || control.touched));
const controlInvalid = !!(control && control.invalid);
const parentInvalid = !!(
control &&
control.parent &&
control.parent.invalid &&
(control.parent.dirty || control.parent.touched)
);
return (isSubmitted || controlTouched) && (controlInvalid || parentInvalid);
}
}