react-hook-form: Problems with Field Array when used with react-beautiful-dnd
Describe the bug I am facing an issue with Field Arrays when the used alongside with the react-beautiful-dnd. I am trying to achieve drag and drop with the Field Array. But there is an issue that while dragging and dropping the field key of a Controller component within the field array is removed.
To Reproduce Steps to reproduce the behavior:
- Go to ‘https://codesandbox.io/s/modern-shape-6v9d6?file=/src/App.js’
- Drag first point down to the second point
- Click on the debug button which calls getValues()
- You can see that the 0th element of the Field Array has lost the
Addresskey which is Controller Component
Codesandbox link (Required) https://codesandbox.io/s/modern-shape-6v9d6?file=/src/App.js
Expected behavior Field key of Controller component should not get removed after drag and drop completed. A clear and concise description of what you expected to happen.
Additional context
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (11 by maintainers)
Commits related to this issue
- fix #1500 controller with useFieldArray during swap — committed to react-hook-form/react-hook-form by bluebill1049 4 years ago
- fix #1500 controller with useFieldArray during swap — committed to react-hook-form/react-hook-form by bluebill1049 4 years ago
Thanks for the prompt replies @bluebill1049 I understand. I will look into it further
5.6.1-beta.1Exactly swap/move work fine for uncontrolled inputs. I don’t get it either. Can you have a looksie when you got time?
On further investigation, I found that this is isn’t a DnD issue at all. There is an issue with the
swapandmovemethods calling them to swap the fields and then calling getValues() later on button click seems to afffect the Controller components(their key is removed) and then key gets added back on any subsequent field change.Please checkout this sandbox: https://codesandbox.io/s/magical-meninsky-s0y70?file=/src/Panel.js I’ve removed all DnD related code to focus on just that. To demonstrate please enter values in the two fields and click on
swap. Then click ondebugto print the values, you can see that theAddresskey is lost on the 0th element