Closed (duplicate)
Project:
Location
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
28 Jan 2012 at 01:40 UTC
Updated:
12 Aug 2014 at 14:01 UTC
Jump to comment: Most recent
Comments
Comment #1
TahitiPetey commentedWoohoo! I figured out a solution. After trudging through the Location module codes, I found the offending lines of code (lines 311 to 315).Originally, the code is as such:if (!isset($element['value']['country'])) {$country = $fdefaults['country'];
}
else {
$country = $element['#value']['country'];
}
I'm unsure how this could have at any point even worked, there is no ['value'] attribute in the array $element (it's #value, you can see this clearly if you dpm($element);).The solution is to replace those lines with these:if (!isset($form_state['values']['locations'][0]['country'])) {$country = $fdefaults['country'];
}
else {
$country = $form_state['values']['locations'][0]['country'];
}
Understandably, this is more of a customized hack for my particular use case--if you require more than 1 location (and thus there are multiple ['locations'][#] sub-arrays), then this would break horribly.Nevermind, this solution doesn't pass validation (I guess I counted my chicken before they hatched!). I did find another solution, I'll post it as a patch tomorrow once I have some time.
Comment #2
Sibiraj PR commentedsame problem here
Comment #3
mstef commentedSame problem, but only on the user profile form. It seems to be working fine on node forms.
Comment #4
ss81 commentedI have the same problem.
Comment #5
Eric B. commentedI have the same problem in 7.x-3.0-alpha1.
Comment #6
gpvdo commentedI ran into the same problem and I have it working - see 'location_element' in Drupal form with Country/Province(select) AJAX update
Looks like TahitiPetey identified part of the problem 2 years ago - I am surprised that it has not been fixed yet. He had the correct solution but ran into the validation issue.
I have a fix for the validation issue as well (validation fails because after repopulating state options, the previous selection may no longer be valid) - I have fixed that as well (see above link).
If you try the fix, please post your results.
Comment #7
djdevinDupe of #1997658: States/Provinces dropdown not updating with country change, fix over there