-
Should it be possible to always update the value of one of the hidden inputs with the value of the current index of
The above does not seem to work (the value does not get updated) CSB: https://codesandbox.io/s/react-hook-form-usefieldarray-forked-j83yco?file=/src/index.js Please add a couple of items, change their first name and last name to be more distinguishable and then click the "Swap" button followed by "Submit". In the console you'll see that the submitted object has the "order" attributes messed up, even though in the UI it seems that they are always kept in correct order (1st column). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You're mixing the concept of controlled vs uncontrolled input by providing the Notice that the You want to manually update the field
|
Beta Was this translation helpful? Give feedback.
You're mixing the concept of controlled vs uncontrolled input by providing the
value
prop to a "registered" input element.Notice that the
change
event's not firing when the field array is re-rendered after theswap
operation, so the newindex
value is not updated in the RHF state.You want to manually update the field
setValue
on theindex
changeonChange
handler