Answer the question
In order to leave comments, you need to log in
How to change validation order in Angular5?
Hello.
For example: there is a reactive form in which the email input field, on which several validators have been hung. More or less like this:
Email: new FormControl('', [Validators.required, Validators.email])
Answer the question
In order to leave comments, you need to log in
You can write your own validator function, like this:
function validateInSequence(
...validators: ( (formControl: FormControl) => any )[]
): (formControl: FormControl) => any {
return function (formControl: FormControl): any {
for (let i = 0; i < validators.length; i++) {
const validationResult = validators[i](formControl);
if (validationResult !== null) {
return validationResult;
}
}
return null;
};
}
new FormControl('', [validateInSequence(Validators.required, Validators.email)]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question