Make field `readOnly` conditionally

default discord avatar
Nikich
last month
4

Is it possible to do so as we can hide/show field based on siblingData? I would like to make it possible to fill text field only once, this means you are not allowed to edit it once collection/global was saved.

  • default discord avatar
    Kyr
    last month

    If you set the "update" permissions on the field to

    false

    and leave create & read as

    true

    then it can be set at creation and read anytime but cannot be updated after creation.



    See:

    https://payloadcms.com/docs/access-control/fields
  • default discord avatar
    Nikich
    last month

    @Kyr A bit unintuitive but works like a charm, thanks!

  • default discord avatar
    Kyr
    last month

    It's more powerful this way as you might want to set it to allow certain roles to be able to update it (like CEO or admins) but not others.

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.