0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.