-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(checkbox): Add RequiredTrue validator for md-checkbox (#6006)
* Try to make screenshot image size same as before * change back to 1024 x 768 * Add MdCehckboxRequiredValidator * extends CheckboxRequiredValidator * Workaround for aot build error * Add doc * fix test
- Loading branch information
1 parent
a87a000
commit 59319d0
Showing
3 changed files
with
91 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @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 { | ||
Directive, | ||
forwardRef, | ||
Provider, | ||
} from '@angular/core'; | ||
import { | ||
CheckboxRequiredValidator, | ||
NG_VALIDATORS, | ||
} from '@angular/forms'; | ||
|
||
export const _MdCheckboxRequiredValidator = CheckboxRequiredValidator; | ||
|
||
export const MD_CHECKBOX_REQUIRED_VALIDATOR: Provider = { | ||
provide: NG_VALIDATORS, | ||
useExisting: forwardRef(() => MdCheckboxRequiredValidator), | ||
multi: true | ||
}; | ||
|
||
/** | ||
* Validator for Material checkbox's required attribute in template-driven checkbox. | ||
* Current CheckboxRequiredValidator only work with `input type=checkbox` and does not | ||
* work with `md-checkbox`. | ||
*/ | ||
@Directive({ | ||
selector: | ||
'md-checkbox[required][formControlName],' + | ||
'mat-checkbox[required][formControlName],' + | ||
'md-checkbox[required][formControl],md-checkbox[required][ngModel],' + | ||
'mat-checkbox[required][formControl],mat-checkbox[required][ngModel]', | ||
providers: [MD_CHECKBOX_REQUIRED_VALIDATOR], | ||
host: {'[attr.required]': 'required ? "" : null'} | ||
}) | ||
export class MdCheckboxRequiredValidator extends _MdCheckboxRequiredValidator {} |
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