我想将“地址”面板中的“国家/地区”文本字段更改为下拉列表。我怎样才能做到这一点?
最佳答案
SugarCRM 6.x:
1) 为您的国家字段创建或更新 vardef:
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) 复制地址字段的编辑 View 模板...
包括/SugarFields/Fields/Address/EditView.tpl
进入/custom 中的新目录:
自定义/include/SugarFields/Fields/[CUSTOM_TYPE_NAME]/EditView.tpl
3) 编辑模板并更改:
<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}}">
收件人:
<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) 在 custom/modules/[MODULE_NAME]/metadata/editviewdefs.php 中将“type”更改为新的自定义类型名称。
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。对要从文本字段更改为下拉列表的每个国家/地区字段重复步骤 1 和 4。对于之前输入的值,您需要确保它们与“countries_dom”中的值匹配。
在 SugarCRM 7.x 中,这更简单,您只需执行第 1 步。
关于php - 在 SugarCRM 中将国家/地区文本字段更改为下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15475553/