I noticed this had been an issue in a previous version but I have the latest (7.x-3.0-rc1) and the states/provinces will not update when the view is a dropdown. Autocomplete doesn't have the problem--just dropdown. The droplist fails to update when the country is changed.

Before it looks like the culprit was in the _location_country_ajax_callback function in the location.module file but I checked mine against the patch from a year ago and it rc1 already has that patch in place.

Any ideas?

Files: 
CommentFileSizeAuthor
#38 states_provinces-1997658-38.patch3.95 KBdjdevin
PASSED: [[SimpleTest]]: [MySQL] 425 pass(es).
[ View ]
#32 1997658-failing-example.patch1.97 KBdjdevin
PASSED: [[SimpleTest]]: [MySQL] 425 pass(es).
[ View ]
#24 states_provinces-1997658-24.patch3.88 KBdjdevin
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch states_provinces-1997658-24.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Comments

delvalle’s picture

Same problem here...

delvalle’s picture

I guess there are many users experiencing this same problem, since I found two more issues regarding this: http://drupal.org/node/1419448 and http://drupal.org/node/1430294. Both are quite old (2012) but still not solved.

Anyone could help, please?

edubuc’s picture

Hi,

Right now I have the same problem when I use Country/Province location field (with dropdown display) on a profile2 entity type.

So on custom node type :

  • Dropdown view : ok
  • Autocomplete view : ok

On a profile2 (entity type) :

  • Dropdown view : not ok - the province list does not update on country change
  • Autocomplete view : ok
vashel’s picture

Version:7.x-3.0-rc1» 7.x-3.0-rc4

I'm running into the same issue with the latest version of Location (7.x-3.0-rc4). I also have profile2 installed, however, I'm running into this problem with the state/province list not updating on the normal user profile form (enabled in Configuration -> Account Settings -> Location Settings). The auto-complete field updates as it should.

Any idea how to fix this? Patches or workarounds?

vashel’s picture

Version:7.x-3.0-rc4» 7.x-3.0-rc5

Still an issue in RC5.

fugazi’s picture

same problem as in #3
profile2
dropdown does not work the province list,
autocomplete ok.

Node Type
dropdown ok,
autocomplete ok.

tested, 7.x-3.x-dev and 7.x-3.1 both are not working

jschoder’s picture

I had the same problem in my local installation. Didn't have the time to support a patch yet. Here is the solution if you want to duplicate it:
https://drupal.org/node/2122095

fugazi’s picture

#7 did you solve it? How could you solve it for your case?

podarok’s picture

Mnilionic’s picture

On custom entities dropdown not updating too

djdevin’s picture

Version:7.x-3.0-rc5» 7.x-3.x-dev
Component:Data update» Code
StatusFileSize
new3.82 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch states_provinces-1997658-11.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Here's a patch to fix it hopefully wherever it is used. Tested with node forms,field configuration, and profile2.

The challenge was setting the value of the province field while the triggering element is the country field. So you have to go up and down the form tree.

Instead of relying on this super old arg(x) logic in the ajax call we can use drupal_array_get_nested_value() and the element's #array_parents.

djdevin’s picture

Status:Active» Needs review
mark.cameron’s picture

The patch works and displays the correct states, but when I try to create a user with a state I get an error saying:

"An illegal choice has been detected. Please contact the site administrator."

I can only create a new user if I don't select a state, Might be linked to the patch?

djdevin’s picture

Try selecting a different country, then a state. I think it has to do with the form rebuild. I'm sure the patch can be fixed up. It's much more graceful solution.

mark.cameron’s picture

No that doesn't work either, as long as I set a state it won't create the user.

It sends me back to the form, the country is selected, but the states list isn't populated, if I change to another country and select a different state, and save, same thing happens.

djdevin’s picture

How do you have your location set up?

jphelan’s picture

This patch did not fix it for me. Using the location field on a crm entity as part of the crm_core module.

DrCord’s picture

When will this patch be committed?

DrCord’s picture

Version:7.x-3.x-dev» 7.x-5.x-dev
DrCord’s picture

This issue still persists on the latest dev version and the patch offered is no longer applicable.

