Make field `readOnly` conditionally

default discord avatar
Nikichlast year
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
    Kyrlast year

    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
    Nikichlast year

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

  • default discord avatar
    Kyrlast year

    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.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

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