I’ve had a search through the forum/GitHub issues and it seems a few people have encountered the same issue, but on previous versions of Ionic or their solutions do not appear to work for me.
I am using ionic 2.1.0 - this appears to also affect all versions of ionic2.
Filling in all inputs, but leaving ‘grantPermission’ checkbox UNCHECKED causes the submit button to become active, as if the form has passed validation.
What I expect:
The form to only become valid once the ‘required’ checkbox is checked.
Any help on this one would be appreciated, thank you!
Build a FormGroup instead of using ngModel. Connect the ion-checkbox to a boolean formControl validated when true. Set the (ionChange) event of the ion-checkbox to call ChangeDetectorRef.detectChanges(), so the formControl updates when the ion-checkbox changes.
There might be a way to make it work with ngModel also, but I’ve found I have much clearer control over FormGroups, especially when ionic-specific inputs are part of the form.
I agree with @AaronSterling’s suggestion of using a FormGroup, but there should be no need for futzing with ChangeDetectorRefs. The following works as expected for me: