Page 1 of 1
How? Make one field read-only for usergroup
Posted: 2019-06-04 16:08
by onoehring
Hi,
I want to avoid that a regular user (not admin) can edit a certain field in a record (but the user must be allowed to edit other fields of the record).
How can I accomplish that?
Searching the forum for read only did not help me.
Olaf
Re: How? Make one field read-only for usergroup
Posted: 2019-06-04 17:32
by pbottcher
Hi,
you would need to provide a little bit more information about your setting. There are a lot of posts about making a field read-only and it depends on the field you have. Is it a look_up field, text field, .... ?
Do you need to make it read-only when the record is already created, or only when it is updated?
Re: How? Make one field read-only for usergroup
Posted: 2019-06-05 06:18
by onoehring
Hi pbötcher,
in the table are 3 fields at this time:
ID, Container, Place.
Of course, the admin (of super admin) should be able to edit the column container and place (ID is PK,autoincrement).
The regular user should not be able to edit the column Container, but only change the column Place of the entity Container.
I am not sure how to do this, as the regular user also needs the ability to edit the record (but only place).
Probably it would be useful, if the admin (super admin) can also add new records (meaning new Container and setting some Place). This I can do using the regular user-/group-setup permissions I think.
Olaf
Re: How? Make one field read-only for usergroup
Posted: 2019-06-05 06:55
by pbottcher
Hi,
in the hooks/TABLENAME.php file you have a function TABLENAME_footer.
in the case section "detailview" or "tableview+detailview" depending on what you use put
Code: Select all
case 'VIEW':
if ($memberInfo['group'] != 'Admins') {
$footer="<%%FOOTER%%><script>\$j('#Container').attr('readonly','true')</script>";
}
else $footer='';
break;
TABLENAME is your TABLE and VIEW is either detailview or tableview+detailview
Re: How? Make one field read-only for usergroup
Posted: 2019-06-05 07:13
by onoehring
Hi pbötcher,
thank you a lot. I will try that. ... No, it did not work. Same for super admin and user of a different group.
I added/replaced to function tbl_Contain_footer
Code: Select all
case 'detailview':
//$footer='';
if ($memberInfo['group'] != 'Admins') {
$footer="<%%FOOTER%%><script>\$j('#Container').attr('readonly','true')</script>";
}
else $footer='';
break;
case 'tableview+detailview':
//$footer='';
if ($memberInfo['group'] != 'Admins') {
$footer="<%%FOOTER%%><script>\$j('#Container').attr('readonly','true')</script>";
}
else $footer='';
break;
Olaf
Re: How? Make one field read-only for usergroup
Posted: 2019-06-05 07:29
by pbottcher
Hi, can you run the $j('#Container').attr('readonly','true') in the debug mode to see if it works.
Re: How? Make one field read-only for usergroup
Posted: 2019-06-05 07:39
by onoehring
Hi,
yes, that works fine.
(I did change the ID to ContainerCode to match the fields)
$j('#ContainerCode').attr('readonly','true')
Of course, I changed that in your original suggestion as well.
Olaf
Re: How? Make one field read-only for usergroup
Posted: 2019-06-05 07:53
by pbottcher
ok, so is it working now? in the code you posted you had #Container
Re: How? Make one field read-only for usergroup
Posted: 2019-06-05 08:03
by onoehring
Hi,
no, it's not working with this code (but when I enter your line in the console the field get's deactivated). I am posting the full function to make sure, I am in the correct place in the file.
Code: Select all
function tbl_Container_footer($contentType, $memberInfo, &$args){
$footer='';
switch($contentType){
case 'tableview':
//$footer='';
if ($memberInfo['group'] != 'Admins') {
$footer="<%%FOOTER%%><script>\$j('#ContainerCode').attr('readonly','true')</script>";
}
else $footer='';
break;
case 'detailview':
//$footer='';
if ($memberInfo['group'] != 'Admins') {
$footer="<%%FOOTER%%><script>\$j('#ContainerCode').attr('readonly','true')</script>";
}
else $footer='';
break;
case 'tableview+detailview':
//$footer='';
if ($memberInfo['group'] != 'Admins') {
$footer="<%%FOOTER%%><script>\$j('#ContainerCode').attr('readonly','true')</script>";
}
else $footer='';
break;
case 'print-tableview':
$footer='';
break;
case 'print-detailview':
$footer='';
break;
case 'filters':
$footer='';
break;
}
return $footer;
}
Olaf
Re: How? Make one field read-only for usergroup
Posted: 2019-06-05 08:04
by onoehring
Hi
oh, I tested on Vivaldi (chromium) and Edge. Same result.
Olaf
Re: How? Make one field read-only for usergroup
Posted: 2019-06-05 08:31
by onoehring
Hi,
I added
Code: Select all
$footer='<!--TEST: '.$memberInfo['group'].' -->"
Diese Ausgabe erscheint aber nicht im generierten HTML Code der Seite.
Kann es sein, dass der (Hook) Code gar nicht ausgeführt wird? Wie kann ich das prüfen?
Olaf
Re: How? Make one field read-only for usergroup
Posted: 2019-06-05 08:46
by onoehring
Hi,
problem SOLVED.
a) the suggestion from pbötcher (
viewtopic.php?f=2&t=3036&p=10110#p10093 ) works fine. Thank you.
b) In the hooks folder there was a file tbl_container ... I renamed the table and I simply added his suggestion to the wrong hooks-file. My fault.
Olaf
Re: How? Make one field read-only for usergroup
Posted: 2021-11-06 21:07
by aarlauskas
Hi, how do you add additional fields to be read only in detail view? Also this seems to be only working for Text type of field. Anyway to deactivate lookup fields? Thanks
Re: How? Make one field read-only for usergroup
Posted: 2021-11-08 16:58
by pfrumkin
Hi,
I am not clear on what you are asking.
Are the additional fields added to the table?
I would look at the tablename_dv hook. There, you can add criteria if the field is readonly for some and not others. If the field is readonly for all users, then another option is to put it in tablename-dv.js file. In either case, this approach requires JQuery coding. The JQuery code is something link
$j('#fieldname').attr('readonly',true);
Hope that helps. Good luck.
~Paul
Re: How? Make one field read-only for usergroup
Posted: 2021-11-08 21:51
by pbottcher
Hi Arni,
for a lookup you need either to wait for the element to be created, which happens after the page is loaded.
An alternativ solution could be that you create a special template file for this case and use the _init hook to point in the needed case to that template.
Re: How? Make one field read-only for usergroup
Posted: 2021-11-09 19:52
by aarlauskas
Hi and thanks for the tips. The original Pascal's solution is good enough for what I need right now, all I want to know is how to lock two or three fields in detail view. The below code locks field 'Container'. If I want to lock 2x fields, 'Container' and 'Ship' for example, how to add 'ship' to this code? Tried some combinations but no luck
Code: Select all
$footer="<%%FOOTER%%><script>\$j('#Container').attr('readonly','true')</script>";
Re: How? Make one field read-only for usergroup
Posted: 2021-11-10 21:20
by pbottcher
Hi Arni,
just add the additional field with a comma sepatation.
e.g. $j('#Container, #FIELD2, #FIELD3').attr('readonly','true')
Re: How? Make one field read-only for usergroup
Posted: 2021-11-11 15:59
by aarlauskas
Brilliant! Thanks Pascal

Re: How? Make one field read-only for usergroup
Posted: 2024-07-12 08:42
by miwalder
Hi,
If data security is not important, you can hide or define fields read only with just CSS. You can add a usergroup where these rules should apply. Consider, that the hidden information is still accessible in the html source code. So it's not a column based security feature but a useful usability hack. See this howto to implement it in Appgini:
https://forums.appgini.com/phpbb/viewto ... f=7&t=5416