Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vanchelo/3217105cf29ad2005110acf6a8d5f6a0 to your computer and use it in GitHub Desktop.
Save vanchelo/3217105cf29ad2005110acf6a8d5f6a0 to your computer and use it in GitHub Desktop.
Mark control and update validity function
import {AbstractControl, FormArray, FormGroup} from '@angular/forms';
export function markControlAsTouchedAndValidate(control: AbstractControl) {
if (control instanceof FormArray) {
control.controls.forEach(nestedControl => {
markControlAsTouchedAndValidate(nestedControl);
});
return;
}
if (control instanceof FormGroup) {
Object.values(control.controls).forEach(nestedControl => {
markControlAsTouchedAndValidate(nestedControl);
});
return;
}
control.markAsTouched();
control.updateValueAndValidity();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment