-
-
Save vanchelo/3217105cf29ad2005110acf6a8d5f6a0 to your computer and use it in GitHub Desktop.
Mark control and update validity function
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
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