Trying to make a custom component, and getting this behaviour.
Does payload defaultValue not work well with custom components?
I am on beta.80
Is this the expected behavior, or am I missing something?
fields: [
{
name: 'color-picker',
type: 'array',
label: 'Color Picker',
defaultValue: () => [
{ variableName: 'name1', color: 'color1' },
{ variableName: 'name2', color: 'color2' },
],
fields: [
{
name: 'variableName',
type: 'text',
},
{
name: 'color',
type: 'text',
},
],
admin: {
components: {
Field: 'src/ui/color-picker',
},
},
},
], const { value, setValue, rows } = useField({ path: 'color-picker', hasRows: true })
console.log({ value, rows })
//{
// "value": 2,
// "rows": [
// {
// "id": "66c04810bc9f85984eccbf0c"
// },
// {
// "id": "66c04810bc9f85984eccbf0d"
// }
// ],
// }I believe what happens is that you set an array with objects as the value, that Payload by default won't expend these objects, unless you provide a [depth](
https://payloadcms.com/docs/getting-started/concepts#depth) parameter
I have no experience with creating custom components or using Payload3, but your situation sounds like a depth issue, perhaps you could try to add an [access control](
https://payloadcms.com/docs/access-control/fields) hook on your field to expand the rows property via the [localAPI](
https://payloadcms.com/docs/local-api/overview)
Thanks for the suggestion, but there is no relationship fields for there to be depth. Seems to be that
const {getData} = useForm()can be used to grab the default.
Star
Discord
online
Get dedicated engineering support directly from the Payload team.