Instructions on how to change the Address State and Country textbox to dropdown. By default in Sugar it is a textbox. The state dropdown will also have dependency on the country and options in State will change according to the selected option in Country. This will also affect the conditions of the fields in Reports module.

Module used for this is Leads module.

1. Go to the following files

<sugar>/custom/modules/Leads/Ext/Vardefs/vardefs.ext.php

<sugar>/custom/Extension/modules/Leads/Ext/Vardefs/vardefs.ext.php

and add the following codes to the file:

$dictionary['Lead']['fields']['primary_address_state']['type'] = 'enum';
$dictionary['Lead']['fields']['primary_address_state']['options'] = 'cstm_states_list';
$dictionary['Lead']['fields']['alt_address_state']['type'] = 'enum';
$dictionary['Lead']['fields']['alt_address_state']['options'] = 'cstm_states_list';
$dictionary['Lead']['fields']['primary_address_country']['type'] = 'enum';
$dictionary['Lead']['fields']['primary_address_country']['options'] = 'cstm_countries_list';
$dictionary['Lead']['fields']['alt_address_country']['type'] = 'enum';
$dictionary['Lead']['fields']['alt_address_country']['options'] = 'cstm_countries_list';

*Note: This will make the type of the Primary and Alternate fields to dropdown and will assign cstm_states_list and cstm_countries_list as the options which is declared on No. 2.

$dictionary['Lead']['fields']['primary_address_state']['visibility_grid'] = array(
	'trigger' => 'primary_address_country',
	'values' => array(
		'Australia' => Array ('', 'ACT', 'NSW', 'VIC', 'QLD', 'SA', 'WA', 'TAS', 'NT'),
		'New Zealand' => Array ('', 'Auckland', 'Canterbury', 'Wellington', 'Waikato', 'Bay of Plenty', 'Manawatu-Wanganui', 'Otago', 'Hawkes Bay',
			'Northland', 'Taranaki', 'Southland', 'Nelson', 'Gisborne', 'Marlborough', 'Tasman','West Coast',),
	),
);

*Note: Value in the trigger is the field the state options will be dependent to. In the example, when Australia is selected, the options in the state will be the array assigned.
2. Go to <sugar>/custom/include/language/en_us.lang.php. This contains the custom dropdown list declarations. Add the codes below:
This is the default value for State dropdown

$GLOBALS['app_list_strings']['cstm_states_list'] = Array (
    '' => '',
    'ACT' => 'ACT',
    'NSW' => 'NSW',
    'VIC' => 'VIC',
    'QLD' => 'QLD',
    'SA' => 'SA',
    'WA' => 'WA',
    'TAS' => 'TAS',
    'NT' => 'NT',
    'Auckland' => 'Auckland',
    'Canterbury' => 'Canterbury',
    'Wellington' => 'Wellington',
    'Waikato' => 'Waikato',
    'Bay of Plenty' => 'Bay of Plenty',
    'Manawatu-Wanganui' => 'Manawatu-Wanganui',
    'Otago' => 'Otago',
    "Hawkes Bay" => "Hawkes Bay",
    'Northland' => 'Northland',
    'Taranaki' => 'Taranaki',
    'Southland' => 'Southland',
    'Nelson' => 'Nelson',
    'Gisborne' => 'Gisborne',
    'Marlborough' => 'Marlborough',
    'Tasman' => 'Tasman',
    'West Coast' => 'West Coast',);

This is the default value for Country dropdown

$GLOBALS['app_list_strings']['cstm_countries_list'] = Array (
    'Australia' => 'Australia',
    'New Zealand' => 'New Zealand',);

3. Go to <sugar>/include/SugarFields/Fields/Address and copy this files

DetailView.tpl

EditView.tpl

SugarFieldAddress.js

SugarFieldAddress.php

and create a CustomAddress folder in <sugar>/include/SugarFields/Fields/ then paste the fields inside CustomAddress folder.

4. Go to <sugar>/include/SugarFeilds/Fields/CustomAddress/EditView.tpland change the State field code:

<input id="{{$state}}" tabindex="{{$tabindex}}" type="text" maxlength="{{$vardef.len}}" name="{{$state}}" size="{{$displayParams.size|default:30}}" value="{$fields.{{$state}}.value}" />

to this:

<select name="{{$state}}" width="{{$displayParams.size|default:30}}" id="{{$state}}" title="{{$vardef.help}}" tabindex="{{$tabindex}}" {{if isset($displayParams.script)}}{{$displayParams.script}}{{/if}}>
{if isset($fields.{{$state}}.value) && $fields.{{$state}}.value != ''}
     {html_options options=$fields.{{$state}}.options selected=$fields.{{$state}}.value}
{else}
     {html_options options=$fields.{{$state}}.options selected=$fields.{{$state}}.default_value}
{/if}
</select>

and also change the Country field code:

<input id="{{$country}}" tabindex="{{$tabindex}}" type="text" maxlength="{{$vardef.len}}" name="{{$country}}" size="{{$displayParams.size|default:30}}" value="{$fields.{{$country}}.value}" />

to this:

<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>     

5. Go to <sugar>/custom/modules/Leads/metadata and updateeditviewdefs.php. Look for this code:

array (
            'name' => 'primary_address_street',
            'hideLabel' => true,
            'type' => 'Address',
            'displayParams' => 
            array (
              'key' => 'primary',
              'rows' => 2,
              'cols' => 30,
              'maxlength' => 150,
            ),
          ),
          1 => 
          array (
            'name' => 'alt_address_street',
            'hideLabel' => true,
            'type' => 'Address',
            'displayParams' => 
            array (
              'key' => 'alt',
              'copy' => 'primary',
              'rows' => 2,
              'cols' => 30,
              'maxlength' => 150,
            ),
          ),

and update the type from Address to CustomAddress

array (
            'name' => 'primary_address_street',
            'hideLabel' => true,
            'type' => 'CustomAddress',
            'displayParams' => 
            array (
              'key' => 'primary',
              'rows' => 2,
              'cols' => 30,
              'maxlength' => 150,
            ),
          ),
          1 => 
          array (
            'name' => 'alt_address_street',
            'hideLabel' => true,
            'type' => 'CustomAddress',
            'displayParams' => 
            array (
              'key' => 'alt',
              'copy' => 'primary',
              'rows' => 2,
              'cols' => 30,
              'maxlength' => 150,
            ),
          ),

6. Perform Quick Repair and Rebuild