setValue not working for arrays with controller
See original GitHub issueDescribe the bug I wonder if this bug is related to https://github.com/react-hook-form/react-hook-form/issues/5232 as the issues I usually see are related to non-primitive values, namely arrays.
To Reproduce
- Use controller interface instead of register to track fields in your form
- Add a manually tracked field via
defaultValues
- Add a callback modifying the manual field and call it (in my example by pressing the “Remove” button)
- Press the “submit” button
Codesandbox link (Required) https://codesandbox.io/s/dark-voice-glnie?file=/src/App.tsx
Expected behavior The submitted values are
{
"array": ["a"],
"firstName": "alll"
}
Actual behavior The submitted values are
{
"array": ["a", "b"],
"firstName": "alll"
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (3 by maintainers)
Top Results From Across the Web
setValue doesn't work when field array name changed · Issue ...
It seems that if a field array item has its name changed and then setValue is used to try and update the name,...
Read more >React hook form method - setValue - doesn't work
I have some clearable select, and I want to reset the applets field in state to an empty array ...
Read more >useForm - setValue - React Hook Form
To update the entire Field Array, make sure the useFieldArray hook is being executed first. Important: use replace from useFieldArray instead, update entire ......
Read more >6 Different Ways to Set Values for Reactive Forms | by Atit Patel
In this article, I am covering all the methods which can be used to set values for single form control or form. 1....
Read more >Array.SetValue Method (System) - Microsoft Learn
If SetValue is used to assign null to an element of an array of value types, all fields of the element are initialized...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@damianobarbati Are you able to upgrade
react-select
to version4.0.0
or newer? Doing so fixes the issues you mention above. Can you verify if that would also resolve the other issues you’re seeing?@mrlubos I see it working properly with the latest
react-select
. I’ll ping if I manage to reproduce the real app behaviour, thank you!