I had formArray
checkbox on my checkboxForm
, I need to disabled button submit if no checkbox are checked
, I had implement custom validator
Make something like this:
export a function. something like this:
export function customValdiator(form: FormGroup) {
const formValue = form.value;
// with the formValue apply your own validation logic .
if (/* HAVE ERROR */) {
return { checkboxesRequired: true };
} else {
return null;
}
}
build your form:
this.checkboxForm = this.formBuilder.group({
receivedSummons: this.formBuilder.array([])
}, { validator: customValdiator });
and remove add validators from your addCheckboxes method.
dont matter if u add or remove rows to receivedSummons
FormArray when u change any data on the form angular will execute customValdiator
function and pass the form as argument and you have access to current receivedSummons values for valid which is checked.