react-hook-form validation triggers even if field has been unregistered

778 Views Asked by At

I have a dynamic form, that I can add/remove fields to it.
I use react-hook-form and also yup to handle form validation.
When a field is removed dynamically, I also unregister it using react-hook-form unregister(name) method.
It seems to be working fine, the values returned by getValues do not include those fields that have been unregistered.
The problem is that yup still tries to validate those fields that are required in the resolver-schema even if they are not registered, so the form will not be submited after submit button has been clicked.

I tried the solution here, but unfortunately that didn't work for me.

Would appreciate some help.

0

There are 0 best solutions below