7

I want to change the "Country" TextField in the Address panel into a dropdown. How can I do this?

Karl Hill
  • 6,972
  • 3
  • 39
  • 64
Ravin Chopra
  • 208
  • 3
  • 12

1 Answers1

10

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.

Karl Hill
  • 6,972
  • 3
  • 39
  • 64
  • 1
    Hello Karl Hill.. Thanks for the answer – Ravin Chopra Mar 22 '13 at 06:22
  • If you need to create a package for this in SugarCRM 7.x, try this: http://stackoverflow.com/questions/34701726/converting-a-textfield-to-dropdown-on-sugarcrm-on-demand-instance#answer-34719955 – Karl Hill Jan 11 '16 at 12:31