Skip to content

Instantly share code, notes, and snippets.

@farithadnan
Created October 12, 2021 05:55
Show Gist options
  • Save farithadnan/47b361b9faeb24208d6713b98c1b6c88 to your computer and use it in GitHub Desktop.
Save farithadnan/47b361b9faeb24208d6713b98c1b6c88 to your computer and use it in GitHub Desktop.
validate the form validity
// Check Validation status inside FormGroup/FromArray
const invalidControls: string[] = [];
const recursiveFunc = (form: FormGroup|FormArray) => {
Object.keys(form.controls).forEach(field => {
const control = form.get(field);
if (control.invalid) { invalidControls.push(field); }
if (control instanceof FormGroup) {
recursiveFunc(control);
} else if (control instanceof FormArray) {
recursiveFunc(control);
}
});
};
recursiveFunc(this.validateForm);
console.log(invalidControls);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment