You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
useController doesn't pick up on the state change because it has exact internally set to true by default without the option to set it. That is why the component doesn't even re-render upon the setValue call => I have found a solution to this - I'm using useWatch with exact set to false.
error is not set. It is not just that useController doesn't cause the component to re-render (as I stated in my 1. point), the error isn't anywhere. I can even use useFormState({ exact: false }) and it still doesn't show.
I have been debugging the 2. issue for a long time and I may have found the reason in the setValues function.
As it recursively goes through the field name, to parse through the name and use the correct value type, it encounters [] as the value and it never calls setFieldValue, because [] is not a primitive value. If the value to set was a primitive, this process wouldn't have been stopped in its tracks and it would have updated the value and formState. It doesn't register the error. I believe it would behave the same if I passed an empty object (to a different field of course) - as it isn't primitive either.
I have not found a solution for this issue. The only workaround was to call trigger immediately after setting the value. That works but I would like to avoid that.
Expected behaviour
Empty array [] should be a valid value and it should correctly trigger validation when shouldValidate is set to true.
What browsers are you seeing the problem on?
Chrome
Relevant log output
No response
Code of Conduct
I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
I don't think we will support this usage as this would further complicate the setValue logic, what i would recommend to use setValue within a loop instead and update your specific field value.
Version Number
7.43.9
Codesandbox/Expo snack
https://codesandbox.io/s/dark-wave-y2zj85
Steps to reproduce
I have a nested field and a custom component hooked to RHF via
useController
. The custom component hasstring[]
as its value type.I need to set the value to
[]
. These are two ways that I tried.a)
b)
a) doesn't work well,
b) works as expected
There are two issues:
useController
doesn't pick up on the state change because it hasexact
internally set totrue
by default without the option to set it. That is why the component doesn't even re-render upon thesetValue
call => I have found a solution to this - I'm using useWatch withexact
set tofalse
.error
is not set. It is not just thatuseController
doesn't cause the component to re-render (as I stated in my 1. point), the error isn't anywhere. I can even useuseFormState({ exact: false })
and it still doesn't show.I have been debugging the 2. issue for a long time and I may have found the reason in the
setValues
function.As it recursively goes through the field name, to parse through the name and use the correct value type, it encounters
[]
as the value and it never callssetFieldValue
, because[]
is not a primitive value. If the value to set was a primitive, this process wouldn't have been stopped in its tracks and it would have updated the value andformState
. It doesn't register the error. I believe it would behave the same if I passed an empty object (to a different field of course) - as it isn't primitive either.I have not found a solution for this issue. The only workaround was to call
trigger
immediately after setting the value. That works but I would like to avoid that.Expected behaviour
Empty array
[]
should be a valid value and it should correctly trigger validation whenshouldValidate
is set totrue
.What browsers are you seeing the problem on?
Chrome
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: