form icon indicating copy to clipboard operation
form copied to clipboard

swapValues error on nested fields

Open justisb opened this issue 5 years ago • 0 comments

Minimal example here: https://codesandbox.io/s/react-form-basic-form-hooks-only-6muwk?fontsize=14&hidenavigation=1&theme=dark

To reproduce:

  1. Add two nested "Nicknames"
  2. Try to move them up/down using the controls, which calls swapValues on their indexes
  3. Observe str.replace is not a function error

It looks like the fields get passed as an array like ['nicknames', '0'] and ['nicknames', '1'] in swapFieldValues: https://github.com/tannerlinsley/react-form/blob/master/src/hooks/useForm.js#L386

But getBy calls makePathArray which expects a string here: https://github.com/tannerlinsley/react-form/blob/master/src/utils.js#L35 https://github.com/tannerlinsley/react-form/blob/master/src/utils.js#L101

I'm not sure if the correct solution is passing in a string from swapFieldValues or to modify makePathArray to check if it's already an array.

justisb avatar Dec 27 '19 22:12 justisb