Hide field depending user group

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
User avatar
cesteban
Posts: 28
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: 219
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.

User avatar
cesteban
Posts: 28
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

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 525
Joined: 2018-04-01 10:12

Re: Hide field depending user group

Post by pböttcher » 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".

User avatar
cesteban
Posts: 28
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
Posts: 28
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
Posts: 28
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

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 525
Joined: 2018-04-01 10:12

Re: Hide field depending user group

Post by pböttcher » 2019-05-16 19:49

Hi,

can you post what you have in your hook file

User avatar
cesteban
Posts: 28
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;
}
}

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 525
Joined: 2018-04-01 10:12

Re: Hide field depending user group

Post by pböttcher » 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')

User avatar
cesteban
Posts: 28
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
Posts: 28
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
Posts: 28
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
Posts: 21
Joined: 2016-03-06 00:59

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.

User avatar
cesteban
Posts: 28
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
Posts: 21
Joined: 2016-03-06 00:59

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.

User avatar
cesteban
Posts: 28
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 654 times

User avatar
cesteban
Posts: 28
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

onoehring
Veteran Member
Posts: 249
Joined: 2019-05-21 22:42
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

Post Reply