How to make a field readOnly based on another field value?
Hello
@740476822193700875, my first guess is
https://payloadcms.com/docs/fields/overviewWhere there is validation information, and that provides siblingData as a prop
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
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 😦
We could help you figure out the field.access.update portion
Want to show us what you tried?
Definitely need this feature
You can acheive the same behavior using access controls if that is helpful!
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.
I'm going to start looking into this soon. Did you make any progress?
@307222801448960000@688437818019938326
nope, I changed my requirements accordingly.
If you set update and create to false it has the same effect as setting it to readOnly
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. Iffalse
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. Iffalse
is returned, any passed values will be discarded.
Iffalse
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
Discord
online
Get dedicated engineering support directly from the Payload team.