Page 1 of 1

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

Posted: 2019-10-06 12:21
by fgazza
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

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

Posted: 2019-10-06 16:51
by pbottcher
Hi Fabiano,

use

$j('#autorizza_attestato').attr("disabled", true);

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

Posted: 2019-10-06 17:18
by fgazza
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

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

Posted: 2019-10-06 19:29
by pbottcher
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.

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

Posted: 2019-10-06 20:09
by fgazza
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