I am currently using the dev version of location module. For some reason the autocomplete feature for location node field is not working. I'm wondering if this is an issue that someone has had. I'm not getting any errors and can't seem to track the issue down.


Realeiko’s picture

Status: Active » Needs work

I have the same issue (Drupal 6.19 + Location 6.x-3.x-dev (2010-Sep-30)).

I've used firefox to peek arround form elements data, and I've found that #autocomplete_path value of state/province is badly build by default. In my case (default country forced to Spain, 'es' code), the value was
'/?q=location/autocomplete/e', instead of '/?q=location/autocomplete/es' (note that contry code is truncated, and this is the bug).

The cause is a incorrect declaration of the default country code in function location_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) in location.module:

function location_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {
  switch ($op) {
    /* ... Other API operations... */

    case 'field_expand':
      switch ($a3) {
    /* ... Other fields expansions ... */
        case 'province':
          drupal_add_js(drupal_get_path('module', 'location') .'/location_autocomplete.js');
          // Original buggy line: $country = $a5['country']['default'] ? $a5['country']['default'] : variable_get('location_default_country', 'us');
          $country = $a5['country'] ? $a5['country'] : variable_get('location_default_country', 'us');
          return array(
            '#type' => 'textfield',
            '#title' => t('State/Province'),
            '#autocomplete_path' => 'location/autocomplete/'. $country,
            '#default_value' => variable_get('location_use_province_abbreviation', 1) ? $obj : location_province_name($country, $obj),
            '#size' => 64,
            '#maxlength' => 64,
            '#description' => NULL,
            // Used by province autocompletion js.
            '#attributes' => array('class' => 'location_auto_province'),
            '#required' => ($a4 == 2),
    /* ... Other fields expansions ... */

Sorry about not providing a .diff file patch... I'm a Drupal newbie and I don't now how to do it... yet... (how embarrassing!!).

atomicbop’s picture

Nice find. Worked perfectly.

jfox77’s picture

Thanks, Realeiko! Fixing the location_locationapi in location.module solved my problem!

rooby’s picture

Status: Needs work » Fixed

I have committed a fix that fixes this issue as well as these two related issues:
#846604: warning: trim() expects parameter 1 to be string, array given in sites/all/modules/location/location.inc on line 498.
#990804: When "Display full province name" is selected, parts of the administrative UI become disabled

The fix was taken from bdragon's DRUPAL-7--4 branch, where he had already fixed this.
The fix checks both $a5['country']['default'] and $a5['country'] as there are times when each is valid.


Status: Fixed » Closed (fixed)

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