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
);
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.
@tylandavis Thank you, this works.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.