Hey everyone, playing around with the Condition field, was wondering if anyone could clarify the difference between Data & Sibling Data,
Just doing some testing and it seems they're both giving me the same output for this code
{
name: "publishedAt",
type: "date",
required: true,
admin: {
position: "sidebar",
condition: (data,siblingData, { user }) => {
if (data.title === "test") {
console.log(data)
return true;
} else {
console.log("data",data)
console.log("sibling Data",siblingData)
return false;
}
},
},
},
this is the output
data {
id: 2,
publishedAt: null,
title: 'tes',
subject: null,
status: 'draft',
updatedAt: '2024-08-20T18:31:18.412Z',
createdAt: '2024-08-20T18:28:13.451Z',
layout: []
}
sibling Data {
id: 2,
publishedAt: null,
title: 'tes',
subject: null,
status: 'draft',
updatedAt: '2024-08-20T18:31:18.412Z',
createdAt: '2024-08-20T18:28:13.451Z',
layout: []
}
Thanks ahead of time
Oh perfect I see, so if I use any of those ill get access to the rest of the data. Thanks so much
the sibling data and data here are the same because you're on the top level of your data structure, try to have a field inside of a
group
/
array
/
blocks
/
tab
with
name
and you'll see
const fields: Field[] = [
{
name: 'topLevelText',
type: 'text',
},
{
type: 'array',
fields: [
{
name: 'text',
type: 'text',
condition: (data, siblingData, { user }) => {
// siblingData doesn't know about topLevelText here siblingData.topLevelText - error
// while data does!
// but instead, siblingData knows about the additionalText field - siblingData.additionalText
// as well current item's id - siblingData.id
return false
},
},
{
name: 'additionalText',
type: 'text',
},
],
},
]
Star
Discord
online
Get dedicated engineering support directly from the Payload team.