Can't submit locations when country changes from the default setting on the node. Autocomplete does not update with the new provinces, causing a form validation error.

Comments

John Carbone’s picture

Title: Province autocomplete not updating when country changes. » Province autocomplete not updating when country changes.

OK, I was able to pin this down. It's actually an issue with the "Admin" theme (aka Slate). Broken Javascript within the theme prevents the Location module's autocomplete.js from firing. You can still use Slate with Location but you'll have to set the administration theme to use the site default when editing nodes.

sreynen’s picture

I had this same problem in a content profile location, and turning off admin module completely didn't fix it, nor did turning off all JS on my theme. I "fixed" it by adding a change() handler for countries to my theme's JS that replicates some of location_autocomplete.js.

YesCT’s picture

Priority: Critical » Normal
Status: Active » Postponed (maintainer needs more info)

Please post the code you used to fix this.

sreynen’s picture

Status: Postponed (maintainer needs more info) » Needs work

This is the code I used in my theme's Drupal.behavior function to get it working:

$('.location_auto_country').change(
    function() {
      var $auto = $(this).parent().siblings('.autocomplete');
      $auto.siblings('.state-province').find('input').unbind();
      $auto.val($auto.val().substr(0, $auto.val().lastIndexOf('/') + 1) + $(this).val()).removeClass('autocomplete-processed');
      Drupal.behaviors.autocomplete(document);
    } // function
 );

As I said, it's duplicate code from Drupal.behaviors.location, so it could use some refactoring if this looks like a good solution.

YesCT’s picture

Issue tags: +location useful code

tagging. as the code in #4 might help others fix this problem, but is not in it's current form a fix ready for commit...

docwilmot’s picture

hello
have location cck in a content profile node and have the same problem. #4 almost works, except if you select one country, then change to another and another, afterwards if for example you type 'p' and each of the countries you've previously tried has a county starting with 'p' you get 3 simultaneous dropdowns listing counties starting with 'p'. firebug shows a div id="autocomplete" for each country.
is there a problem with locations in content profiles? would be grateful for a fix either way.
thanks

docwilmot’s picture

seems this works:

$('.location_auto_country').change(
    function() {
      var $auto = $(this).parent().siblings('.autocomplete');
      $auto.siblings().find('input').unbind();
      $auto.val($auto.val().substr(0, $auto.val().lastIndexOf('/') + 1) + $(this).val()).removeClass('autocomplete-processed');
      Drupal.behaviors.autocomplete(document);
    } // function
);

but still curious why this is necessary at all.

jphelan’s picture

Issue summary: View changes

Same issue. For me it was lines 8 and 25 and/or 30 of location_autocomplete.js. The admin theme I'm using replaces the fieldsets with collapsible divs in the template.php file. Changing the fieldset:first to the themes class for the wrapper div fixed it for me.

var country_input = $('.location_auto_country', $(this).parents('fieldset:first, .views-exposed-form:first'));

provinceItem = $('.location_dropdown_province', $(this).parents('fieldset:first, .views-exposed-form:first'));
legolasbo’s picture

Status: Needs work » Closed (outdated)

Closing old D6 issues as D6 is end of life