I've actually changed it manually (in 5.0f), but it was somewhat of a hack and definitely not upgrade safe, so I have mixed feelings about encouraging anyone to try and copy what I did. That being said, here's what I did; you're mileage may vary.
The key file involved is (for the US edition) /include/SugarFields/Fields/Address/en_us.EditView.tpl. For non-US users, I assume you change the file in the same folder named EditView.tpl.
In this file I found the line that creates the country field as a standard text input and commented it out like this:
Code:
{*<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}}">*} I then added this instead:
Code:
<select name="{{$country}}"
id="{{$country}}"
title='{{$vardef.help}}'
tabindex="{{$tabindex}}"
{{if isset($displayParams.javascript)}}
{{$displayParams.javascript}}
{{/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> Now you need to make sure Sugar treats the country field as a dropdown (enum) and knows which list to use. You can do this in a fast, non-upgrade-safe way, or the slower way. The non-upgrade-safe way is to go to /include/SugarObjects/templates/person/vardefs.php and modify the definitions of primary_address_country and alt_address_country. I played it safe and did the upgrade-safe modification instead. It means you have to create a file for each module you want to change. For example, for the Leads module I made a file called /custom/Extension/modules/Leads/Vardefs/custom.php. and added this code. The key changes are making the type = enum and adding an 'options' value:
PHP Code:
$dictionary['Lead']['fields']['primary_address_country'] =
array (
'name' => 'primary_address_country',
'vname' => 'LBL_PRIMARY_ADDRESS_COUNTRY',
'type' => 'enum',
'options' => 'countries_dom',
'group'=>'primary_address',
'comment' => 'Country for primary address',
'merge_filter' => 'enabled',
);
$dictionary['Lead']['fields']['alt_address_country'] =
array (
'name' => 'alt_address_country',
'vname' => 'LBL_ALT_ADDRESS_COUNTRY',
'type' => 'enum',
'options' => 'countries_dom',
'group'=>'alt_address',
'comment' => 'Country for alternate address',
'merge_filter' => 'enabled',
);
You will now need to repeat/adapt this change for any other modules (like Contacts) that you want to modify. Keep in mind that the Accounts module doesn't use the 'primary_' and 'alternate_' prefixes, but 'billing_' and 'shipping_' instead.
One other thing to change is the checkbox that lets you copy from one address to the other -- it doesn't work with dropdown fields. To be honest I find this feature fairly useless, so one easy option is to disable it. You do this by commenting out the last section of the en_us.EditView.tpl file that starts "{{if $displayParams.copy}} ...".
If you're feeling more daring, you can do what I did and replace the copy-as-you-type checkbox with a click-and-copy button. To do this, instead of commenting out the code as above, replace it with this:
Code:
{{if $displayParams.copy}}
<tr>
<td width='{{$def.templateMeta.widths[$smarty.foreach.colIteration.index].label}}%' class="dataLabel" NOWRAP>
{*{sugar_translate label='LBL_COPY_ADDRESS_FROM_LEFT' module=''}:*}
<input style='background-color:#D4D0C8;' type="button" value="Copy Primary Address" onclick="syncFields('{{$displayParams.copy}}', '{{$displayParams.key}}');">
{*<input id="{{$displayParams.key}}_checkbox" name="{{$displayParams.key}}_checkbox" type="checkbox" onclick="syncFields('{{$displayParams.copy}}', '{{$displayParams.key}}');"; CHECKED>
*}
</td>
</tr>
{{else}}
<tr>
<td colspan="2"> </td>
</tr>
{{/if}}
Now change the first line of this file so it points to the custom javascript file we're about to create:
HTML Code:
<script src="include/SugarFields/Fields/Address/SugarFieldAddress_cust.js" language="javascript"></script>
Now create a file in the same folder at the tpl file called "SugarFieldAddress_cust.js". Paste this code in:
HTML Code:
var elems=new Array("address_street", "address_city", "address_state", "address_postalcode","address_country");
function writeToSyncField(e){
fromEl=YAHOO.util.Event.getTarget(e,true);
if(typeof fromEl!="undefined"){
toEl=document.getElementById(fromEl.id.replace(fromKey,toKey));
toEl.value=fromEl.value;
}
}
function syncFields(fromKey,toKey){
for(x in elems){
f=fromKey+"_"+elems[x];
e2=document.getElementById(f);
t=toKey+"_"+elems[x];
e1=document.getElementById(t);
if (e2.tagName == "SELECT") {
e1.selectedIndex = e2.selectedIndex;
} else {
e1.value = e2.value;
}
}
} Although this seems to work for me just fine, I want to stress I haven't done extensive testing on different platforms/browsers and these changes will be blown away on the next update that changes the en_us.EditView.tpl file. Also, if your country list has labels that are different from the values, the list view and detail view will show the value rather than the label.
I hope this helps out,
Greg Watson
Bookmarks