Next.js Discord

Discord Forum

Shadcn Form-field modification

Unanswered
Magyar agár posted this in #help-forum
Open in Discord
Magyar agárOP
Hello , i am trying to modify a form which i use for my ecomerce, basically i have colors and sizies and i want to be able to select and register multiple not just one for every product. Can somone help or at leas see what am i doing wrong? or any other solution .

15 Replies

American black bear
You gotta explain your problem more specifically
use screenshots
Can't really understand what's your problem TBH
Magyar agárOP
this is my prisma schema
it does not work
Serbian Hound
What do these look like?
import { Category, Color, Image, Product, Size, Subcategory } from "@prisma/client"
What kind of errors do you get, and where?
Magyar agárOP
i am not getting any error it just dont adds the data , nothing happens practically
So what you're saying is you are using a multiselect component but when you submit you get nothing as output?
Magyar agárOP
Magyar agárOP
i get this , but i am not sure what i am suposed to do next
Serbian Hound
It looks like everything is working, what happens if you log the selected and sizeList and change the selected values?
Are they showing the correct selections?
If so, you just need to store the resulting arrays as json in your DB.
Magyar agárOP
yes they are showing the correct, but i cant register the array of data
Serbian Hound
Are you passing initialData every time? Because in your onSubmit you have
if (initialData) {
        await axios.patch(`/api/${params.storeId}/products/${params.productId}`, {...data, sizes: sizeList, colors: selected});
      } else {
        await axios.post(`/api/${params.storeId}/products`, data);
      }

But your formSchema doesn't include sizes or colors so if no initialData is passed then it will use the POST action without sending the sizes and colors

If you have initialData, then try logging the received data in your API route and see if you have sizes and colors.
If they are there, then the issue must be when you're trying to mutate your DB, likely because of schema/model and accepted data type for the columns being different.
Magyar agárOP
yes i made some modifications but this one is hard