Read-only field for a group

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
dannybridi
Veteran Member
Posts: 54
Joined: 2016-03-21 19:33

Read-only field for a group

Post by dannybridi » 2018-04-11 15:29

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

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Read-only field for a group

Post by pbottcher » 2018-04-17 21:14

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.
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.

R Tammam
Veteran Member
Posts: 113
Joined: 2017-08-26 15:35

Re: Read-only field for a group

Post by R Tammam » 2018-04-17 21:45

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

Code: Select all

$userinfo= getMemberInfo();
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

Code: Select all

$j(function(){ 
}) 

i tired it and it works with me

i hope it would help you

dannybridi
Veteran Member
Posts: 54
Joined: 2016-03-21 19:33

Re: Read-only field for a group

Post by dannybridi » 2018-04-19 17:09

Thank you Tammam and pböttcher for your help. I will test and will report back.

Post Reply