-
-
Notifications
You must be signed in to change notification settings - Fork 526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Help] How to hide|read only a field for non admins when editing/creating an entry in a collection #677
Comments
I believe that requires a read-only or hidden attribute on the field definition so we can define the field like:
The hidden field can be added easily to the input:
but believe that should be performed in a more generic way and maybe including other field types than text. The readonly option seems a bit more simple as it can be handled as new attribute:
and the text template can be updated to:
think is a small change that provides the flexibility you described above |
This is probably a common case. BTW I would also like to know more about what can I do in collection settings so I could implement this or e.g. collection level id filter myself. |
hi, i have the same problem. how can i hide or make a field read-only ? i guess a primary-key is something very common and never should be editable by any user. thanks ! |
i took a while till i found out, that i have to make these changes in |
If you want to hide the slug field (and optional more fields) completely for non-admins, you can use this: <?php
/*
hide fields for non-admins
How to use:
* edit collection and open "Permissions" tab
* enable "read" permission and place the code below
*/
$hiddenFields = ["slug"];
if ($context->user && $context->user['group'] != 'admin')
foreach($hiddenFields as $field)
$context->options['fields'][$field] = false; or simpler: <?php
if ($context->user && $context->user['group'] != 'admin')
$context->options['fields']['slug'] = false; |
I had this issue when dealing with a nested set inside a repeater. Each set needs to have a unique ID, but I obviously don't want any users to be able to touch that. If you are using the API: And when dealing with items created in the GUI, you can use webhooks to append ID to the item before the collection is saved using the |
I do have a
slug
field, which I set automatically via$app->on("collections.save.before.{collectionName}"
and I would like that field to be either not visible or read-only when a non-admin user (I have created other groups viagroups:..
inconfig.yaml
is creating or editing an entry.I saw a comment earlier about custom PHP code in a collections Permissions, #676 which may be useful but I need some guidance on if and how it's possible to adjust an entry to accomplish that desired outcome.
Thanks!
The text was updated successfully, but these errors were encountered: