Issue
I have created a validator this way:
static repeatedPerson(): ValidatorFn {
return (array: FormArray) => {
if (array && array.length > 0) {
// I do some logic here
if (//AnyCondition) {
return {RepeatedPerson: true};
}
}
return {};
};
}
Then I add my validator to a formArray:
this.persons.setValidators(repeatedPersonNumber());
I tried other ways such as persons:
new FormArray([], repeatedPersonNumber())
new FormArray([], repeatedPersonNumber)
this.persons.setValidators(repeatedPersonNumber);
I put the breakpoint into the repeatedPerson validator and only call it once to return the function. But the validation itself never get triggered...
Any idea?
Solution
For the statement - this.persons.setValidators(repeatedPersonNumber)
, you need to call updateValueAndValidity()
for the new validation to take effect.
Check if this works. If that doesn't, you need to provide the HTML code and your Submit function code snippet to understand where the problem exactly lies.
Answered By - The Cloud Guy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.