Changing one of the selectors to x, changes all the others to x.

default discord avatar
sasjumb
last month
2

See picture.



If i change eg colorClassName to a specific value, all my other selectors change to that value as well, I dont want this to happen.



Code:



import { Block } from "payload/types";



import { backgroundColor } from "../fields/backgroundColor";



export const PillBlock: Block = {


slug: "PillBlock",


labels: {


singular: "Pill",


plural: "Pills",


},


fields: [


{ name: "title", type: "text", required: true },


backgroundColor({ overrides: { label: "colorClassName ", required: true } }),


backgroundColor({ overrides: { label: "colorDarkClassName", required: true } }),


backgroundColor({ overrides: { label: "textColorClassName ", required: true } }),


backgroundColor({


overrides: {


label: "textColorDarkClassName",


required: true,


hooks: {


afterChange: [


args => {


args.value = "dark:text-" + args.value;


},


],


},


},


}),


],


};




import { Field, SelectField } from "payload/types";


import deepMerge from "../utilities/deepMerge";



interface Args {


overrides?: Partial<SelectField>;


}


const options = [


{ label: "Main Primary Dark", value: "main-primary-dark" },


....


];


export const backgroundColor = ({ overrides = {} }: Args): Field =>


deepMerge(


{


name: "backgroundColor",


type: "select",


options: options,


},


overrides


);

  • discord user avatar
    tylandavis
    Payload Team
    last month

    This is likely because all of your fields technically have the same name

    backgroundColor

    . Try passing an argument to your function that you can use to set a unique name for your field.

  • default discord avatar
    sasjumb
    last month

    @tylandavis Thank you, this works.

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.