According to this video
https://www.youtube.com/watch?v=Efn9OxSjA6Y, I managed to create a custom field and got required data using useFormFields as recommended by @Mitth but I m having an issue when I use hasMany prop. The value is not saved after hitting save .
I think you are missing a getter and setter for the new field. See here for docs on it.
Spesificly this line:
const { getPreference, setPreference } = usePreferences();
where the getter and setter are defined. i havent done an implamantaion with this but it should be fairly straight forward if you look at the example.
I will try this
You can see from the source code that the onChange is a bit differrent when you have multiple options, check this out:
https://github.com/payloadcms/payload/blob/master/src/admin/components/forms/field-types/Select/index.tsx#L64-L85oh yes
On change did solve my issue on setting the value but I m getting this type issue which is of course I have custom field type set to text which I cant change to array
Do you need it to be stored in the DB?
I feel like a
ui
field would be perfect for this
Yes its a cart thats why and admin can add into some add ons in users cart, product is generally free but add ons are not and add ons varies according to product thats why I have to keep it there
Well I understand that for addOns, but what is the need for selectedAddOns? Or am I misunderstanding?
User can only select add ons from a single product he cant add another product or add ons from another product
oic, you will likely want to use a
json
field type instead of text field type for your custom field
Thank you for your help. I m very new to this and still exploring. Changing type to json helped.
yeah no problem!
Could you link the code? Im having the same issue...
change type to json and in your custom select field instead of Select input just use Select from "payload/components/forms"
Can you link the whole component file?
@banks this is just like the date field in the other thread you have going
Star
Discord
online
Get dedicated engineering support directly from the Payload team..