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

Best way to implement Angular cross field validation

Discussão em 'Angular' iniciado por Heyjojo, Novembro 27, 2025.

  1. Heyjojo

    Heyjojo Guest

    I am trying to figure out the best way to implement cross field validation in Angular.

    For example, I have a select field that makes another field mandatory.

    I want to be able to:

    • Change the border color of the field if it is invalid
    • Display a * in front of the field whenever it becomes mandatory
    • Display a specific error message that explains what validation rule is broken.

    So far, I came up with three solutions but they don't feel so convincing to me.

    • Listen to select field changes and update second field's validators.
    • Listen to both fields changes and manually perform setErrors
    • Lift validation to formGroup (which can feel extremely cumbersome since, validation state is now stored in formGroup and not directly available in formControl).

    Here is a Stackblitz implementation that demos my investigations.

    Continue reading...

Compartilhe esta Página