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.

Difference between Data & Sibling Data

default discord avatar
fakecash12 months ago
2

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

  • default discord avatar
    Payload-Botlast year


  • default discord avatar
    ritsu0455last year

    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 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.