I'm trying to write custom form validator.
I have two component main-form and options. In options component I have list of checkboxes, and would like to validate, that on each row is checked at least one option.
https://stackblitz.com/edit/stackblitz-starters-quy57f
On option component I have validation method, and in case some row is invalid I emit this to main-component. On main-component I have property, which react on this emittor. There is also form validator, which should react on this isInvalid property:
<form #inputForm="ngForm" appFormStatusValidator [isInvalid]="isInvalid">
But inside of the validator, the isInvalid property is false, even if property on the form is true (and vice versa).
Could you please tell me, what I'm doing wrong?
I expect, when I check option1 on each row, that status of the main-form would be 'VALID'. But in the console log i see:
options component: is INvalid: false main form - isInvalid: false validator: is invalid: true
Why is property isInvalid true inside validator even if I set isInvalid to false on the main-form component?
Thanks a lot for any advice.
We can simply just provide the IDs as input to the directive and the directive will use these values and loop through the form control values and apply the logic which will determine if the form is valid or not.
But please not, when you add or remove a value into the array that is used for the
*ngForthen you need to change the reference of the array by doingdirective
main form.com.ts
main form com.html
options.ts
options.html
stackblitz