Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When editing a location with an autocomplete province field, it shows the province code besides the province name, even when you have configured location to use full province names.
The value of location_use_province_abbreviation is not checked in the function location_locationapi, so it always uses the province code:
case 'province':
if (isset($a5['country']) && is_string($a5['country'])) {
$country = $a5['country'];
}
elseif (isset($a5['country']['default']) && is_string($a5['country']['default'])) {
$country = $a5['country']['default'];
}
else {
$country = variable_get('site_default_country', 'us');
}
switch ($settings['widget']) {
// @codingStandardsIgnoreStart
case 'select':
// Options are defined once during hook_element implementation.
// @see _location_process_location
// $options = array_merge(array('' => t('Select'), 'xx' => t('NOT LISTED')), location_get_provinces($country));
if (!empty($settings['#parents'])) {
$wrapper_suffix = '-' . implode('-', $settings['#parents']);
}
else {
$wrapper_suffix = '';
}
return array(
'#type' => 'select',
'#title' => t('State/Province'),
'#default_value' => $obj,
'#description' => NULL,
'#required' => ($settings['collect'] == 2),
'#attributes' => array('class' => array('location_dropdown_province')),
'#prefix' => '<div id="location-dropdown-province-wrapper' . $wrapper_suffix . '">',
'#suffix' => '</div>',
);
// @codingStandardsIgnoreEnd
case 'autocomplete':
default:
drupal_add_js(drupal_get_path('module', 'location') . '/location_autocomplete.js');
return array(
'#type' => 'textfield',
'#title' => t('State/Province'),
'#autocomplete_path' => 'location/autocomplete/' . $country,
'#default_value' => $obj,
'#size' => 64,
'#maxlength' => 64,
'#description' => NULL,
'#attributes' => array('class' => array('location_auto_province')),
'#required' => ($settings['collect'] == 2),
);
}
The #default_value of the returned array of the autocomplete case should be the province name, when location_use_province_abbreviation is false.
Comment | File | Size | Author |
---|---|---|---|
#2 | location-province_autocomplete_full_name-2567161-2.patch | 683 bytes | tucho |
Comments
Comment #2
tuchoI attach a patch that fixes this issue.
When you select using full province names, the autocomplete field shows the full name besides the province code.
Comment #3
podarokThanks, merged.