function display(){ // add this if function display doesn't exist
global $current_user;
// check if current user is in specific role
// code taken from thread
$IS_AM = in_array("<ROLE NAME>", ACLRole::getUserRoleNames($current_user->id));
if($IS_AM)
$this->ev->ss->assign('readOnly', 'readonly = "readonly"');
else
$this->ev->ss->assign('readOnly', '');
parent::display(); // add this if function display doesn't exist
} // add this if function display doesn't exist
Dropdown fields not accept readonly atribute in tag. And date & time field have a javascript onclick atribute in the calendar image, so the best way is hide the field. To make dropdown field “readonly” and hide the date field, include in the display() function:
function display(){ // add this if function display doesn't exist
global $current_user;
// check if current user is in specific role
// code taken from thread
$IS_AM = in_array("<ROLE NAME>", ACLRole::getUserRoleNames($current_user->id));
if($IS_AM){
$this->ev->ss->assign('readOnly', 'readonly = "readonly"');
$this->ev->ss->assign('readOnlyDropDown', 'disabled= "true"');
$this->ev->ss->assign('HideDateTime', 'style="display:none;"');
}else{
$this->ev->ss->assign('readOnly', '');
}
parent::display(); // add this if function display doesn't exist
} // add this if function display doesn't exist
@berriop hello buddy , Actually i was trying to do the same with the image field , Is that possible? to do so ?
If its possible could you please tell me in detail.Thanks in advance.
I sort of combined what you did and another post using {if} statements in the custom code. I needed to test if user was admin, if so then make it editable. Otherwise, just show the value.
My view.edit.php is:
class AccountsViewEdit extends ViewEdit
{
public function __construct()
{
parent::__construct();
$this->useForSubpanel = true;
$this->useModuleQuickCreateTemplate = true;
}
public function display()
{
global $current_user;
// Check if the user is an administrator
$isAdministrator = $current_user->is_admin;
// Set the $readOnly variable based on the user's administrator status
$readOnly = $isAdministrator ? '' : 'readonly = "readonly"';
// Assign $readOnly to Smarty template
$this->ev->ss->assign('readOnly', $readOnly);
//Assign $isAdministrator to Smarty template
$this->ev->ss->assign('isAdministrator', $isAdministrator);
parent::display(); // Call the parent display function to render the view
}
}