I want to change the "Country" TextField in the Address panel into a dropdown. How can I do this?
SugarCRM 6.x:
1) Create or update the vardef for your country field:
custom/Extension/modules/[MODULE_NAME]/Ext/Vardefs/custom_primary_address_country.php
$dictionary['<MODULE_NAME>']['fields']['primary_address_country']['comments']='Country for primary address';
$dictionary['<MODULE_NAME>']['fields']['primary_address_country']['group']='primary_address';
$dictionary['<MODULE_NAME>']['fields']['primary_address_country']['options']='countries_dom';
$dictionary['<MODULE_NAME>']['fields']['primary_address_country']['type']='enum';
2) Copy the edit view template for the Address fields...
include/SugarFields/Fields/Address/EditView.tpl
into a new directory within /custom:
custom/include/SugarFields/Fields/[CUSTOM_TYPE_NAME]/EditView.tpl
3) Edit the template and change:
<input type="text" name="{{$country}}" id="{{$country}}" size="{{$displayParams.size|default:30}}" {{if !empty($vardef.len)}}maxlength='{{$vardef.len}}'{{/if}} value='{$fields.{{$country}}.value}' tabindex="{{$tabindex}}">
To:
<select name="{{$country}}" width="{{$displayParams.size|default:30}}" id="{{$country}}" title="{{$vardef.help}}" tabindex="{{$tabindex}}" {{if isset($displayParams.script)}}{{$displayParams.script}}{{/if}}>
{if isset($fields.{{$country}}.value) && $fields.{{$country}}.value != ''}
{html_options options=$fields.{{$country}}.options selected=$fields.{{$country}}.value}
{else}
{html_options options=$fields.{{$country}}.options selected=$fields.{{$country}}.default_value}
{/if}
</select>
4) In custom/modules/[MODULE_NAME]/metadata/editviewdefs.php change "type" to your new custom type name.
0 =>
array (
'name' => 'primary_address_country',
'hideLabel' => true,
'type' => '<CUSTOM_TYPE_NAME>',
'displayParams' =>
array (
'key' => 'primary',
'rows' => 2,
'cols' => 30,
'maxlength' => 150,
),
'label' => 'LBL_PRIMARY_ADDRESS_COUNTRY',
),
5. Repeat steps 1 & 4 for every country field you want to change from a textfield to dropdown. For previously entered values you'll need to make sure they match the values within 'countries_dom.'
In SugarCRM 7.x this is simpler, you should only need to do Step 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With