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

217
Views
Angular form custom validator on two fields

I have question how to valid on two fields simultaneously in Angular FormGroup. I must create custom validation on value return backend I don't have any idea how to create it. Thanks for any idea.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to create AsyncValidator and bind it to the FormGroup, then you will have access to the group fields and can validate two fields in one validation tick. There is some example for you:

group = new FormGroup(
    {
      a: new FormControl(''),
      b: new FormControl(''),
    },
    { asyncValidators: customAsyncValidator() }
  );


function customAsyncValidator(): AsyncValidatorFn {
  return (group: FormGroup) => {
    const a = group.get('a').value;
    const b = group.get('b').value;
    return of('value').pipe(
      delay(500),
      map((value) => (value === a || value === b ? null : { fields: true }))
    );
  };
}

Hope this helps. Stackblitz

about 4 years ago · Juan Pablo Isaza 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!