How To? ShadCn Form With 'useFieldArray' and Multiple ComboBox's and setValue Overwitting Previous ComboBox Values #2877
Unanswered
launchthatbrand
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to create a form with 2 comboboxes inside a fieldArray.
What is happening with the below code:
Everything works fine on the frontend. I can add multiple instances of the array fields and my select options are correct. On form submit I am simply console.log the values. What is not working is that when I fill out the first combobox, hit submit, the nested item category title/id fields are correct. When i fill out the first comboBox, then the second comboBox, hit submit, the item title/id is correct, but it has overwritten the nested category title/id to be blank.
I believe this has to do with my second comboBox setValue:
which has no data for `items.${index}.category, so it overwrites all other data in items.${index} to undefined/blank.
Things I have tried:
This half works, but now I cannot modify my second combobox value after initial selection. I do not think ...field.value is correct, maybe I should be passing {...field} into the combobox component as seen here in the Input component?
This actually works, but if I were to have 10 nested fields to set the code seems exhausting
What is the proper way to define the setValue function with multiple ComboBox's?
My Code:
I have an interface:
and then a fieldArray:
my first comboBox:
my second comboBox:
Beta Was this translation helpful? Give feedback.
All reactions