Page 1 of 1
Read-only field for a group
Posted: 2018-04-11 15:29
by dannybridi
Hello,
I have successfully used the following code in tablename-dv.js to make a field read only:
document.getElementById("fieldname").readOnly = true;
I’d like to make this functionally dependent on the group membership of a logged in user. Or, make the field read only for all users, except for for those who are members of the administrator group.
Any ideas?
Thanks
Re: Read-only field for a group
Posted: 2018-04-17 21:14
by pbottcher
Hi, you can use ajax to retrieve the group membership of the logged user and make the field readonly if it matches your requirement.
hope that helps.
Re: Read-only field for a group
Posted: 2018-04-17 21:45
by R Tammam
Hello dannybridi,
you cann do it easily by inserting simple code in hooks/footerextras.php
1- you should retrieve user info in the php part of the code
her's a screenshot of it's position
https://www.screencast.com/t/iWdjZZ3x
2- you should then check the user group in the js part , you will need to change allowed_groups whith any group you want to add readonly property to
Code: Select all
var user_group = <?php echo json_encode ( $userinfo['group'] ) ;?> ;
var allowed_groups = ['Admins','agents','accountatns'];
for( var i=0; i<allowed_groups.length;i++ ){
if(allowed_groups[i] == user_group){
document.getElementById("CustomerID").readOnly = true;
}
}
and here's a screen shoot of it's position , make sure to put the js code in
https://www.screencast.com/t/fSfYRfpwt
i tired it and it works with me
i hope it would help you
Re: Read-only field for a group
Posted: 2018-04-19 17:09
by dannybridi
Thank you Tammam and pböttcher for your help. I will test and will report back.