set a checkbox field as readonly for those who do not belong to the admin group

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

set a checkbox field as readonly for those who do not belong to the admin group

Post by fgazza » 2019-10-06 12:21

Hi!
I would like to set a checkbox field (named autorizza_attestato) as readonly for those who do not belong to the admin group.

I used this code in the hook file of my table partecipazione_evento_pubblico but it does not work.

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

<?php
$form_code = ob_get_contents();
ob_end_clean();

$html .= $form_code;


if(!in_array($memberInfo['group'], ['Admins'])) {
ob_start();
?>
<script>
$j(function() {
$j('#autorizza_attestato').prop('readonly', true);
})
</script>
<?php
$html .= ob_get_clean();
}

}

Any help please?

Thank you!

Fabiano

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

Re: set a checkbox field as readonly for those who do not belong to the admin group

Post by pbottcher » 2019-10-06 16:51

Hi Fabiano,

use

$j('#autorizza_attestato').attr("disabled", true);
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.

fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Re: set a checkbox field as readonly for those who do not belong to the admin group

Post by fgazza » 2019-10-06 17:18

thanks also for this advice!
I read in the forum somewhere that the "disable" attribute can create data loss. I didn't understand what you meant.
Can I safely use the disable attribute?

the important thing is that if the administrator sets the field in a state and an unauthorized user opens the record and modifies it, not the checkbox field remains in the status set by the administrator

Thanks!
Fabiano

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

Re: set a checkbox field as readonly for those who do not belong to the admin group

Post by pbottcher » 2019-10-06 19:29

Hi Fabiano,

when you use the disable attribute, the data for that field will not be passed when the page is submitted. So as you only want the admin to change that field, there is no risk of data loss.
It would be different if you would use that field in a conditional way via another input which would disable the field.
So to my opinion, in your case, you can use it like that.
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.

fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Re: set a checkbox field as readonly for those who do not belong to the admin group

Post by fgazza » 2019-10-06 20:09

Thank you so much for your explanations!
So i think too that in my case I can use the disable attribute with no risks!
Thanks a lot !!!
Fabiano

Post Reply