Hide field depending user group

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Hide field depending user group

Post by cesteban » 2019-05-15 19:02

Hi,

I'm trying to hide a checked field if the user isn't in the "adminstrador" group

I tried with this code but the detail view shows me blank

function Pagos_dv($selectedID, $memberInfo, &$html, &$args){
/* current user is not an administrador group?
if($mi['group'] != 'administrador'){
$html .= <<<eoc <script="">
\$j(function() { $j('#checado').hide();
})
</script>
EOC;
}
}
</eoc>


Regards

Esteban Ceniceros
Mexico City

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Hide field depending user group

Post by jsetzer » 2019-05-15 19:33

Do eoc and EOC match in your code? In your forum post they don't.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Hide field depending user group

Post by cesteban » 2019-05-15 21:47

Thanks

I copied exacttly the sample code from the suport page from AppGini

Regards

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

Re: Hide field depending user group

Post by pbottcher » 2019-05-16 07:12

Hi,
try this:

Code: Select all

function Pagos_dv($selectedID, $memberInfo, &$html, &$args){
	/* current user is not an administrador group? 
	if($memberInfo['group'] != 'administrador'){
		$html.=<<<EOC
		<script>
		\$j(function() { \$j('#checado').hide(); })
		</script>
EOC;
	}
}
In the funtction you need to access the $memberInfo, not the $mi, also the EOC marks is case sensitiv, so the must be eqal and no space or any other information after the starting on and the ending one must be at the beginning of the line.

Make sure that you check against the correct group. In your case "administrador".
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.

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Hide field depending user group

Post by cesteban » 2019-05-16 18:16

Thanks pböttcher

Now the page is displaying but the function $j('#checado').hide(); is not working

Regardless of whether the user belongs to the 'administrador' group or not, the checkbox always appears

Regards

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Hide field depending user group

Post by cesteban » 2019-05-16 18:33

I tried this from the console and always get the value "1", checked or not

j('#checado').val();

This is the code for the checkbox

<input type="checkbox" name="checado" id="checado" value="1">

Regards

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Hide field depending user group

Post by cesteban » 2019-05-16 19:04

If I run from the console this comand

$j('label[for="checado"]').hide();

The checkbox and the label these disappear

and with this command

$j('label[for="checado"]').sown();

both appear

But if I include the code at the Pagos.php this dont works

Regards

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

Re: Hide field depending user group

Post by pbottcher » 2019-05-16 19:49

Hi,

can you post what you have in your hook file
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.

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Hide field depending user group

Post by cesteban » 2019-05-16 23:23

Thanks,

This is the code

function Pagos_dv($selectedID, $memberInfo, &$html, &$args){

/* current user is not an administrador group?

if($memberInfo['group'] != 'administrador'){
$html.=<<<EOC
<script>
\$j(function() { \$j('label[for="checado"]').hide(); })
</script>
EOC;
}
}

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

Re: Hide field depending user group

Post by pbottcher » 2019-05-17 11:02

Hi,

I tried it on my testsystem and it works.

Can you please post the code exaclty as you have it in your hook file (with all spaces, tabs, etc.).

And did you check of a user that is not in the administrador group (sorry to ask so stupid...).

Also you could test for the user that is in the administrador group by setting

if($memberInfo['group'] == 'administrador')
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.

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Hide field depending user group

Post by cesteban » 2019-05-20 15:12

Thanks,

I copied the code exactly from the file

I checked about the user group but in both cases with a user from the administrator group ornot the field it is not hiding

Today I will make another tests and but really I can understand what's happen

Thanks for your support and help

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Hide field depending user group

Post by cesteban » 2019-05-20 15:31

Now I ran again the funcion

$j('label[for="Checado"]').hide();

An I got this message


n.fn.init [label, prevObject: n.fn.init(1), context: document, selector: "label[for="Checado"]"]
0: label
context: document
length: 1
prevObject: n.fn.init [document, context: document]
selector: "label[for="Checado"]"
__proto__: Object(0)

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Hide field depending user group

Post by cesteban » 2019-05-20 15:34

Sorry

it isn't a error is working the function from de console, but not from the php file

User avatar
landinialejandro
AppGini Super Hero
AppGini Super Hero
Posts: 126
Joined: 2016-03-06 00:59
Location: Argentina
Contact:

Re: Hide field depending user group

Post by landinialejandro » 2019-05-20 15:39

hi, try in the browser console to write your code:

Code: Select all

$j('label[for="Checado"]').hide();
and see in your page if it is hide, if dont work you have a problem in the selector.
Alejandro.
AppGini 5.98 - Linux OpenSuse Tumblewweed.

Some of my posts that may interest you:
:arrow: Landini Admin Template: Template for Appgini like AdminLTE
:arrow: Profile image plugin: add and changue image user profile
:arrow: Field editor in table view: Configurable fast edit fields in TV
:idea: my personal page

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Hide field depending user group

Post by cesteban » 2019-05-20 16:30

I thing the If isn't working!!!

User avatar
landinialejandro
AppGini Super Hero
AppGini Super Hero
Posts: 126
Joined: 2016-03-06 00:59
Location: Argentina
Contact:

Re: Hide field depending user group

Post by landinialejandro » 2019-05-20 18:35

i need to see the code in html from the browser, you can post the screenshot please?
make right click over the checkbox and the click in inpsecto option.
Alejandro.
AppGini 5.98 - Linux OpenSuse Tumblewweed.

Some of my posts that may interest you:
:arrow: Landini Admin Template: Template for Appgini like AdminLTE
:arrow: Profile image plugin: add and changue image user profile
:arrow: Field editor in table view: Configurable fast edit fields in TV
:idea: my personal page

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Hide field depending user group

Post by cesteban » 2019-05-20 21:40

Hi,

this is the code: (I changed some names doing tests, and I tried disable the checkbox)


function Pagos_dv($selectedID, $memberInfo, &$html, &$args){
/* current user is not an Adminis group?
$mi=$memberInfo['group'];
if($memberInfo['group'] != 'Admins'){
$html.=<<<EOC
<script>
\$j(function() { \Checado.disabled = true)
</script>
EOC;
}
}

And think the if is not working, I made some test directly from the console and hide o diabled working well
Attachments
checkbox.jpg
checkbox.jpg (97.31 KiB) Viewed 14715 times

User avatar
cesteban
Veteran Member
Posts: 52
Joined: 2018-04-18 09:56

Re: Hide field depending user group

Post by cesteban » 2019-05-20 22:59

Thanks to Alejandro Landini

Now is working

The code is:

function Pagos_dv($selectedID, $memberInfo, &$html, &$args){
// current user is not an Adminis group?
$mi=$memberInfo['group'];
if ($memberInfo['group'] != 'Admins'){
$html.="<script>\$j('#Checado').attr('disabled', true);</script>";
}
}

Best regards

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Hide field depending user group

Post by onoehring » 2019-05-24 12:35

Hi cesteban,

I think the field will be hidden from view only. The "interested" user could still use some tool (chrome developer console) to activate the checkbox.
Maybe it's worth keeping in mind, that user input should not be trusted.

I would think it would be much better, if the field would actually not be generated at all and that there should be some serverside checking done be AppGini to make sure that something the user does not see, can not be changed by that user either.

Olaf

lectura
Posts: 28
Joined: 2015-01-10 13:29

Re: Hide field depending user group

Post by lectura » 2019-10-31 05:28

how are you people;
been following the hide fields and I have manage to add some ideas for hiding date values for example you do not want users to input date.

function table_dv($selectedID, $memberInfo, &$html, &$args) {
$mi=$memberInfo['group'];
if ($memberInfo['group'] != 'Admins'){
$html.="<script>\$j('#status').attr('disabled', true);</script>";
$html.="<script>\$j('#date-dd').attr('disabled', true);</script>";
$html.="<script>\$j('#date-mm').attr('disabled', true);</script>";
$html.="<script>\$j('#date').attr('disabled', true);</script>";
}

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Hide field depending user group

Post by onoehring » 2019-12-11 15:46

Hi,

did you see my Field Permissions ( viewtopic.php?f=4&t=3308 )? I admit, implementing takes some minutes, but the result is quite good I think.

Olaf

Post Reply