React-hook-form: Nested useFieldArray - nested children values lost after moving items.

Created on 8 Feb 2020  ·  3Comments  ·  Source: react-hook-form/react-hook-form

Describe the bug

It seems like, after moving entries from the parent record, if immediately after you submit the form, the data provided to the submit callback is incomplete for the entries that have been moved (they do not contain info about the nested entities).

To Reproduce

https://codesandbox.io/s/react-hook-form-usefieldarray-n0xph?fontsize=14&hidenavigation=1&theme=dark

  • Create three nested entities, like
append 1 - nested 1
append 2 - nested 2
append 3 - nested 3
  • Press move button: append 2 - nested 2 and append 3 - nested 3 will change their positions
  • Click on submit

The output in the console will be:

0: {name: "append 1", nested: Array(1)}
1: {name: "append 3"}
2: {name: "append 2"}

Expected behavior

The output in the console should be:

0: {name: "append 1", nested: Array(1)}
1: {name: "append 3", nested: Array(1)}
2: {name: "append 2", nested: Array(1)}

Additional Context

An additional example of the issue with screenshots can be seen in https://github.com/react-hook-form/react-hook-form/issues/993#issuecomment-583681395

bug

Most helpful comment

oh, @jd-erreape it's never gonna work lol. I haven't published anything hahaha. I will publish a minor version with all the fixes and features tmr.

All 3 comments

Thank you so much! have tested the sandbox and it works with no issue.

Have tried to test it on my project also, but not sure why (maybe because I had already tried 4.8.3-next.0 tag before) I cannot get the latest changes, but have done the same mods than the commit locally and it also fixes my use case.

Looking forward for the next version release to fully try it :) Thanks for all the help and keep the hard work with this awesome library!

oh, @jd-erreape it's never gonna work lol. I haven't published anything hahaha. I will publish a minor version with all the fixes and features tmr.

Was this page helpful?
0 / 5 - 0 ratings