#How to get field value for access control purposes?
11 messages · Page 1 of 1 (latest)
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
- Field-level Access Control - Available Controls - Create
- Field-level Access Control - Available Controls - Read
- Field-level Access Control - Available Controls - Update
- Field-level Access Control
- Field-level Access Control - Available Controls
Community-Help:
How get the field data for access control?
How to get field value for access control purposes?
did you try using update property in access?
access: {
update: ({data, doc, siblingData, req}) => {
// rest of code
}
}
Yes, data returns as an empty object, and siblingData is undefined.
doc returns all the data, so I can't filter to return true/false for a specific value.
And with req, I don't think there is any parameter that correlates to the specific field that is being updated, right?
I am not sure i understand your use case.
Do you mind posting example?
I have recently implemented various use case when field is hidden, disabled, read only, etc, using both admin and access properties.
Sure,
const predefinedSections = [
{
section: 'Hero',
slug: 'hero',
},
{
section: 'Featured Products',
slug: 'featured-products',
},
];
const HomePage: GlobalConfig = {
slug: 'homepage',
access: {
read: () => true,
},
fields: [
{
name: 'sections',
label: 'Sections',
type: 'array',
fields: [
{
name: 'section',
label: 'Section Title',
type: 'text',
},
{
name: 'slug',
label: 'Section Slug',
type: 'text',
required: true,
// I want to make this field read-only for the predefined sections. For example, if the user creates another section different from the predefined slugs, he'll be able to edit this field. However, the predefined ones are read-only and cannot be deleted (the user can only update the Section Title).
},
],
defaultValue: predefinedSections,
},
],
I would probably create custom Field component for that and compare value of sections field (useField) with predefinedSections