Comments (5)
Hey @richardvanbergen ,
This is actually intended behavior that we settled on while designing the readOnly
feature.
We thought that in order for a field to be "read", its value must be set in the first place. While a value could be set with hooks or through APIs, given that this command only affects the admin panel, we determined that readOnly
should only affect update
operations.
To disable your field within the create
operation, you can set an access control function on it like below:
{
label: 'S3 URL',
name: 's3Url',
type: 'text',
admin: {
readOnly: true,
},
access: {
create: () => false,
},
hooks: {
beforeChange: [
(): undefined => undefined,
],
afterRead: [
({ data }): string => {
return getUrl(String(data.filename))
}
]
}
}
I am open to revisiting the readOnly
function though. We use it on things like Transactions or Orders, where an admin may need to manually place an order for a customer upfront, and have the ability to create all fields, but then not be able to go back and re-edit.
However, our above use-case could be solved the same way through access control functions. Thoughts?
from payload.
Update:
Changing readOnly
to affect both create
and update
will only require one line to be removed:
Nice and easy. I'm up for it...
from payload.
@richardvanbergen In addition to the above fix, you'll likely want to use a condition to hide the field if it is not populated like this:
admin: {
readOnly: true,
condition: (data) => data?.s3Url,
}
from payload.
I agree, readOnly
should be applied consistently.
In a future update we could allow a function call that returns boolean
to give devs more control. That complicates the admin UI a little so we can wait on that for now.
from payload.
Thanks guys that all makes a lot of sense. I didn't really have a use case for it because we're all about the content editing and less so about transactions.
Sorry about the late reply I kind of forgot I filed this bug report 😆
from payload.
Related Issues (20)
- plugin-cloud-storage: Create new file (and upload) from URL. HOT 1
- plugin-cloud-storage: Internal API not responding the url HOT 2
- plugin-cloud-storage: Documents created through admin panel don't utilize configuration prefix HOT 1
- plugin-cloud-storage: 403 forbidden when uploading a file HOT 6
- plugin-cloud-storage: Avoiding Vercels upload limit by using PresignedUrls HOT 1
- plugin-cloud-storage: TypeError: options.adapter is not a function with Vite Bundler HOT 4
- plugin-cloud-storage: Ensure vite bundler compatibility HOT 6
- plugin-cloud-storage: S3 KMS encryption not supported HOT 2
- plugin-cloud-storage: disablePayloadAccessControl not working for Preview Sizes HOT 1
- plugin-cloud-storage: Images not found on payload URL HOT 2
- plugin-cloud-storage: npm commands missing from readme HOT 1
- plugin-cloud-storage: Document where to find Access key, key id, etc. in AWS HOT 4
- plugin-cloud-storage: Unable to load thumbnails || blocked by csp issue HOT 2
- plugin-cloud-storage: S3 adapter not working with create-payload-app template HOT 3
- Lexical editor does not allow adding new elements when blocks are the only elements HOT 3
- Live Preview breaks when preview frame context changes HOT 2
- draftMode() expects to have requestAsyncStorage, none available. HOT 2
- Local API: updating nested fields throws validation error HOT 3
- The mongodb adapter's migrate:down downgrades all migrations instead of ones in the latest batch HOT 1
- Payload Cloud: No DNS Record generated for Custom Domain HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from payload.