Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
AsyncValidator overwrites Validator

Are there any reasons why adding a validator overwrites the existing async validator?

I use Angular 12 and addValidator() on formGroup. The docs say: "without affecting other validators."

As soon as I add the validator, async validator did not fire any more.

public testValidator(): AsyncValidatorFn {
    return (control: AbstractControl): Observable<ValidationErrors | null> => {
      return of({wrongAuthority: 123});
    }
  }

public authorityValidator(control: AbstractControl) {
   return {wrongAuthority: 12333};
}

this.form = this._fb.group({...}, { asyncValidators: this.testValidator()});

this.form.addValidators(this.authorityValidator);
this.form.updateValueAndValidity();

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Investigation of Angular code provide some results:

(this as {errors: ValidationErrors | null}).errors = this._runValidator();
(this as {status: FormControlStatus}).status = this._calculateStatus();

 if (this.status === VALID || this.status === PENDING) {
    this._runAsyncValidator(opts.emitEvent);
 }

As you can see sync validator executes first and sets the status of control then if he throws an error async validator is ignored by the value of status. That makes sense.

Github

P.S. executing of validators with console.log

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!