Created
June 11, 2020 10:54
-
-
Save MarsiBarsi/e204280a9f26781f6e1a310d375e8255 to your computer and use it in GitHub Desktop.
Mark control and update validity function
This file contains 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