Something went wrong with multiple checkboxes #10798
-
Please explain me what I did wrong, if you can. Code example. https://codesandbox.io/p/sandbox/react-hook-form-3pygzt Output data is expected and work perfectly But if I added defaultValues or use reset() . output values is inconsitence |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Please describe more detail on what is wrong after adding default values or reset method. |
Beta Was this translation helpful? Give feedback.
-
You're using a "flat array" which is not supported by RHF. You need to provide a field name for the array instead. useForm({
- defaultValues: defaultSubscribes
+ defaultValues: {
+ subscribers: defaultSubscribes
+ }
})
<CheckboxNg
- name={`${index}.email`}
+ name={`subscribers.${index}.email`}
control={control}
/> Here's a working codesandbox. |
Beta Was this translation helpful? Give feedback.
You're using a "flat array" which is not supported by RHF.
You need to provide a field name for the array instead.
Here's a working codesandbox.