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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tucho created an issue. See original summary.

tucho’s picture

Status: Active » Needs review
FileSize
683 bytes

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

podarok’s picture

Status: Needs review » Fixed

Thanks, merged.

  • podarok committed 1c02d43 on 7.x-3.x authored by tucho
    Issue #2567161 by tucho: Province name not shown when using autocomplete
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.