I am trying to add validation to my Angular app's form.
The first section of my form contains:
The button is to be disabled until the user checks the checkbox & chooses an option from both radio button group's.
Here is the code for my button:
<button
[disabled]="
theChkAcceptTerms.invalid ||
theInsuredType.invalid ||
theReportInjury.invalid
">
And here is the code for my checkbox:
<checkbox
id="accept"
heading="I accept"
name="accept"
value="accept"
[(ngModel)]="chkAcceptTerms"
required
#theChkAcceptTerms="ngModel">
</checkbox>
Currently, when the page loads the button is disabled. It is only enabled once I check the checkbox, & choose an option in both radio groups.
However, if I un-check the checkbox, the button is not disabled.
Can someone please tell me how I can disable the above button if the checkbox is not checked. Thanks a lot!
You need to get the two way data binding for your controls and check them in the disabled attribute as
[disabled]="!checkBox || !radioGroup1 || !radioGroup2"
Check out the sample I created HERE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With