djdevin’s picture

Version:7.x-5.x-dev» 7.x-3.x-dev

Current version is 7.x-3.x

Status:Needs review» Needs work

The last submitted patch, 11: states_provinces-1997658-11.patch, failed testing.

djdevin’s picture

Status:Needs work» Needs review
StatusFileSize
new3.88 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch states_provinces-1997658-24.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Rerolled.

DrCord’s picture

Then why do I have 7.x-5.x-dev as the latest version, downloaded from drupal.org via drush? This problem still persists in that version...

The very latest dev version that apparently came out last night does not seem to have this problem anymore...yay!

djdevin’s picture

I think it's because 5.x is technically newer than 3.x however it was abandoned long ago.

You won't see the issue unless you are using a location field outside of the root of a form or in the 'locations' form element. So, basically anything that isn't stock Drupal/Location, like field collection or profile2.

DrCord’s picture

If you have an abandoned branch that is easily installable, that is REALLY messed up, you need to remove it. Drupal's auto update informed me of an update to this branch that needed to be installed as it was newer... drush happily moved me to the abandoned branch...

Now I am on a abandoned branch and moving back is going to be a problem...please advise.

podarok’s picture

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

7.x-4.x and 7.x-5.x are abandoned versions. Don't use them. The working and actively maintained branch is 7.x-3.x
This version marked as supported instead of others, so if You have got an abandoned via drush for some unknown reason - this is a bug of a drush.

Sorry for making You uncomfortable with using location module. Abandoned branches are the tails from previous maintainers and will be removed asap

Please, do update tjis issue if You want something updated/changed...

djdevin’s picture

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

Hey this is actually still "needs review" (#24)

It fixes an issue when Location fields are used within nested field locations (i.e., not at the root of $form).

Currently reproducible in 3.x with field collection and profile2.

podarok’s picture

Status:Needs review» Needs work
Issue tags:+Needs tests

#24 looks not so trivial. Good to see test cases here.
Needs tests.

djdevin’s picture

Hm it's tricky because it's AJAX, I'm not sure we can test it thoroughly with Simpletest.

To be fair there also aren't any existing tests for the Location AJAX functionality so this would be a new test case anyway.

I'll try it without JS off and maybe submitting the form with only a country selected will give me something to work with.

djdevin’s picture

StatusFileSize
new1.97 KB
PASSED: [[SimpleTest]]: [MySQL] 425 pass(es).
[ View ]

Here's an example of it not working, just a simple "location_element" field on a custom form.

Selecting a country has no effect.

After patching with #24, it works as expected.

I tried to write some tests but I can't find a way to reproduce it without AJAX. I might be able to fake a POST and check responses.

wwwjaylee’s picture

Status:Needs work» Reviewed & tested by the community
Issue tags:-Needs tests

Djdevin, #24 works flawlessly! Thank you so much!

The last submitted patch, 24: states_provinces-1997658-24.patch, failed testing.

podarok’s picture

Status:Reviewed & tested by the community» Needs work
deminy’s picture

We noticed this issue with our Drupal installation (Drupal 7.37, Location 7.x-3.6, Commerce 7.x-1.11, with multilingual support) under certain situation:

* We have a few languages enabled, including English and Chinese. We did not see any related issues with English version.
* When editing Commerce products with default admin pages shipped by Commerce, everything is fine even under Chinese language.
* Under the customized product edit page developed by us, the issue happened when using Chinese language, as mentioned in the title of this thread: "States/Provinces dropdown not updating with country change".

Applying patch #24 fixed the issue. I have just applied the patch and not quite sure if there could be any side-effects, but will report in case I see any.

Thanks for the patch, @djdevin.

djdevin’s picture

Status:Needs work» Needs review
StatusFileSize
new3.95 KB
PASSED: [[SimpleTest]]: [MySQL] 425 pass(es).
[ View ]

Rerolled.

Miles Ulrich’s picture

#38 solved an issue I was seeing with a Location field inside of a Profile2 profile. Thanks!

fyberoptik’s picture

Thanks djdevin!!! #38 worked perfectly.