Page 1 of 1
Hide field depending user group
Posted: 2019-05-15 19:02
by cesteban
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
Re: Hide field depending user group
Posted: 2019-05-15 19:33
by jsetzer
Do eoc and EOC match in your code? In your forum post they don't.
Re: Hide field depending user group
Posted: 2019-05-15 21:47
by cesteban
Thanks
I copied exacttly the sample code from the suport page from AppGini
Regards
Re: Hide field depending user group
Posted: 2019-05-16 07:12
by pbottcher
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".
Re: Hide field depending user group
Posted: 2019-05-16 18:16
by cesteban
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
Re: Hide field depending user group
Posted: 2019-05-16 18:33
by cesteban
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
Re: Hide field depending user group
Posted: 2019-05-16 19:04
by cesteban
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
Re: Hide field depending user group
Posted: 2019-05-16 19:49
by pbottcher
Hi,
can you post what you have in your hook file
Re: Hide field depending user group
Posted: 2019-05-16 23:23
by cesteban
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;
}
}
Re: Hide field depending user group
Posted: 2019-05-17 11:02
by pbottcher
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')
Re: Hide field depending user group
Posted: 2019-05-20 15:12
by cesteban
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
Re: Hide field depending user group
Posted: 2019-05-20 15:31
by cesteban
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)
Re: Hide field depending user group
Posted: 2019-05-20 15:34
by cesteban
Sorry
it isn't a error is working the function from de console, but not from the php file
Re: Hide field depending user group
Posted: 2019-05-20 15:39
by landinialejandro
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.
Re: Hide field depending user group
Posted: 2019-05-20 16:30
by cesteban
I thing the If isn't working!!!
Re: Hide field depending user group
Posted: 2019-05-20 18:35
by landinialejandro
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.
Re: Hide field depending user group
Posted: 2019-05-20 21:40
by cesteban
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
Re: Hide field depending user group
Posted: 2019-05-20 22:59
by cesteban
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
Re: Hide field depending user group
Posted: 2019-05-24 12:35
by onoehring
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
Re: Hide field depending user group
Posted: 2019-10-31 05:28
by lectura
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>";
}
Re: Hide field depending user group
Posted: 2019-12-11 15:46
by onoehring
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