angular: A required checkbox should always be invalid if unchecked
I’m submitting a … (check one with “x”)
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
Given an <input type="checkbox">
with the required
attribute, ngModel
correctly considers it invalid to start with. Checking it correctly makes it valid, but after unchecking it it’s still valid.
Expected behavior
A required checkbox should always be invalid if it’s not checked.
Reproduction of the problem
http://plnkr.co/edit/GZI2fiZ65qtJQIjJbZLh?p=preview
What is the motivation / use case for changing the behavior?
HTML5 Form Validation doesn’t allow submitting a form if a required checkbox is unchecked. (Or at least that’s how Chrome and Firefox work.)
- Angular version: 2.0.0-rc.6
- Browser: [all]
- Language: [all]
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 5
- Comments: 15 (3 by maintainers)
Commits related to this issue
- fix(forms): introduce checkbox required validator Closes #11459 — committed to DzmitryShylovich/angular by deleted user 8 years ago
- fix(forms): introduce checkbox required validator Closes #11459 — committed to DzmitryShylovich/angular by deleted user 8 years ago
- fix(forms): introduce checkbox required validator Closes #11459 — committed to DzmitryShylovich/angular by deleted user 8 years ago
- fix(forms): introduce checkbox required validator Closes #11459 — committed to DzmitryShylovich/angular by deleted user 8 years ago
- fix(forms): introduce checkbox required validator Closes #11459 — committed to DzmitryShylovich/angular by deleted user 8 years ago
- fix(forms): introduce checkbox required validator Closes #11459 — committed to DzmitryShylovich/angular by deleted user 8 years ago
- fix(forms): introduce checkbox required validator Closes #11459 Closes #13364 — committed to angular/angular by deleted user 8 years ago
you can you Validators.requiredTrue instead of Validators.required
Still observing the same issue in Angular version :7. Even with requiredTrue Validator, the experience is still the same. I tried writing a custom validator but the value once changed, remains the same. In my case I keep getting “on” as the value. It is killing me. Am I doing something wrong ?
For thoes using the reactive forms method and needing a quick hacked fix,