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.

Hide field if is not set

default discord avatar
feyd.harkonnenlast year

Hello! I'm trying to do a soft delete for a collection. What I want to achieve is to show

deletedAt

on

read

(only for Admin dashboard) only when is not undefined. The issue is that I can't achieve this. I tried using

field.access

:



{
    name: 'deletedAt',
    type: 'date',
    label: {
        en: 'Deleted at',
        ro: 'Șters la',
    },
    access: {
        create: () => false,
        read: ({ data }) => {
            return data ? data.deletedAt !== undefined : false;
        },
        update: () => true,
    },
},


But from what I see, first the Admin is calling the

/access

to see if has access, but in this step the

data

is undefined. After

/access

a new request is made to the request itself and I have access to

data

. The problem is that in the

Admin

only the

/access

matter when it comes to showing the field or not.



What I can do to achieve this?



Adding

admin.condition

solved the issue.

    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.