Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

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

default discord avatar
sasjumblast year
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
    last year

    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
    sasjumblast year
    @783701636165402624

    Thank you, this works.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.