I have a color picker field component that I want to use in multiple collections, and I want to add a condition for when to show it on different collections. What is the best way to add more properties to config object?
Is your custom field component a function already? i.e. in your configs you are saying
// ...other fields
colorPicker(),
// ...more fields
If not, you will need to convert it into a function, that when called returns the config object.
Once you have that, you can modify that function to take some arguments. You will likely want to pass the field
name
that you will need to access the field off of
siblingData[${name}]
within the condition,
andthe value you want to conditionally show the field when equal to.
in the end it could look like:
// ...other fields
colorPicker('some-field', 'some-value'),
// ...more fields
You could also pass 1 object instead of 2 strings as the argument, if that is easier to read for you, like:
// ...other fields
colorPicker({ fieldName: 'some-field', fieldValue: 'some-value' }),
// ...more fields
thanks @Jarrod! that makes a lot of sense, this is exactly what I was looking for.
beautiful!
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.