Make field readOnly in Admin based on another field vlaue

default discord avatar
fedoraman
10 months ago
11

How to make a field readOnly based on another field value?

  • default discord avatar
    notchr
    10 months ago

    Hello @fedoraman, my first guess is

    https://payloadcms.com/docs/fields/overview


    Where there is validation information, and that provides siblingData as a prop

  • discord user avatar
    jarrod_not_jared
    Payload Team
    10 months ago

    Currently readOnly is a boolean, so it cannot be conditional. This will likely be added as a feature in the near future.



    You could use access control on the field, and have the field.access.update return false based on other fields in the doc

  • default discord avatar
    iamlinkus
    8 months ago

    Hi, there's been quite some time, has there been something done with conditional readOnly fields?



    I have a couple of fields that I want to be visible with content within them, but enable editing only if a checkbox is set and couldn't figure out how to do that with the access control stuff 😦

  • default discord avatar
    notchr
    8 months ago

    @iamlinkus We could help you figure out the field.access.update portion



    Want to show us what you tried?

  • default discord avatar
    s4chin
    6 months ago

    Definitely need this feature

  • default discord avatar
    notchr
    6 months ago

    @Sachin You can acheive the same behavior using access controls if that is helpful!

  • default discord avatar
    s4chin
    6 months ago

    using access control I can only make it disappear, update or create but what I need is a specific field to be read only when certain value is match. I don't know may be there is a way but I m completely new in this so still figuring out.

  • default discord avatar
    brianjm
    last month

    I'm going to start looking into this soon. Did you make any progress? @Sachin @iamlinkus

  • default discord avatar
    s4chin
    last month

    @BrianJM nope, I changed my requirements accordingly.

  • default discord avatar
    lealax
    last month

    If you set update and create to false it has the same effect as setting it to readOnly

  • default discord avatar
    brianjm
    last month
    access

    does not effect the

    readOnly

    status/behavior in the UI. See the screenshots.



    This is consistent with the [documentation](

    https://payloadcms.com/docs/access-control/fields

    ).



    [Create](https://payloadcms.com/docs/access-control/fields#create)
    Returns a boolean which allows or denies the ability to set a field's value when creating a new document. If false is returned, any passed values will be discarded.

    [Update](https://payloadcms.com/docs/access-control/fields#update)
    Returns a boolean which allows or denies the ability to update a field's value. If false is returned, any passed values will be discarded.

    If false is returned and you attempt to update the field's value, the operation will not throw an error however the field will be omitted from the update operation and the value will remain unchanged.
    image.png
    image.png
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.