Replies: 4 comments 1 reply
-
SB link: https://codesandbox.io/p/sandbox/cocky-fermat-wmrkfh |
Beta Was this translation helpful? Give feedback.
-
My alternative approach which I don't want to be doing is adding entries manually to the field array when my component mounts from the data received from the api call |
Beta Was this translation helpful? Give feedback.
-
Hoping for @bluebill1049 or someone to help. I have tried also to use useFieldArray and append the api values and it still doesn't set the values for the nested "employees" array |
Beta Was this translation helpful? Give feedback.
-
I think I'm experiencing a similar issue, did you ever find a solution to this? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi
I am trying to reset a form using default values and values that are loaded from an API call (the structure of both objects are the same).
However when I try to reset the form with
apiValues
structure I find that RHF fails to use the values in the nested structure (i.e. the employees structure from the API is not used at all) and instead when I dogetValues
on the field in question I see an empty array, i.e. thedefaultValues
are shown:And the object created from an API call:
In the component I do this once I have fetched the API data:
The
sports
array is however populated with the API data correctly in the form when I usereset
When I view the data that exists in
apiValues
in the debugger I can see that the employees emails are populated, however afterreset
is called, I am just presented with thedefaultValues
value which is an empty array.I have also tried to provide dummy values to
defaultValues
as such:What is puzzling is the object (that I merge) before passing it to the
reset
function has all the values I expect to see (i.e. from the API and any defaults). It seems to me RHF is stripping or ignoring the nested structure and just defaulting back to an empty array?!I am using RHF
7.45.4
Any help/tips would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions