Created
October 12, 2021 05:55
-
-
Save farithadnan/47b361b9faeb24208d6713b98c1b6c88 to your computer and use it in GitHub Desktop.
validate the form validity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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