-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ff8d87
commit 84841d0
Showing
5 changed files
with
61 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,45 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {InjectionToken} from '@angular/core'; | ||
import {NgControl, FormGroupDirective, NgForm} from '@angular/forms'; | ||
|
||
/** Injection token that can be used to specify the global error options. */ | ||
export const MD_ERROR_GLOBAL_OPTIONS = | ||
new InjectionToken<() => boolean>('md-error-global-options'); | ||
new InjectionToken<ErrorOptions>('md-error-global-options'); | ||
|
||
export type ErrorStateMatcherType = | ||
export type ErrorStateMatcher = | ||
(control: NgControl, parentFormGroup: FormGroupDirective, parentForm: NgForm) => boolean; | ||
|
||
export interface ErrorOptions { | ||
errorStateMatcher?: ErrorStateMatcherType; | ||
showOnDirty?: boolean; | ||
errorStateMatcher?: ErrorStateMatcher; | ||
} | ||
|
||
export class DefaultErrorStateMatcher { | ||
|
||
errorStateMatcher(control: NgControl, formGroup: FormGroupDirective, form: NgForm): boolean { | ||
const isInvalid = control && control.invalid; | ||
const isTouched = control && control.touched; | ||
const isSubmitted = (formGroup && formGroup.submitted) || | ||
(form && form.submitted); | ||
|
||
return !!(isInvalid && (isTouched || isSubmitted)); | ||
} | ||
} | ||
|
||
export class ShowOnDirtyErrorStateMatcher { | ||
|
||
errorStateMatcher(control: NgControl, formGroup: FormGroupDirective, form: NgForm): boolean { | ||
const isInvalid = control && control.invalid; | ||
const isDirty = control && control.dirty; | ||
const isSubmitted = (formGroup && formGroup.submitted) || | ||
(form && form.submitted); | ||
|
||
return !!(isInvalid && (isDirty || isSubmitted)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters