...

/

Cross-reference Validation

Cross-reference Validation

Learn how to evaluate a form's validity based on multiple fields.

We’ve seen how basic Angular form validation works and how it’s possible to create custom validators when there’s the need to implement a logic that’s not covered by the built-in validators.

In some circumstances, the validation logic requires considering the value of multiple controls simultaneously. We’ve learned how to apply validators to a single control, but how do we implement a validation that considers various fields at once? Cross-reference validation, as the name suggests, allows gathering the controls’ values across the form and combining them in a single custom validator.

To consider multiple fields at once, we need to apply the custom validator to the parent control, which is the FormGroup. This is because we need to cover the whole form’s scope to access the target controls’ values. The FormGroup accepts a collection of child controls as the first parameter and a ...