0

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 .

2
  • 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 Koppa
    Sep 14, 2017 at 13:22
  • Possible duplicate of How to validate that at least one checkbox should be selected?
    – Pengyy
    Sep 14, 2017 at 13:23

1 Answer 1

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();
  }
}); 

Not the answer you're looking for? Browse other questions tagged or ask your own question.