diff --git a/src/app/account/register/password-error-state-matcher.spec.ts b/src/app/account/register/password-error-state-matcher.spec.ts new file mode 100644 index 0000000..75a6610 --- /dev/null +++ b/src/app/account/register/password-error-state-matcher.spec.ts @@ -0,0 +1,7 @@ +import { PasswordErrorStateMatcher } from './password-error-state-matcher'; + +describe('PasswordErrorStateMatcher', () => { + it('should create an instance', () => { + expect(new PasswordErrorStateMatcher()).toBeTruthy(); + }); +}); diff --git a/src/app/account/register/password-error-state-matcher.ts b/src/app/account/register/password-error-state-matcher.ts new file mode 100644 index 0000000..12aa1a9 --- /dev/null +++ b/src/app/account/register/password-error-state-matcher.ts @@ -0,0 +1,11 @@ +import { ErrorStateMatcher } from '@angular/material/core'; +import { FormControl, FormGroupDirective, NgForm } from '@angular/forms'; + +export class PasswordErrorStateMatcher implements ErrorStateMatcher { + isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { + const invalidControl = !!(control && control.invalid && control.parent.touched); + const invalidParent = !!(control && control.parent && control.parent.invalid && control.parent.touched); + + return invalidControl || invalidParent; + } +}