How to create custom dropdown field read only according to Roles?

Using this code, I can make text field read only according to Roles.

‘customCode’ => ‘<input type=“text” class=“distance_c” tabindex=“0” title="" value="{$fields.distance_c.value}" maxlength=“100” size=“30” id=“distance_c” name=“distance_c” {$readOnly}>’,

but for dropdown field how It would be changed???

Can anyone help me here? Thanks in advance…

:frowning: :dry: :silly: :blink:

Hi there,

You could do this for each option in the dropdown, or do a for loop and for each item in the array/drop down set them to read only?

Thanks,

Will.

Thanks for the reply Sir.

Could you please help me how to do that?

Dear Frndz,

Need your kind support for creating custom dropdown field read only and relate field read only according to roles???

Thanks

Hello sandeepg,

I have a question, how do you set in roles to define if the field is readonly or not?

Hello sandeepg,

I finally understand what you mean:

see the response in http://www.suitecrm.com/index.php?option=com_kunena&view=topic&catid=12&id=305&Itemid=1136#5620.

Hello Sugar Frnd,

Thankyou very much for your reply.

Using your code for custom dropdown field, I got it working.
But for the default dropdown fields, the code is still not working.

Why it is not working for default dropdown fields?

Thanks,
Sandeep Bodh

You can paste here your code of defs and view.edit?

Because I used the same code to change the default dropdown account_type in Accounts module and works fine.

Hello Frnd,

No, I again checked it for account_type field, but its still not working.

The code in view.edit.php file is:

<?php if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); class CasesViewEdit extends ViewEdit { public function display() { // add this if function display doesn't exist global $current_user; // check if current user is in specific role $IS_AM = in_array("ASC / Franchisee", ACLRole::getUserRoleNames($current_user->id)); if($IS_AM && !empty($this->bean->id)) { $this->ev->ss->assign('readOnly', 'readonly = "readonly"'); $this->ev->ss->assign('readOnlyDropDown', 'disabled= "true"'); } else { $this->ev->ss->assign('readOnly', ''); $this->ev->ss->assign('readOnlyDropDown', ''); } parent::display(); // add this if function display doesn't exist } // add this if function display doesn't exist } And the code in editviewdefs.php is: array ( 'name' => 'ticket_status_c', 'studio' => 'visible', 'label' => 'LBL_TICKET_STATUS', 'customCode' => ' Open Closed Pending ', ), ), This is for custom dropdown and it is working fine, now I have removed the default dropdown. You can use any default dropdown field from the module. Thanks, Sandeep Bodh

Can you please help me how to make relate field read only according to roles?

Thanks

Hi sandeepg,

I dont understand why it would work for custom fields and not for default fields yet fairly surprised that it works at all.

By definition, a dropdown is always READONLY.
By definition, a dropdown DISABLED is not sent via FORM SUBMIT.

So if you were to set the field to disabled it would act like its read only and not selectable. however doing this will remove it from being posted to SuiteCRM and not saved into the database. I overcame this by setting the dropdown to disabled and inserting a hidden field with the same name and value of the disabled field. e.g

<select name="one" disabled>
<option selected>default
<option>other
<option>you can't pick this
<option>pick me if you can
<option>blah
</select>
<input type="hidden" name="one" value="default">

all thats left to do here is put this into SuiteCRM for the drop downs that you require it on. Hope that helps.

Hey lan,
It is not working for me. I’m using suite 7.11.4
and if I set hidden field with same name then form is not submitting.