Replies: 3 comments 5 replies
-
Your second input is never registered. Only registered input's values become part of |
Beta Was this translation helpful? Give feedback.
-
@mogelbrod @GaneshSinghPapola @wdfinch Method "setValue" with option "shouldValidate: true" only triggers validation for registered field name. Method "trigger" should be used in order to force validate the unregistered field. For example:
Working sample: https://codesandbox.io/s/react-hook-form-validation-of-unregistered-input-forked-cyvj6 |
Beta Was this translation helpful? Give feedback.
-
Something similar happened to me, and I had a hard time finding a solution. Maybe it will help someone else.
|
Beta Was this translation helpful? Give feedback.
-
First of all, thanks for a great open source library - and kudos for the seemingly super quick response times you have on discussions and issues!
On to the question:
I spent an hour today debugging an issue where some semi-controlled (using
setValue()
) form fields didn't seem to hide/show validations errors upon input, only on submit (usingmode: 'all'
, plusshouldUnregister: false
to avoid having to use hidden inputs). After a while I discovered that it was due to the broken fields not being registered, which made me curious about if getting validations to work without field registration is possible? The fact thatsetValue()
takes an optionalshouldValidate
flag made me think that it was already possible, but it appears not to be the case - without any hacking into the library internals?This codesandbox should showcase what I'm trying to accomplish.
shouldUnregister: false
ensures unregistered field values remainresolver
defines validations for unregistered field(s) as well as registered onessetValue('unregistered', value', { shouldValidate: true })
should trigger validation of the unregistered fieldWith these 3 steps taken I expected validations to be triggered when validity of the unregistered field changes, but alas that doesn't happen right now. I've skimmed around the source code but haven't found a specific reason as to why this shouldn't be possible.
Thanks in advance, and thanks again for this great project 👍
Beta Was this translation helpful? Give feedback.
All reactions