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.

Make field readOnly in Admin based on another field vlaue

default discord avatar
fedoraman87422 years ago
11

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

  • default discord avatar
    notchr2 years ago

    Hello

    @740476822193700875

    , 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
    2 years 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
    iamlinkus2 years 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
    notchr2 years ago
    @688437818019938326

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



    Want to show us what you tried?

  • default discord avatar
    s4chinlast year

    Definitely need this feature

  • default discord avatar
    notchrlast year
    @307222801448960000

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

  • default discord avatar
    s4chinlast year

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

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

    @307222801448960000

    @688437818019938326
  • default discord avatar
    s4chinlast year
    @1090615594568667286

    nope, I changed my requirements accordingly.

  • default discord avatar
    lealaxlast year

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

  • default discord avatar
    brianjmlast year
    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.
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.