1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Conditional required validation in angular reactive form

Discussão em 'Angular' iniciado por vinit tyagi, Agosto 13, 2025.

  1. vinit tyagi

    vinit tyagi Guest

    I want to apply conditional validation on some properties based on some other form values. I have referred some answers Angular2: Conditional required validation, but those are not fulfil my need. Because I have to implement conditional validation in 40+ form(around 30 fields) of my large enterprise application. I don't want write the same code in every component and change the FormControl name. I don't know how this can be achieved via Directive.

    if age control valuev is greater than 18 than the license number field is required.

    Here's my code:

    this.userCustomForm = this.angularFormBuilder.group({
    age:['',Validators.required],
    licenseNo:[''] // Here I want to apply conditional required validation.
    });


    In my application there are some cases where I want set conditional validation based on nested FormGroup or FormArray values.

    Please guide me, how can I achieve this.

    Continue reading...

Compartilhe esta Página