Skip to content

Instantly share code, notes, and snippets.

@MarsiBarsi
Created June 11, 2020 10:54
Show Gist options
  • Save MarsiBarsi/e204280a9f26781f6e1a310d375e8255 to your computer and use it in GitHub Desktop.
Save MarsiBarsi/e204280a9f26781f6e1a310d375e8255 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