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 .
-
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, on the Angular guide– Jack KoppaSep 14, 2017 at 13:22
-
Possible duplicate of How to validate that at least one checkbox should be selected?– PengyySep 14, 2017 at 13:23
Add a comment
|
1 Answer
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();
}
});