mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2025-04-28 02:53:11 +00:00
37 lines
1.2 KiB
TypeScript
Executable File
37 lines
1.2 KiB
TypeScript
Executable File
import {Component} from '@angular/core';
|
|
import {FormControl, FormGroupDirective, NgForm, Validators} from '@angular/forms';
|
|
import {ErrorStateMatcher} from '@angular/material/core';
|
|
|
|
/** Error when invalid control is dirty, touched, or submitted. */
|
|
export class MyErrorStateMatcher implements ErrorStateMatcher {
|
|
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
|
|
const isSubmitted = form && form.submitted;
|
|
return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted));
|
|
}
|
|
}
|
|
|
|
/** @title Select with a custom ErrorStateMatcher */
|
|
@Component({
|
|
selector: 'select-error-state-matcher-example',
|
|
templateUrl: 'select-error-state-matcher-example.html',
|
|
styleUrls: ['select-error-state-matcher-example.css'],
|
|
})
|
|
export class SelectErrorStateMatcherExample {
|
|
selected = new FormControl('valid', [
|
|
Validators.required,
|
|
Validators.pattern('valid'),
|
|
]);
|
|
|
|
selectFormControl = new FormControl('valid', [
|
|
Validators.required,
|
|
Validators.pattern('valid'),
|
|
]);
|
|
|
|
nativeSelectFormControl = new FormControl('valid', [
|
|
Validators.required,
|
|
Validators.pattern('valid'),
|
|
]);
|
|
|
|
matcher = new MyErrorStateMatcher();
|
|
}
|