I'm new in angular how to used Custom validation for validate array of Multiple checkbox
and I want a button
should be disabled until a one checkbox
checked .
Asked
Active
Viewed 663 times
0

Ganesh Udmale
- 407
- 6
- 10
-
We'll need to see some of the code you've tried, but the issue of validating a field based on values other than that of the input itself often requires a factory function, where you return the actual validator function based on whether or not a condition exists. Like the first example [here](https://angular.io/guide/form-validation#custom-validators), on the Angular guide – Jack Koppa Sep 14 '17 at 13:22
-
Possible duplicate of [How to validate that at least one checkbox should be selected?](https://stackoverflow.com/questions/43384804/how-to-validate-that-at-least-one-checkbox-should-be-selected) – Pengyy Sep 14 '17 at 13:23
1 Answers
1
You have to subscribe to your checkbox control and react (enable/disable the button) to it when its value changes. Something like:
this.myForm.controls.isEnableCheckbox.valueChanges
.subscribe(checked => {
if(checked){ // here you enable or disable the button or you can set a variable to do that...
this.myForm.controls.buttonToEnable.enable();
} else {
this.myForm.controls.buttonToEnable.disable();
}
});

Bruno João
- 5,105
- 2
- 21
- 26