I created a special validator that applies to the full group of forms and then adds an error to the form control:
The following CameraSizeMin settings are invalid.
class CustomValidator {
static validate(abstractForm: FormGroup): {[key: string]: any} => {
let cameraSizeMin = abstractForm.get("cameraSizeMin");
let cameraSizeMax = abstractForm.get("cameraSizeMax");
if (true) {
cameraSizeMin.setErrors({"customValidation": true});
}
}
}
You will register it in the form group:
this.specFilterForm = this.fb.group({
cameraSize: this.fb.group(
{
cameraSizeMin: this.cameraSizeMin,
cameraSizeMax: this.cameraSizeMax,
}, {validator: CustomValidator.validate}
)
});
source
share