I need to figure out how will i be able to add the second validator in my reactive forms. I've added the "AvailabilityBalanceValidator" to the patchValues() which initialize the rows. However only the first validator is working, how come the second validator which is the AvailabilityBalanceValidator() is not working. Please check this link CHECK THIS LINK
patchValues() {
const materialForms = this.orders
.reduce((acc, i) => [...acc, ...i.materials], [])
.map(x => {
return (this.fb.group({
checkbox_value: [null],
material_id: [{ value: x.id, disabled: true }],
material_name: x.name,
available_qty: 10,
quantity: [null]
}, [this.subFormValidator.bind(this), { validator: this.AvailabilityBalanceValidator('available_qty', 'quantity') }]));
});
this.myForm.setControl('rows', this.fb.array(materialForms));
this.myForm.setValidators([this.formValidator.bind(this)])
}
AvailabilityBalanceValidator(campo1: string, campo2: string) {
return (group: FormGroup): { [key: string]: any } => {
const balance = group.controls[campo1];
const quantity = group.controls[campo2];
if (balance.value < quantity.value) {
return {
out: true
};
}
};
}