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
Read-only field for a group
Re: Read-only field for a group
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.
hope that helps.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: Read-only field for a group
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
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
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
Code: Select all
$userinfo= getMemberInfo();
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;
}
}
https://www.screencast.com/t/fSfYRfpwt
Code: Select all
$j(function(){
})
i tired it and it works with me
i hope it would help you
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: Read-only field for a group
Thank you Tammam and pböttcher for your help. I will test and will report back.