Does RHF only validate fields when they are dirty? #11223
Replies: 1 comment 1 reply
-
it is hard to say what is happening without code/sandbox provided. It depends on the sort of validation you have, how you set up the form etc. If you can provide sandbox, that can help! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a
useFieldArray
of objects, every input of the object has a validation rule defined.I also have an 'add item' button and I want it to be disabled if the array is not valid. I'm using
getFieldState
to check the validity of the array (yes, i'm correctly subscribing toerrors
in theformState
), but the validation won't be triggered until I touch one of the inputs in the array, so the button appears enabled even if the form is not valid.I tried combining the
invalid
andisDirty
properties fromgetFieldState
to disable the 'add item' button but this causes more problems (e.g if I pre-populate the form with values from a fetch request, it might be valid even if it is not dirty, so the button will be disabled while it shouldn't).I also tried calling
trigger
to validate the fields when mounting the component or whenappend
ing an item to the array but it still won't change the invalid prop from getFieldState. Any ideas on how to solve this? thanksBeta Was this translation helpful? Give feedback.
All reactions