I have a few issues with the location module.

Is there a way you can make location module to show state/province as a drop down . The default is autocomplete and users type in what they want and it becomes an unknown entry. Also would like to show the full state name in address field.

Also how can you add new provinces?

Thanks in advance


Anarchtica’s picture

I would also like to see the state/province as a drop down menu.

jcamfield’s picture

This would be great as an option to use instead of the auto-complete, especially with some of the varying ways to enter provinces (e.g., in Jamaica, the standard way to name a province is St. Andrew, but in Locations it's expanded to Saint Andrew -- which I'm sure is conforming to a wise standard, but causes some confusion when the St... doesn't auto-complete.

aaronbauman’s picture

I'm not a fan of the autocomplete, and many of my clients don't want it.

aaronbauman’s picture

Version:5.x-3.0» 6.x-3.x-dev

moving this to HEAD

andrewsuth’s picture

+1 for drop-down option

superduperdan’s picture

After searching, I don't think there is a module that would enable this feature. Would like to see this integrated.

YesCT’s picture


khan2ims’s picture


Is there any updates on doing drop down for state/ province field?

Xabi’s picture


mrtoner’s picture

Category:support» feature
Priority:Critical» Normal
Status:Active» Needs review
new1.3 KB

See how this works for you.

Summit’s picture

Subscribing, greetings, Martijn

Drupal-Tech’s picture

Patch only work for first time.. first time it shows state of US what about when we change Country

kvvnn’s picture

I need this functionality as well. I will post any success I have in implementing / finding it.

Summit’s picture

Great! Looking forward to it!
Greetings, Martijn

sbydrupal’s picture

Subscribe +1

nick.harris’s picture

Agreed and following also.

mcaden’s picture


Wait...The patch mrtoner made...Is Drupal-Tech saying it works for US and nowhere else, or works for US once and when country gets changed stops working at all?

scottrigby’s picture

works for me (US)

Though this should probably be a configuration?

onesimpleman’s picture

Yes it works only for the default location,
ie if it is UK it shows states in UK same with USA.
Changing the country has no effect on the states. ie if I change country to xyz the states will still be showing the states in the default country.
I think the patch works partially, but think it needs a new location_autocomplete.js to make it work properly.

jcamfield’s picture


Especially with some of the lacking information about states in a lot of non-Western countries; this would be really helpful.

Also - I've already sunk a lot of time into updating some of the /supported files; should I start submitting them?

lalart.pl’s picture


mcaden’s picture

BTW the patch in #10 worked for me.

cerup’s picture


I think this is an essential feature. I have to make this field required so that I can map correctly, but many of my users can't find their correct state/province through autocomplete. A drop-down is a must.

cerup’s picture


I agree, this is essential. Like the above, I must require this field for proper mapping, but many of the users can't find their closest state/province which means they can't complete registration.

Summit’s picture

May be using hierarchical_select for this (www.drupal.org/project/hierarchical_select) ? That works great for taxonomy and nodes, but I do not see a location submodule yet. I am not a programmer, but would test for the builder off course.

Lots of blogging about it, see masterissue: http://drupal.org/node/31609#comment-906923. I think Wim and Bdragon didn't get in touch yet...

greetings, Martijn

jrosen’s picture


newtonpage’s picture

Version:6.x-3.x-dev» 6.x-3.1-rc1
Category:feature» support
Priority:Normal» Critical

My 2-cents - - I very much need this, too - - in my case, I would love to have the ability to use JS to control specific options within a drop-down if the country has state/province info and a non-autocomplete text box for unsupported countries.

The main issue for our site is that we require the state and country and city for a node (and user) but find it is quite easy to fail validation WRT state-city matching (in the US). (Note that we are using the non-CCK implementation as this worked best for us.

Also, the current autocomplete is insensitive to country, so that a node located in (for example) the UK will auto-suggest US states. (Noting that the default country in our case is set the US) - - apologies if this is contained indifferent thread (I will search this out).

So, my wish-list is as follows - - and I would massively grateful for guidance as to patches and snippets:

1) drop-down for state-provinces that are supported - - use JS to swap in the correct widget or to populate the options within the select (the latter being preferred for obvious reasons).

2) in non-supported countries, use a non-autocomplete text box and allow mistakes (that is, do not validate country vs. province)

Has anyone done this sort of thing before? If so, love to pick your brain (and will certainly return the favor if I can). I am in the process of constructing a module to deal with this sort of thing.

thanks to all


newtonpage’s picture

Update to the previous post.

First of all - - apologies for posting before properly researching this (IMHO) excellent module / api (notwithstanding other (not-so-appropriate criticisms I have seen).

So, here is what I am doing:

in the node entry form, substitute a select drop-down for the current text box (not quite how I will do this yet) with the appropriate id and name and so on.

default to the US.

use location_get_provinces() to fetch an array of provinces

populate the box.

When the user changes country, use jQuery to detect the change and use ajax to call a module-based function to return a new select box (via json) to swap in.

submit the country in the ajax data - - seem to be able to use the simple jQuery load function.

example get the country from the submitted data
$current_country = 'whatever';

$us_countries_array = location_get_provinces($current_country);

//standard php for populating a select box
$select = '<select name = "TBD" id = "TBD" size = "1">'."\r\n";

foreach($us_countries_array as $key=>$value) {
$select .= "\t".'<option value ="'.$key.'">'.$value.'</option>'."\r\n";

$select .= '</select>';

return $select;

/*then, on the client side, test the return:
- if the select has options, display
- if not, display non-autocomplete text field


I have run preliminary tests on this and it works - - but have not tried to submit it.

The question I am now looking at now is how to make sure the name and id match what the module expects and whether I can pass validation.

Concrete question:

the current text field ids output via my template as follows:

$output .= drupal_render($form['locations'][0]['province']);


<input id="edit-locations-0-province" class="form-text form-autocomplete location_auto_province" type="text" value="" size="64" name="locations[0][province]" maxlength="64" autocomplete="OFF" rel="state"/>

where I create and use the 'rel' attribute in the jQuery for various reasons.

Thus: I will try to substitute something like this?

$select = '<select name = "locations[0][province]" id = "edit-locations-0-province" size = "1">'."\r\n";

Does this make sense?

if so, then I will gladly post the php and jQuery snippets.

Goals - -

1) avoid complex client-side tricks

2) avoid validation errors by offering only options that are valid WRT the selected country

3) simple and hard-to-mess-up UI

Thoughts from anyone?



aaronbauman’s picture

new17.13 KB

This patch addresses the issue raised in the title.
This patch also addresses some bugs raised in comments #12, 17, 19 that provinces only reflect the default country setting.
Further questions raised within this issue, e.g. "Also how can you add new provinces?", should be addressed in a new issue.

newtonpage raises quite a host of topics in comments #27 and 28, those of which relate to the original intent of this issue are addressed by this patch. I confess I have not spent the time to grasp the full extent of the content of those comments. Please feel free to retool this patch and resubmit if anyone would like to further develop this patch. Please address those concerns only as they are relevant to this issue. Further issues, UI improvements, or more fundamental changes to the system should be raised in new issue(s).



  • This patch maintains full backwards compatibility for existing installations. None of the changes in this patch will affect existing implementations adversely.

Admin notes:

  • Admins can now select whether State/Province fields should use "autocomplete" (default) or "select" widget in the "Collection Settings" fieldset of the location administration form (applies to CCK and node_ and user_location)
  • If selected, "select" widget replaces the default autocomplete on the user-facing location form

User-facing notes:

  • the select widget is initialized with the appropriate options for the default country
  • If "country" is being collected, the select widget is updated with the appropriate options each time the user changes the country field

Developer notes:

  • Implemented javascript menu callback location/fetch_provinces to retrieve json'ified list of provinces for the selected country
  • Updated location_invoke_locationapi: for $op = 'field_expand', $a4 now expects an array of field-specific settings in the same format returned for $op = 'default', e.g.
    array('collect' => 1, 'default' => 'us', 'widget' => 'select', 'nodiff' => FALSE)
  • State/Province options are initialized in funciton _location_expand_location in order to maintain state across form POSTs
  • Implemented function location_field_widgets to encourage further extensibility
  • Extended javascript library (location_autocomplete.js) to support rebuilding "select" widget on country change.
aaronbauman’s picture

Version:6.x-3.1-rc1» 6.x-3.x-dev
Category:support» feature

Moving back to HEAD.
I'm torn between calling this a feature request or bug report.
Since the latest patch doesn't address any of the javascript-based usability concerns, I'll leave it as a feature request.

Again, if you need support relating to this issue, please open a new issue or go to the forums / irc.

newtonpage’s picture

I apologize to all if I posted comments #27 and #28 within the wrong thread - - by way of explanation, I began with a concrete question but then segued into proposing a solution for my particular requirements - - which are (simply stated): to present the user with a dynamically populated states/provinces select widget keyed to country.

As a note, I have solved my problem and it works well - - and while the referenced patch addresses some of my issues, there are enough things I need that are not addressed that I have implemented a solution that does not require patching.

Note that one reason I needed this is that this site is international and the node form of interest requires correct entry of both country and state/province - - this is, of course, not unusual - - but in our case, we were failing validation under the following (common) user-input cases:

1) users in the US could (and often did) input misspelled/malformed states in spite of the autocomplete text field;
2) non-US users had the same error-possibility as above but were also presented with the US-based states in the autocomplete;
3) further, for some countries, users were entering provinces that they felt were correct but which did not match the DB - - thus, triggering validation errors that they could not understand.

While failing validation is not disaster, it did present challenges in the error-case UI since this is a multi-stage form. Thus, avoiding easy-to-create errors is a priority. In essence, this required a "guided-path" UI that forecloses the possibility of incorrect input (short of hacking the form, an error cases trapped by standard validation provided by the location module).

For those who need something like this (to present a dynamic states/province select widget keyed to country), I am happy to post the code. In my case, I used code in a template for this form, a small js file that uses jQuery and small module for ajax callback. It is not complex and works quite well.

If posting this solution is desirable, where would the issue maintainers prefer I post this? Sorry for my ignorance, but I honestly do not know.



Summit’s picture

+1 to post your solution!
Greetings, Martijn

newtonpage’s picture

I am happy to but do not want to "clog-up" this thread - - where should I post? as a reply to this comment?

Summit’s picture

I think so, it has to do with the dropdown, so no clogging up, right?
greetings, Martijn

newtonpage’s picture

I suspect the moderators may yell at me for this but here goes:

Here is what I did.


- - country default = US;
- - state select box on default contains the US states;
- - location elements are non-CCK;
- - when the country select box changes, the state / province select box is auto-filled when with the provinces supplied by the location module.

In my template that renders this form, I did this:

I create the select box and populate it with the US states - - AND also render the state text fields BUT hide that field in the CSS (I used display: none;).


//use the location module function to fetch the US states:
$us_countries_array = location_get_provinces();

//create a select box variable
$select = '<select name = "state" id = "node-form-location-state-select"" size = "1">'."\r\n";
//create the first option with value 0
$select .= "\t".'<option value = 0>Please Select State</option>'."\r\n";

//populate the select options from the array
foreach($us_countries_array as $key=>$value) {
$select .= "\t".'<option value ="'.$key.'">'.$value.'</option>'."\r\n";

//close the select element
$select .= '</select>';

//output the element
$output .= $select;

//more code specific to my site such as a throbber and error message

//then output the 'real' postal_code text box

$output .= drupal_render($form['locations'][0]['postal_code']);

Note again that the text box is hidden via CSS.

Then, in a jQuery file (I created one to go with a module that controls these elements), I did this:

//this detects the change in country select box
$("#edit-locations-0-country").change( function () {

//get the  current select value
  var newCountry = $("#edit-locations-0-country :selected").val();

//I used getJSON, but other JQuery ajax will work as well
//note that I append the new county in the $_GET array
//this ajax call references the menu callback in the module I created - - see the next snippet
    function(j) {
//when the JSON returns, fadeOut the target element, empty the options, pass in the new options and fade in
//note that in other sites, additional logic may be required  

Then in a module:

//create the callback menu item
function YOUR-MODULE_menu () {

$items['update/state/select'] = array(
'title' => 'Swap the Select Box',
'page callback' => 'update_state_select',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,

return $items;

//This is the referenced callback
function update_state_select() {

//retrieve the current country from the $_GET array
        $current_country = check_plain(trim($_GET['country']));

//get the provinces of the country and store in an array variable
$countries_array = location_get_provinces($current_country);

//you may wish to have site specific logic here for error cases

//note also that I probably overuse check_plain, but caution is good

//init a variable for the text in the first option
$insert = "";

//init the return variable
       $options = "";

//change the text for the first element, depending on if it is the US
if ($current_country === "us") {
$insert = "Please Select State";
else {
$insert = "Please Select Province";

$options = "\t".'<option value = 0>'.check_plain($insert).'</option>'."\r\n";

foreach($countries_array as $key=>$value) {
$options .= "\t".'<option value ="'.$key.'">'.check_plain($value).'</option>'."\r\n";

'status' => TRUE,
'data' => $options

//note that additional logic may be required for specific sites
//note also that an error condition should probably be trapped here

Next, I discovered that the location module wants the submission for the province field from the text widget only. so, I write the currently selected option text to the hidden text field that was output by the template (the one that I hid with the CSS).

So, after the json object is returned, I do this:

   //make sure the state select box goes to the initial value ("Please Select Province");
   $("#node-form-location-state-select :selected").val("0");
   //empty the text box in case something was already there.

Finally, I detect when a change-of-state occurs in the newly-populated state / province select box and write it the value to the hidden text field:

//detect the change-in-state in the select box
$("#node-form-location-state-select").change( function () {
  //just to be cautious, make sure it is clean
  //this code could be cleaned up a bit
  var currentSelect = Drupal.checkPlain(jQuery.trim($("#node-form-location-state-select :selected").text()));
   //write this value to the hidden text field

//other UI control logic specific to the site


Note that there are a few supported countries with no provinces (Vatican, for example, as well as a few in the Caribbean).

Since this case will yield an empty array, I trap this in the module-based callback by returning a text string rather than an array. (This logic is not shown in the snippets but is obvious.) The javascript detects this and hides the select box and inserts the phrase. In my case, I used: "This country has no provinces". Other techniques may suit you better.

So, in this case, since the location validator accepts an empty field for these countries, I make certain the hidden text field is empty.

Net-net, this works nicely. Some may view this as a hack, but in my view, it is, rather, a workaround for an excellent module that provides lots of other functionality. Also, in my opinion, it really only requires a few lines of code.

Note that I use a custom throbber while awaiting the json return (which the jQuery "shows and hides" as appropriate) and have other UI features that I have excised from these snippets.

If this were to be generalized and integrated into the module, it could be done in similar fashion to five-star where the admin pages offer the ability to use a js - ajax callback - - and this can be either the pre-canned one or one you supply. The js could be easily rolled in - - but does require at least jQuery 1.2 (I use 1.3 here). But I suspect that this may not be at the top of list for new features.

Questions and critiques welcome.


aaronbauman’s picture

There's nothing wrong with posting another solution - that's what this forum is all about.
However, it's very difficult for others to test your solution without a proper patch (see http://drupal.org/patch/create for an explanation).

After reviewing the code you posted I think we're both working towards a similar solution.
I think the best pieces of both could be combined to reach an optimal solution to this issue.

I'll take a stab at rolling a combined patch as soon as I can if no one beats me to it.

newtonpage’s picture

hello aaron

thx for the reply - - sorry for my long-ish reply here - - net-net I would be happy to help in anyway I can.

As for patching, I am quite inexpert at rolling patches. But . . . I promise to work on this as I want to be useful contributor here.

I suppose that (assuming that I "cure" my patching experience), a patch would 1) create a menu item; 2) create a new callback for this item. I assume this would go into the location module and this seems simple enough.

But in my solution, I assume: 1) that there is "target" select element into which the json returned data is placed. If there is a default country (as in my case), the theme layer populates this select with the default country's provinces /states. If there is no default country, there must be a blank target - - and again, in my case, I made that target a select element. But this may not suit everyone as it assumes my theme layer deals with this.

I looked at creating the select element in the location module but, to honest, I was afraid I would break something - - especially since I had to "workaround" the fact that the module (seemed to) require input from a text element, rather than a select element. But it appears to me that a patch would have to modify (at least): 1) location_settings() (to offer the option of a populated select box); 2) location_locationapi() (case = "field_expand" / case = "province") (where there would have to a logic branch to bypass the existing code in the event that a select is chosen - - and wherein it returns a element with the options supplied by location_get_provinces($default_country).

Again, to be honest, I was afraid of breaking something but - - agin - - I will help in any way I can.

BTW - - in the post that follows is the result of our researching what "provinces" are called in each supported country.


newtonpage’s picture

This follows up previous comments #35 and #37.

Note : aaron - - I include this if the event that it would be useful - - and again, if I can assist in a patch, I am happy to do so.

I am not certain if this would like to be rolled in the patch discussed in comment #36, but here it is.

In our application, it is desirable to make certain that a "province" was correctly named (and we are looking at the translation aspect, as well but only support English at the moment).

So, if, for example, the country is Slovakia, they call their provinces "Prefectures", whereas, the Cyman Islands have "Districts".

Further, if there are no provinces, we need to display that we cannot find them - - for example, the Vatican may be selected as a country but has nothing like a province.

The implementation is rather simple but detailed:

In the module callback, we first test if the country has provinces in the db - - if not, we return -1 in the JSON. This was developed by trial and error. We took the approach of testing with a case statement but may change this.

$countries_array = location_get_provinces($current_country);
if (count($countries_array) == 0 ) {
switch ($current_country) {
  case "ax": case "ai": case "aq": case "gu": case "im": case "an": case "nu": case "sg":  case "sj": case "va":
  case  "aw": case "bv": case "gp": case "mq": case "re": case "vg": case "cx": case "fk": case "fo": case "gf":
  case "gi": case "gg": case "je": case "lb": case "mk": case "yt": case "me": case "ne": case "nf": case "ps":
  case "pn": case "pr": case "rs": case "gs": case "eh":
   $options = -1;
  $options = count($countries_array);

Then if the array in non-empty, we do this:

else {
//create a suffix
$insert_prefix = "Please Select ";
//call a function to get the proper name (see the next code block)
$insert_country_division = select_section($current_country);
//concatenate the response with the suffix
$insert_phrase = $insert_prefix.$insert_country_division;

//make sure the first option has this phrase as the option text with value = 0
$options = "\t".'<option value = 0>'.check_plain($insert_phrase).'</option>'."\r\n";

foreach($countries_array as $key=>$value) {
   $options .= "\t".'<option value ="'.$key.'">'.check_plain($value).'</option>'."\r\n";

//$options is the returned within the JSON object

The function that is called above to create is the "insert" phrase (named select_section() ) is as follows:

function select_section($which) {
$insert_division ="";
switch($which) {
  case "af": case "dz": case "ao": case "ar": case "am": case "by": case "be": case "ba": case "bg":
  case "bi": case "kh": case "ca": case "cd": case "cr": case "cu": case "do": case "ec": case "gq": case "et":
  case "fj": case "fi": case "ga": case "id": case "ir": case "kz": case "ke": case "kg": case "la": case "mg":
  case "mv": case "mn": case "mz": case "nl": case "nc": case "kp": case "pk": case "pa": case "pg": case "pl":
  case "ru": case "rw": case "st": case "rs": case "cs": case "sl": case "sb": case "za": case "kr": case "es":
  case "lk": case "tw": case "tj": case "th": case "to": case "tr": case "tm": case "ua": case "uz": case "vu":
  case "vn": case "eh": case "zm": case "zw": case "tw":
   $insert_division = "Province";
  case "au": case "at": case "br": case "de": case "in": case "my": case "mx": case "mm": case "ng": case "sd":
  case "us": case "ve": case "pw":
   $insert_division = "State";
  case "gl": case "mc": case "pr": case "qa": case "sm":
   $insert_division = "Municipality";
   case "al": case "hr": case "ee": case "hu": case "ie": case "lv": case "lr": case "lt": case "no": case "ro":
   case "se": case "uk":
    $insert_division = "County";
  case "as": case "bs": case "bz": case "bt": case "bw": case "vg": case "bn": case "cy": case "tl": case "tf":
  case "gi": case "hk": case "il": case "ki": case "ls": case "ly": case "lu": case "mw": case "mu": case "md":
  case "nr": case "pt": case "sh": case "ws": case "sr": case "sz": case "tc": case "tv": case "vi": case "ug":
  case "wf":
   $insert_division = "District";
  case "ad": case "ag": case "bb": case "bm": case "dm": case "gd": case "gg": case "jm": case "je": case "ms":
  case "kn": case "vc":
   $insert_division = "Parish";
  case "cv":
   $insert_division = "Municipality";
  case "az":
   $insert_division = "Rayon";
  case "bh": case "eg": case "jo": case "kw": case "lb": case "sy": case "ye": case "tn":
   $insert_division = "Governorate";
  case "bf": case "cm": case "td": case "cl": case "cz": case "dk": case "dj": case "er": case "fr": case "ge":
  case "gh": case "gn": case "gw": case "gy": case "is": case "iq": case "it": case "ci": case "jp": case "mo":
  case "mk": case "ml": case "mt": case "mr": case "ma": case "na": case "np": case "nz": case "om":
  case "ps": case "pe": case "ph": case "sn": case "sc": case "sk": case "si": case "so": case "tz": case "tg":
   $insert_division = "Region";
  case "cf":
   $insert_division = "Prefecture";
  case "ck":
   $insert_division = "Council";
  case "bj": case "bo": case "co": case "cg": case "sv": case "gt": case "ht": case "hn": case "ni": case "py":
  case "uy":
   $insert_division = "Department";
  case "gf": case "li": case "yt": case "pm":
   $insert_division = "Commune";
  case "ch": case "cn":
   $insert_division = "Canton";
  case "mh": case "tk": case "um":
  $insert_division = "Atoll";
  case "gr":
   $insert_division = "Periphery";
  case "sa": case "ae": case "ae":
   $insert_division = "Emirate";
  case "gs": case "km": case "hm": case "io": case "fm": case "mp":
   $insert_division = "Island";
  case "tt":
   $insert_division = "Corporation";
  case "cc":
   $insert_division = "Island (Atoll)";
  case "ky":
   $insert_division = "Section";
  case "bd": case "gm":
   $insert_division = "Division";
  case "pf":
   $insert_division = "Sub-Division";
  case "lc":
   $insert_division = "Quarter";
return $insert_division;

If this format is not useful, I can supply the raw data.

Finally, in the jQuery that supports this form, we split the first option text and extract the proper phase for form announce section.

Thus, for the Cyman Islands, we output "Please Select District" followed by the dropdown with the districts.

aaronbauman’s picture

newtonpage, re #38:
this is great work - looks like you did a lot of research, so thanks for sharing.

I agree that the switch/case is unwieldy. Probably the best way to go would be either a mapping table with this data, or some kind of solution involving Drupal's translation system (I'm not very familiar with i18n support, so I don't know how feasible that would be).

Either way, this discussion is tangential enough to merit its own issue.
Let's try to keep the focus of this issue on the input type of the field.

newtonpage’s picture

I understand and appreciate the kind response - - as a note, I posted #38 in the event that something like this may be included in a patch since this code is included in the callback in my current solution. The switch/case structure is clunky but was the shortest path for me at the time. There are certainly many better ways to do it.

looking forward to helping with this issue going forward.


aaronbauman’s picture

new17.64 KB

OK, I've rerolled the patch to take into account concerns about the handful of countries with no provinces.
After reviewing the comments in this thread, I am fairly certain that all concerns relevant to the original issue have been addressed.

This patch is almost the same as comment #29,
with the following change:
if a country is selected that doesn't have any provinces,
the State/Province <select> element is truncated to a single value:
<option value="">n/a</option>

This hopefully eliminates any user confusion about whether to leave the default "Please Select" value, or to choose "NOT LISTED".

This patch does not address #636464: When State/Province is required, cannot validate for countries without States/Provinces

sleestaklightning’s picture

new35.43 KB

Either this isn't working properly, or I made a slight mistake when I manually applied the patch. If that's the case, perhaps someone can help me figure out where that was. I was able to toggle the collection widget between autocomplete and dropdown, but the collection form isn't updating the available provinces when I change the country. In the screenshot, I've set the country to Argentina. It's still showing the US provinces, and there's a "()" between "NOT LISTED" and "Alabama", which leads me to suspect I may have broken some syntax. In a view I've created, nothing has changed since I applied the patch, although I've tried removed the provinces filter, saving, and adding it again, as well as clearing both Location caches. The exposed filter continues to display as an autocomplete widget, and only loads US states. When I un-set my default country in the Location settings, the widget fails to load any states/provinces at all.


rubymuse’s picture

I'm seeing the same exact behavior, and I didn't manually apply the patch. (I used 'patch' -- that's not manual, is it?)

rubymuse’s picture

I think I have this working after doing the following:
- location_autocomplete.js, line 96 (function location_update_provinces) - needed to remove trailing comma after the last property in the object (causes IE7 to throw an error)
- Several 'console.log' calls needed to be commented out.

I say I "think" it's working because before making these changes I was able to get it to work when I had firebug turned on, so I'm not entirely confident the behavior is consistent. But so far it appears to be.

Note that the top of the list still shows the following:
Please select

sleestaklightning’s picture

rubymuse: Can you post an updated patch?

Also, does this work with all geocodable countries? There was a patch to google.inc which enabled the module to map every location that Google can (http://drupal.org/node/584014), but none of the countries for which that added support (France, etc) are working with this dropdown selection patch. The provinces populate and can be selected, but no results are returned.

obiwankaynobi’s picture

subscribing :)

hinikato’s picture

This patch is fixed version of patch by aaronbauman and should resolve the problems raised in comments #42, #43 and #44.

cerup’s picture

Component:User interface» Code
Assigned:Unassigned» hinikato
Status:Needs review» Needs work

Which patch hinikato? You didn't attach a patch.

hinikato’s picture

Sorry, here it is ;)

hinikato’s picture

Issue reporting system did not accept # char in the patch file name. This is fixed version of the file with accepted file name.

cerup’s picture

hinikato: which version is this patch against? I was able to patch part of 6x-3.0 but it didn't appear to patch the whole thing since I don't get a dropdown and still get autocomplete. Is this what the patch is for? If you can provide more information, that would help.

sleestaklightning’s picture


what version is this your patch against? i reverted to the latest dev version (12/16), so my baseline for location.module is:

location.module,v 2009/12/16 21:38:06 bdragon Exp $

do i need to go back to an older version? or can you update the patch to work with the latest dev release?


hinikato’s picture

This patch is for 6.x-3.1-rc1 version. See for version number in location.info file.

This is example of location.info file for 6.x-3.1-rc1 version of the location module:

; $Id: location.info,v 1.3 2008/07/24 19:44:00 bdragon Exp $
name = Location
package = Location
description = The location module allows you to associate a geographic location with content and users. Users can do proximity searches by postal code.  This is useful for organizing communities that have a geographic presence.
core = 6.x

; Information added by drupal.org packaging script on 2009-03-03
version = "6.x-3.1-rc1"
core = "6.x"
project = "location"
datestamp = "1236112547"

This version can be found on the CVS repository (http://drupal.org/node/321)

hinikato’s picture

I have found a small bug in the previous patch: when "State/Province" item is missing, the module will show the error message. This patch fixes this situation.

cerup’s picture

Thanks hinikato.

I applied the patch the rc1. I'm getting an error when I change the Country:

'Error in network connection. Please reload the page and try again (1).'

hinikato’s picture

cerup, please, use the last patch, that I provided.
If error will still occur, please describe your conditions (which country do you select when error occur and other details). Video with bug will be very helpful ;)

cerup’s picture

I tried with the latest patch (I tried with both actually).

When I change the 'Country' field and it attempts to load the States/Provinces it gives an alert 'Error in network connection. Please reload the page and try again (1).'

For example, if I change 'United States' to 'Australia' (or any other country) it'll present the above alert as if it's not finding the states from that country. If I change it back to the default country, I also get the error. So essentially changing the Country field to anything presents the alert error.

hinikato’s picture

cerup, which browser do you use?

I need a dump of some variables to detect the problem. Please change location_update_provinces(countryItem, provinceItem) function in location_autocomplete.js file to this one:

// Invoke the ajax request to fetch provinces for the specified country
function location_update_provinces(countryItem, provinceItem) {
  if (!countryItem.val().length) {
  var country = countryItem.val();
  if (countryItem.val() == 'xx') {
    locationFillProvinceList(provinceItem, country);
  else {
    return $.ajax({
      url : Drupal.settings.basePath + Drupal.settings.location_fetch_provinces_url + '/' + country,
      data : { input_id : provinceItem.attr('id'), country : country },
      dataType : 'json',
      success : location_update_provinces_callback,
      error : function(XMLHttpRequest, textStatus, errorThrown) {window.prompt('Copy value bellow and paste it where you need', XMLHttpRequest.responseText);}

after that try to change country and paste here result.
cerup’s picture

I appreciate the quick response and helpfulness thus far hinikato

I'm testing on both firefox and IE8. Both have the same results.

Here's the results:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://cdn.gigya.com/JS/gigya.js?services=socialize" type="text/javascript"></script>
<title>Page not found | vps1</title>
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/views/css/views.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/node/node.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/system/defaults.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/system/system.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/system/system-menus.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/modules/user/user.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/cck/theme/content-module.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/filefield/filefield.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/fivestar/css/fivestar.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/default/files/fivestar/basic/basic.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/cck/modules/fieldgroup/fieldgroup.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/popups/popups.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/modules/popups/skins/basic/basic.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/themes/pixture_reloaded/layout.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/themes/pixture_reloaded/style.css?U" />
<link type="text/css" rel="stylesheet" media="all" href="/sites/all/themes/pixture_reloaded/sf/css/superfish.css?U" />
<!--[if IE]>     <link type="text/css" rel="stylesheet" media="all" href="/sites/all/themes/pixture_reloaded/ie.css" >   <![endif]-->
<script type="text/javascript" src="/misc/jquery.js?U"></script>
<script type="text/javascript" src="/misc/drupal.js?U"></script>
<script type="text/javascript" src="/sites/all/modules/fivestar/js/fivestar.js?U"></script>
<script type="text/javascript" src="/sites/all/modules/gigya/gigya.js?U"></script>
<script type="text/javascript" src="/sites/all/modules/gigya/gigya.behaviors.js?U"></script>
<script type="text/javascript" src="/misc/jquery.form.js?U"></script>
<script type="text/javascript" src="/sites/all/modules/popups/popups.js?U"></script>
<script type="text/javascript" src="/sites/all/themes/pixture_reloaded/sf/js/superfish.js?U"></script>
<script type="text/javascript"> <!--//--><![CDATA[//><!-- jQuery.extend(Drupal.settings, { "basePath": "/", "fivestar": { "titleUser": "Your rating: ", "titleAverage": "Average: ", "feedbackSavingVote": "Saving your vote...", "feedbackVoteSaved": "Your vote has been saved.", "feedbackDeletingVote": "Deleting your vote...", "feedbackVoteDeleted": "Your vote has been deleted." }, "gigya": { "conf": { "APIKey": "2_QM_ZwDj8QGMv7dujfGQienzYehOs_LkNzte1ghS53UaJE99QthyDD1vOcLEwdWK-", "enabledProviders": "facebook, myspace, twitter, google, yahoo, aol" } }, "popups": { "originalPath": "location/fetch_provinces/vg", "defaultTargetSelector": "div.left-corner \x3e div.clear-block:last", "modulePath": "sites/all/modules/popups", "autoCloseFinalMessage": 1 } }); //--><!]]> </script>
<body id="pixture-reloaded" class="not-front logged-in page-location no-sidebars page-location-fetch-provinces-vg section-location no-logo">
<div id="skip-to-content"> <a href="#main-content">Skip to main content</a> </div>
<div id="header-menu">
  <div id="head-elements">
    <div id="branding"> </div>
    <!-- /#branding -->
  <!-- /#head-elements -->
<!--/#header-menu -->
<div id="header"></div>
<!--/#header -->
<div id="page" style="width: 1000px;">
  <div id="main" class="clear-block no-header-blocks">
    <div id="content">
      <div id="content-inner">
        <div id="content-header" class="clearfix"> <a name="main-content" id="main-content"></a>
          <h1 class="title">Page not found</h1>
        <!-- /#content-header -->
        <div id="content-area"> The requested page could not be found. </div>
    <!-- /#content-inner, /#content -->
  <!-- #main -->
  <div id="footer" class="region region-footer">
    <div id="footer-message"> </div>
    <!-- /#footer-message -->
  <!-- /#footer -->
<!--/#page -->
<!-- gigya-6.x-1.0-beta10 minor version:3 -->
hinikato’s picture

You got 404 not found error. This means that url in function location_update_provinces() is invalid.

I think your problem in cache. Please try to clear cache in admin/settings/performance, clicking on the "Clear cached data" button.

cerup’s picture

You're right! I should have known. Mistake 101 - always try clearing the cache! :D

Thanks again and great work on the patch. I hope they commit this!

jpshayes’s picture


hinikato’s picture

I have found that in case of using autocomplete field, the JavaScript error will occur. I have fixed the invalid variable reference and provide the new patch.
This one should fix the problem completely (I hope).

superduperdan’s picture

Sorry for the dumb question but do I ONLY need to install the last patch from this post or all of them in order from top to bottom? Great work on getting this done everyone!

hinikato’s picture

superduperdan, you need to install 6.x-3.1-rc1 and apply the last patch which I provided from comment #63.

hinikato’s picture

hinikato’s picture

monotaga’s picture


RickyS’s picture

Category:feature» bug
Priority:Critical» Normal

I have started testing the patch on comment 63 and found one bug.

When I update a node, it saves different province item from what I chose. It happens when I choose "Japan" from the dropdown menu as a country. For example, when I choose "Tokyo" as province entry, it saves "Iwate". "Saitama" becomes "Hokkaido". It seems like something to do with the numeric array keys in location/supported/location.jp.inc since Tokyo's array key is 13 and Iwate's array key is 03. Saitama's array key is 11 and Hokkaido's array key is 01

Thank you for implementing a great patch. This is exactly what I wanted!

RickyS’s picture

Category:bug» feature
Priority:Normal» Critical
jpshayes’s picture

Priority:Critical» Normal

Someone correct me if I am wrong, but feature request should never be marked "critical"

mrtoner’s picture

@JPSH: you are correct. And feature requests should always go against dev. Bugs on an attached patch might get marked "needs work" but never change the category.

(Sorry I haven't been around since #10, but I get easily sidetracked.)

YesCT’s picture

RickyS in #69 are you saying that the patch fixes your problem, or that it almost does and there is still a small error even with the patch?

I think this issue needs someone who has been following it to re-read it from the beginning and post a summary to make it easier for a maintainer to get a quick understanding of what the problem is, and whether there is a patch that fixes it (and if the patch might cause any other problems).

jpshayes’s picture

I am having the same problem as RickyS is having in #63 only I am having the problem on user location. I have not tried it on node locations.

YesCT’s picture

marked #768832: Provinces & Cities as a drop down in views as a duplicate of this issue

jday’s picture

how about adding the state drop down option to the exposed view filter?

marcus178’s picture

I'm using 3.1-rc1 and have applied the patch but I get the following errors

warning: array_filter() [function.array-filter]: The first argument should be an array in /sites/all/modules/location/location/contrib/location_cck/location_cck.module on line 385.
warning: array_keys() [function.array-keys]: The first argument should be an array in /sites/all/modules/location/location/contrib/location_cck/location_cck.module on line 385.
warning: Invalid argument supplied for foreach() in /sites/all/modules/location/location/location.module on line 1541.
khan2ims’s picture

I am also getting the same error as mentioned by Marcus.

khan2ims’s picture

Please try following this post http://drupal.org/node/330066

YesCT’s picture

using [#nnnnnn] (cool way to link to another issue

#330066: Add option to have the views province filter as a select field

nimek’s picture

Let someone apply the path from #63 and post patched version or submit as another dev release.

daneyuleb’s picture

After applying patch at #63, the province drop-downs appear fine in the GUI, but when Editing registration, receive: "An illegal choice has been detected. Please contact the site administrator.". Log shows "Illegal choice FL in State/Province element." type errors ocurring.

Assigning: [#validated]="true" fixes the issue for me, but that's a little insecure (though, in a drop-down list of values I supply, not sure how insecure it really is).

Just throwing this out there to see if anyone else has run into it with this patch. If no one else is experiencing similar, I'll consider it something peculiar to my setup.

clashar’s picture

actually would be better to have both dropdown + autocmoplete field for cities, provinces

goron’s picture


I've just gotten the same error. I think it's related to the "force default" option for the country field. It stops happening when I switch that to "require"...

Anyone have any idea why that's happening?

raj1111’s picture

I have a few issues with the address module. I want show value of state and State / Province with full name

bcmiller0’s picture

Modified patch from #63 comment above to make it apply cleanly to 6.x-3.1 as #63 only applied to 6.x-3.1-rc1 .

YesCT’s picture

Status:Needs work» Needs review
recrit’s picture

patch needs some small fixes:
line 275 of original module file: for loop end bracket } should come after the following code

       // If "State/Province" is using the select widget, update the element's options
       if ($field == 'province' && $fsettings[$field]['widget'] == 'select') {
         $country = $element['#value']['country'];
         if (empty($country)) {
           $country = $fdefaults['country'];
         $provinces = location_get_provinces($country);
         // The submit handler expects to find the full province name, not the abbreviation.
         // The select options should reflect this expectation.
         $element[$field]['#options'] = array_merge(
           array('' => t('Please select'), 'xx' => t('NOT LISTED')),

Also, street is not getting the required set correctly. After patch it is still $a4 == 2 and should be

'#required'       => ($settings['collect'] == 2),
Summit’s picture

Hi, Could you build a new patch with your modifications please?
Thanks a lot in advance!
Greetings, Martijn

recrit’s picture

#88 rolled into patch

khosman’s picture

Applying the patch listed in #90 brings me the following:

Fatal error: Call to undefined function location_load_locations() in C:\wamp\www\sites\all\modules\location\location_node.module on line 38

Is this possibly caused by something I did whilst installing the patch - or something bizarro with the patch itself?

recrit’s picture

#90 was just some code clean up... did you previously try #86 with no issues?

khosman’s picture

No - my mistake was to apply 90 directly to the mod.

However... when I apply 86 to a clean copy of the mod (specifically version 3.1), I get:

Fatal error: Call to undefined function location_load_locations() in C:\wamp\www\sites\all\modules\location\location_node.module on line 38


The "patching process" seems to go smoothly, printing out
patching file location. module
patching file locationautocomplete.js

I get 0 errors there - but the site has been replaced by the error listed above.

bander2’s picture

I applied the patch 86 to 3.1. The patch applied fine, but I get error message:

"warning: Invalid argument supplied for foreach() in D:\www_acc_test\includes\form.inc on line 1430."

on any page with the location form and the state/province drop down is blank.

Patch 90 seems to work better. The State/Province drop down is populated with US states (US being the default). But when I change countries, I get an alert box with:

"Error in network connection. Please reload the page and try again (1)."

and the State/Province drop down says "Loading..."

aaronbauman’s picture

#94: the patch adds a new menu callback.
you need to clear your site cache in order to rebuild menus. ( admin/settings/performance )

dunno what the form.inc error is about.

DamienMcKenna’s picture

Status:Needs review» Reviewed & tested by the community

The patch in #90 works fine for me, though I wish it defaulted to use the drop-down rather than the autocomplete :p

+1 for inclusion in the next release.

larskleiner’s picture

I'm using 6.x-3.x-dev and had problems applying the #90 patch. Attached a re-rolled version I got to work with 6.x-3.x-dev.

Thanks for the great patch, it's exactly the functionality I need. Hope it will find its way into the next release.

DamienMcKenna’s picture

Status:Reviewed & tested by the community» Needs work

I found a problem with the patch in #90 with countries that use numeric province short names, e.g. China. the file location.cn.inc includes the following:

function location_province_list_cn() {
  return array(
    '11' => "Beijing",
    '12' => "Tianjin",
    '13' => "Hebei",
    '14' => "Shanxi",
    '15' => "Nei Mongol",

When editing a location and the country is changed to China it loads the correct values into the form:
<select name="field_address[0][province]" class="form-select error location_dropdown_province" id="edit-field-address-0-province"><option value="">Please Select</option><option value="xx">NOT LISTED</option><option value="11" class="location_dropdown_join_&amp;country=cn,cn">Beijing</option><option value="12" class="location_dropdown_join_&amp;country=cn,cn">Tianjin</option><option value="13" class="location_dropdown_join_&amp;country=cn,cn">Hebei</option><option value="14" class="location_dropdown_join_&amp;country=cn,cn">Shanxi</option><option value="15" class="location_dropdown_join_&amp;country=cn,cn">Nei Mongol</option><option value="21" class="location_dropdown_join_&amp;country=cn,cn">Liaoning</option><option value="22" class="location_dropdown_join_&amp;country=cn,cn">Jilin</option><option value="23" class="location_dropdown_join_&amp;country=cn,cn">Heilongjiang</option><option value="31" class="location_dropdown_join_&amp;country=cn,cn">Shanghai</option><option value="32" class="location_dropdown_join_&amp;country=cn,cn">Jiangsu</option><option value="33" class="location_dropdown_join_&amp;country=cn,cn">Zhejiang</option><option value="34" class="location_dropdown_join_&amp;country=cn,cn">Anhui</option><option value="35" class="location_dropdown_join_&amp;country=cn,cn">Fujian</option><option value="36" class="location_dropdown_join_&amp;country=cn,cn">Jiangxi</option><option value="37" class="location_dropdown_join_&amp;country=cn,cn">Shandong</option><option value="41" class="location_dropdown_join_&amp;country=cn,cn">Henan</option><option value="42" class="location_dropdown_join_&amp;country=cn,cn">Hubei</option><option value="43" class="location_dropdown_join_&amp;country=cn,cn">Hunan</option><option value="44" class="location_dropdown_join_&amp;country=cn,cn">Guangdong</option><option value="45" class="location_dropdown_join_&amp;country=cn,cn">Guangxi</option><option value="46" class="location_dropdown_join_&amp;country=cn,cn">Hainan</option><option value="51" class="location_dropdown_join_&amp;country=cn,cn">Sichuan</option><option value="52" class="location_dropdown_join_&amp;country=cn,cn">Guizhou</option><option value="53" class="location_dropdown_join_&amp;country=cn,cn">Yunnan</option><option value="54" class="location_dropdown_join_&amp;country=cn,cn">Xizang (Tibet)</option><option value="61" class="location_dropdown_join_&amp;country=cn,cn">Shaanxi</option><option value="62" class="location_dropdown_join_&amp;country=cn,cn">Gansu</option><option value="63" class="location_dropdown_join_&amp;country=cn,cn">Qinghai</option><option value="64" class="location_dropdown_join_&amp;country=cn,cn">Ningxia</option><option value="65" class="location_dropdown_join_&amp;country=cn,cn">Xinjiang</option><option value="71" class="location_dropdown_join_&amp;country=cn,cn">Taiwan</option><option value="91" class="location_dropdown_join_&amp;country=cn,cn">Xianggang</option><option value="92" class="location_dropdown_join_&amp;country=cn,cn">Aomen</option><option value="97" class="location_dropdown_join_&amp;country=cn,cn">Chongqing</option><option value="98" class="location_dropdown_join_&amp;country=cn,cn">Gaoxiong</option><option value="99" class="location_dropdown_join_&amp;country=cn,cn">Taibei</option></select>

The problem occurs as follows:
  • If the value had been previously saved, e.g. via manual database changes or converted data, when the form is loaded the option values for the province select tag changes to an integer starting at 1 rather than the correct values, i.e. it resets the array's keys to start from 1.
  • When saving the record it is unable to match the province against the location_province_list_XX() functions so gives the error "The specified province was not found in the specified country."

In both cases the values on the form field change to:

<select name="field_address[0][province]" class="form-select location_dropdown_province" id="edit-field-address-0-province"><option value="" class="location_dropdown_join_cn">Please select</option><option value="xx" class="location_dropdown_join_cn">NOT LISTED</option><option value="0" class="location_dropdown_join_cn">Beijing</option><option value="1" class="location_dropdown_join_cn">Tianjin</option><option value="2" class="location_dropdown_join_cn">Hebei</option><option value="3" class="location_dropdown_join_cn">Shanxi</option><option value="4" class="location_dropdown_join_cn">Nei Mongol</option><option value="5" class="location_dropdown_join_cn">Liaoning</option><option value="6" class="location_dropdown_join_cn">Jilin</option><option value="7" class="location_dropdown_join_cn">Heilongjiang</option><option value="8" class="location_dropdown_join_cn">Shanghai</option><option value="9" class="location_dropdown_join_cn">Jiangsu</option><option value="10" class="location_dropdown_join_cn">Zhejiang</option><option value="11" class="location_dropdown_join_cn">Anhui</option><option value="12" class="location_dropdown_join_cn">Fujian</option><option value="13" class="location_dropdown_join_cn">Jiangxi</option><option value="14" class="location_dropdown_join_cn">Shandong</option><option value="15" class="location_dropdown_join_cn">Henan</option><option value="16" class="location_dropdown_join_cn">Hubei</option><option value="17" class="location_dropdown_join_cn">Hunan</option><option value="18" class="location_dropdown_join_cn">Guangdong</option><option value="19" class="location_dropdown_join_cn">Guangxi</option><option value="20" class="location_dropdown_join_cn">Hainan</option><option value="21" class="location_dropdown_join_cn">Sichuan</option><option value="22" class="location_dropdown_join_cn">Guizhou</option><option value="23" class="location_dropdown_join_cn">Yunnan</option><option value="24" class="location_dropdown_join_cn">Xizang (Tibet)</option><option value="25" class="location_dropdown_join_cn">Shaanxi</option><option value="26" class="location_dropdown_join_cn">Gansu</option><option value="27" class="location_dropdown_join_cn">Qinghai</option><option value="28" class="location_dropdown_join_cn">Ningxia</option><option value="29" class="location_dropdown_join_cn">Xinjiang</option><option value="30" class="location_dropdown_join_cn">Taiwan</option><option value="31" class="location_dropdown_join_cn">Xianggang</option><option value="32" class="location_dropdown_join_cn">Aomen</option><option value="33" class="location_dropdown_join_cn">Chongqing</option><option value="34" class="location_dropdown_join_cn">Gaoxiong</option><option value="35" class="location_dropdown_join_cn">Taibei</option></select>

As you can see, the values change from the correct values to an integer starting at 1.
DamienMcKenna’s picture

Found the problem! If you use the function array_merge() with numerical keys it re-stacks all of the keys starting at 0 - gotta love the consistencies in PHP. This function is used in the following lines in the patch:

+      $element[$field]['#options'] = array_merge(
+        array('' => t('Please select'), 'xx' => t('NOT LISTED')),
+        $provinces
+      );

Fixed patch on the way..
DamienMcKenna’s picture

Status:Needs work» Needs review
new18.07 KB

Here's an updated patch that replaces the array_merge() function with a simple addition.

nunami’s picture

Although it's been more than a month since the last post, is there any chance that this feature or option will be included in the next release of the location module?

monotaga’s picture

I agree w/nunami. The patch in #100 works fine for me. I'd love to see this committed.

Fidelix’s picture

Well, #100 is not working for me.

Whenever i submit a node with Dropdown, i get an "Invalid Choice detected" error.

And also, can this be used with the views filter?

clashar’s picture

#100 works well for me in CCK.
I tried submitting, also ok.

clashar’s picture

by the way is it possible to include this feature also to views location?
here is related issue : #330066: Add option to have the views province filter as a select field

ikeigenwijs’s picture


mcarbone’s picture

Status:Needs review» Needs work

I'm getting "illegal choice detected" with #100 as well. It seems to be because I have the country set to US by force default, but it's not in the $obj variable in location_locationapi().

bryancasler’s picture


zeezhao’s picture


Katrina B’s picture

Subscribing. I'm not a programmer, so this thread is difficult for me to follow completely. I'm mostly interested in seeing if/when this is available in the Location module itself.

DamienMcKenna’s picture

@mcarbone: thanks for identifying that, I'll see what I can do.

drecute’s picture


oscardax888’s picture


prabhakarsun’s picture

#100 is for which version?

Stomper’s picture

A dropdown would be great, especially since I am developing on a localhost (quite laggy) and the autocomplete is quite slow.

On a related topic, would it be possible for us to import (like taxonomy csv) our own created lists into a location drop down. In my case I have taxonomy vocabulary that contains what are technically location values (store franchises). The values are custom and location relevant.

The values are organized by state and city, so basically I'd like the workflow to be as such - User selects state, available city options are based on selected state, after selecting the city the user can select the valid (based on city relationship) store franchise (my custom values).

Is this possible?

ajayg’s picture

Status:Needs work» Needs review
new16.46 KB

Here is a rerolled patch 100 against the location dev version as of Jan 30, 2010. It doesn't have changes committed
Commit #494690 by rooby at 17:27
Location: /modules/location/location.module @ DRUPAL-6--3

#931526 by rooby, mikeytown2 - Fixed undefined index notices in template_preprocess_location().

Otherwise it is much current than the previous patch (patch 100). Please review/test.

This is important and long due patch. It creates a new widget type. If you see a particular use case is missing with new widget type (but it works fine with original widget) please still support commiting it since it is not breaking existing functionality. We can then work on another patch to fix what is missing since this is fairly large patch and sooner we can commit the better.

ajayg’s picture

No one here to test/review this long due patch? :(

Stomper’s picture

I've never worked with patches before, how do I add them and use them?

hutch’s picture

tibip’s picture

An workaround for #107 is to set Country as "Allow" and Default value to "United States" or whatever in "Collection" settings either for user locations in "User settings" or for CCK fields in content types and then hide the Country field by using hook_form_alter and #after_build for that form. For example you could set $form['#after_build'][] = 'my_alter_location_form'; in hook_form_alter and then inside function 'my_alter_location_form':

$form['locations'][0]['country']['#prefix']='<div style="display:none">';

This worked for me. I hope that helps.
dafeder’s picture

#116: Still getting illegal choice detected for this patch.

dafeder’s picture

Ah, I see... if I enable country, it stops giving the error. OK for now but should be fixed, no ideas at the moment.

alexbk66-’s picture


k1’s picture

#116 works for me only on node create. It doesn't when exposing filter by state> There is no dropdown menus on exposed filter and also lost filtering functionality.
Is there a way to make this patch work for provinces of any country? Drop down menu only lists U.S states.

HnLn’s picture


Jerome F’s picture


urbanbricks’s picture


Also, confirming error in comments #82 & #83 "An illegal choice has been detected. Please contact the site administrator."

I think it's related to the "force default" option for the country field. It stops happening when I switch that to "require"...

This temporary fix resolved the error.

LGLC’s picture

Amazing work on this patch! I've applied it by hand to 6.x-3.1 (not dev) and am having a few issues when using the select box. After having a look through the code, it seems that $location['province'] is set to the province code - and this is getting sent through to Google, which then can't geocode it properly. This is in contrast to the autocomplete box, which (if I print out $location['province'] within google.inc) has it set to the text display of the province rather than the code.

Tracing back through the code, it seems inside location_save the provinces are different for the different widgets (province code for the select box vs province name for the autocomplete). _location_geo_logic looks like it expects the province to be set to the full name and then only changes it to the province code once geocoding has occurred.

I couldn't find where the stored value of the autocomplete was different to that of the select box, or where there was a mapping from province code to name (or vice versa). I even tried changing the dropdown javascript to set the values of the option html elements to the province name rather than the province code (i.e. value rather than key), but that caused illegal selection errors.

For now I can just work around the problem by using $address .= location_province_name($location['country'], $location['province']); rather than just $address .= $location['province']; inside _google_geocode_flatten within google.inc, but that means that I can only use the dropdown and not the autocomplete. That's not really a problem at the moment, but obviously isn't a very good way of doing it!

Also, if I use the autocomplete box, when the form first loads the autocomplete doesn't work - it's only after changing the country that the javascript is triggered, causing the autocomplete to then work.

If anyone has any ideas I'd be very grateful! Looking in firebug I couldn't ever see the html that contained the (province name) text of the autocomplete selection (only the value of the input, which was just set to the province code). How does the javascript of an autocomplete change the value of a text box?


spessex’s picture

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

Newbie here so not sure if I'm asking the right question. Would this patch work on the latest version? I'd assume that this would have been ported across in the latest release but I do not have the drop-down facility?

Thank you

ajayg’s picture

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

The patch is for 6.x only. Please do not change the version number till this patch is commited or new 7.x version of patch arrives.

spessex’s picture

sorry about that. hadn't quite realised what I'd done but thanks for the feedback :-)

mototribe’s picture


djdevin’s picture

new1.42 KB

Does anyone else have a problem with tao-based themes (rubik, cube, etc)? Tao rewrites fieldset as a div with a class fieldset, so the jquery selector doesn't work. I changed the selectors from 'fieldset:first' to '.location' and it fixed the issue for me.

YesCT’s picture

I tried applying patch from #116 to 6.x-3.1 and got:

patch -p0 < 364287-location.module-province-select-in-sign-up-116.patch
patching file location.module
Hunk #3 succeeded at 455 (offset -2 lines).
Hunk #5 succeeded at 500 (offset -2 lines).
Hunk #7 succeeded at 532 (offset -2 lines).
Hunk #9 succeeded at 612 (offset -2 lines).
Hunk #11 succeeded at 666 (offset -2 lines).
Hunk #13 succeeded at 704 with fuzz 2 (offset -2 lines).
Hunk #14 FAILED at 715.
Hunk #15 succeeded at 768 (offset -8 lines).
Hunk #16 succeeded at 788 (offset -2 lines).
Hunk #17 succeeded at 1098 (offset -8 lines).
Hunk #18 succeeded at 1269 (offset -2 lines).
Hunk #19 succeeded at 1550 with fuzz 2 (offset -9 lines).
1 out of 19 hunks FAILED -- saving rejects to file location.module.rej
patching file location_autocomplete.js

cat location.module.rej
*** 653,674 ****
            else {
              $country = variable_get('site_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),
-           );
          case 'country':
            // Force default.
-           if ($a4 == 4) {
              return array(
                '#type' => 'value',
                '#value' => $obj,
--- 715,766 ----
            else {
              $country = variable_get('site_default_country', 'us');
+           switch ($settings['widget']) {
+             case 'select':
+               static $js_set;
+               if (empty($js_set)) {
+                 drupal_add_js(array(
+                   'location_fetch_provinces_url' => 'location/fetch_provinces',
+                   // TODO: Is there a javascript-y t() function to use instead?
+                   // If not, this should be standardized / modularized
+                   't_please_select' => t('Please Select'),
+                   't_not_listed' => t('NOT LISTED'),
+                   't_not_applicable' => t('n/a'),
+                 ), 'setting');
+                 $js_set = TRUE;
+               }
+               // Options are defined once during hook_element implementation
+               // @see _location_expand_location
+               // $options = array_merge(array('' => t('Please select'), 'xx' => t('NOT LISTED')), location_get_provinces($country));
+               return array(
+                 '#type'           => 'select',
+                 '#title'          => t('State/Province'),
+                 '#default_value'  => $obj,
+                 '#description'    => NULL,
+                 '#required'       => ($settings['collect'] == 2),
+                 '#attributes'     => array('class' => 'location_dropdown_province'),
+               );
+               break;
+             default:
+               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' => 'location_auto_province'),
+                 '#required' => ($settings['collect'] == 2),
+               );
+               break;
+           }

          case 'country':
            // Force default.
+           if ($settings['collect'] == 4) {
              return array(
                '#type' => 'value',
                '#value' => $obj,
YesCT’s picture

(I might try it the right way too: changing to dev, and applying it on that.) But for now, I finished the patch manually, tried it, and it worked. I selected dropdown in the content type manage fields field configuration settings.

I was trying this in order to get editablefields to work with location (in Internet Explorer / IE )
#1207506: autocomplete ajax edits but does not save with text allowed values autocomplete in IE and Chrome and initially at least, it seems to work to fix that.

rooby’s picture

I have had some time to have a little look over the code and test and it looks good. The approach seems fine.

I will give it some extensive testing and a full code review tomorrow and post a new patch.
At first glance it looks like the location_field_widgets() function might be better replaced with a new 'widget' hook_locationapi() op, and in response to the code comment about a javascript t() function there is Drupal.t(). Also, the widget selection would be better as a select instead of radios so it can fit in the table of settings nicer.

So it's too late now but I'll make those changes tomorrow and check everything out in more detail so it can get committed.

rooby’s picture

Here is what I have.

I have done a small amount of testing but it would be good if some people can do some quick re-tests for their use cases.

Changes are:
* Removed 't_not_applicable' => t('n/a'), from the options send to the javscript as it is never used and was left over from a previous version of the patch.
* Changed from using the already translated t_* options to using Drupal.t() to translate in the javascript.
* Replaced location_field_widgets() with a new location_locationapi() op 'widget'. Seeing as fields, defaults & field_expand are in there it makes sense to also have this in there.
* Changed the widget setting from radios to a select field so it better fits in the table of options.
* Changes the validation logic (almost) back to how it is in the current dev version. This is because the new validate code was the cause of the "An illegal choice has been detected. Please contact the site administrator." error when using force default country (changes to this validation aren't really relevant to this patch anyway and could have their own issue if need be).

Responses to some of the various bug reports:

Is there a way to make this patch work for provinces of any country? Drop down menu only lists U.S states.

- It does work for provinces of any country. It shows provinces of whatever country is selected.
If you are using the force country selection option you will only get provinces for the default country.

works for me only on node create. It doesn't when exposing filter by state> There is no dropdown menus on exposed filter and also lost filtering functionality.

- Views exposed filters are not handled in the same way, so they stay as autocomplete. That is not part of this patch. Views filtering still works for my testing.

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

- (When using the force default country option) - This has been fixed.

@LGLC re #128:
Google geocoding should (and does for the couple of quick tests I did) work if the state/province is an abbreviation. All the examples in the google documentation actually send abbreviations and it should work either way (as long as we are using the correct abbreviations). Can you give an example address that doesn't work?

The problem you are seeing with the autocomplete not working properly the first time after a page load - I believe that was a bug that has been fixed and is not present in the latest dev.

alexbk66-’s picture

Great job @rooby. I would be glad to test it.

Would it be possible to attached patched files though, I don't know how to apply patches yet.

Sinovchi’s picture

A manually applied the patch from #137 and tested it. It works for me.

Jerome F’s picture

@alexbk66 : applying patch is not a big deal, just read : http://drupal.org/node/707484 and http://drupal.org/patch if you're unfamilliar with it.
All the instructions you need to do it for location module are there: http://drupal.org/node/18723/git-instructions/6.x-3.x

Basically download and install git: http://git-scm.com/download

Open your terminal, and type

git clone --branch 6.x-3.x http://git.drupal.org/project/location.git
cd location

You will find a location module on your root folder
Download the patch in #137, put it in this location folder
then go back to your terminal and type:
git apply -v location-province_drop_down-364287-137.patch

And you can replace your old location module folder with this patched version to test it.
alexbk66-’s picture

Thanks @Jerome F, I installed git, applied the patch #137 and it works!
Just a thought, readme should be updated to explain where to change to widget type.

ajayg’s picture

Status:Needs review» Reviewed & tested by the community
rooby’s picture

Version:6.x-3.x-dev» 7.x-3.x-dev
Assigned:hinikato» Unassigned
Status:Reviewed & tested by the community» Patch (to be ported)

Committed to 6.x-3.x with a minor fix:

+++ b/location_autocomplete.js
@@ -3,31 +3,117 @@
+  var country = countryItem.val();
+  if (countryItem.val() == 'xx') {
+    locationFillProvinceList(provinceItem, country);
+  }

Changed to

+  var country = countryItem.val();
+  if (country == 'xx') {
+    locationFillProvinceList(provinceItem, country);
+  }


Needs porting to Drupal 7.

If anyone finds any bugs in what was committed please open new issues.
For additional functionality like support for a select field for the views exposed province filter, also open new issues.

This issue is now just for porting the current patch to drupal 7.

Powered by Dreditor.

goron’s picture

Status:Patch (to be ported)» Needs work
new12.38 KB

Here is a first attempt at a patch for D7 Location. This is for the 7.x-3.x branch, and can be applied to the latest dev release as of this posting.

This adds a dropdown widget option for the State/Province field, and implements the Location form using the native D7 AJAX framework. Note that the autocomplete widget still works using the older D6 method.

However, it has a serious bug. I'm posting here because after considerable effort I haven't been able to solve it, and I'm hoping someone will be able to help. When a Province is selected, and then the Country field changed, the form returns an error ('An illegal choice has been detected. Please contact the site administrator.')

Here's how to reproduce the error:

  1. Apply patch to latest Dev release for Location 7.x-3.x
  2. Go to the configuration page for a content type (say, article)
  3. Enable at least the country and province fields for collection, choosing 'Allow'
  4. Choose 'Dropdown' as the widget for Province/State
  5. Choose the US as the default country
  6. Go to the 'add' page (i.e. node/add/article)
  7. Choose a US state from the Province dropdown
  8. Open the Country dropdown and choose any other country
  9. The provinces should change. Choose a Ukraine province
  10. Change the country back to the US
  11. You should see the error now. Note that this doesn't happen when changing the country from the US to something else. This must be related to the US being chosen as the default.

Please let me know if you can at least point me in the right direction for fixing this bug. Thanks.

goron’s picture

Status:Needs work» Needs review

changing to 'needs review' so this might get looked at.

BeaPower’s picture


inTOOLS’s picture

For me the patch works fine. I did not need to change country though, I have only one default.

goron’s picture

Status:Needs review» Patch (to be ported)

yes, with just one country this should work fine. With more than one country, however, it doesn't work, and I haven't been able to solve the problem.

ankur’s picture

Status:Patch (to be ported)» Needs work
new13.45 KB

Here's an updated version of the patch given by goron in #144 that makes it work with multiple locations and cck locations. It doesn't answer the validation issue, though, that gives you the message that says "An illegal choice has been detected...".

ankur’s picture

So, here's what I've gathered from testing the most recent patch:

This is the process that causes an error goes as follows:

(1) Make a province selection.
(2) Change the country, triggering a rebuild of the province drop-down via AJAX
(3) Make a province selection on the updated drop-down.
(4) Change the country again.

This results in the province drop-down being returned with the error status message attached to it.

Whether you start with the U.S. as your country or change to it -- it doesn't matter. What seems to be happening, though, is that the form is being validated when the AJAX callback is made to retrieve the HTML for the updated province drop-down.

One thing I do notice, though, is that the drop-down returned when the error message is returned is for the US states. On my install, the US also happens to be the default.

goron’s picture

Thanks for improving the patch ankur.

As for the error - I think that it's related to a note that is made on the Ajax Forms docs page:

Changes to the form must only be made in the form builder function or validation will fail. The callback function must not alter the form or any other state.

The form in Location is built in a few separate functions. What makes me think this may be related is that the changes made to the form by AJAX are not made in the same function that returns the $form. As far as I can tell, that is the definition of the 'form builder function' (though I'm not sure).

That's as far as I've gotten.

puya’s picture

Hi. I get the following errors when I apply the patch on #149

patching file location.module
Hunk #1 FAILED at 238.
Hunk #2 succeeded at 270 (offset -29 lines).
Hunk #3 succeeded at 495 (offset -30 lines).
Hunk #4 succeeded at 533 (offset -32 lines).
Hunk #5 succeeded at 550 with fuzz 2 (offset -32 lines).
Hunk #6 succeeded at 602 (offset -33 lines).
Hunk #7 succeeded at 623 (offset -33 lines).
Hunk #8 succeeded at 636 (offset -33 lines).
Hunk #9 succeeded at 651 (offset -33 lines).
Hunk #10 succeeded at 668 (offset -33 lines).
Hunk #11 succeeded at 686 (offset -33 lines).
Hunk #12 succeeded at 696 (offset -33 lines).
Hunk #13 FAILED at 719.
Hunk #14 FAILED at 732.
Hunk #15 FAILED at 781.
Hunk #16 succeeded at 793 (offset -41 lines).
Hunk #17 succeeded at 1055 (offset -43 lines).
4 out of 17 hunks FAILED -- saving rejects to file location.module.rej
ankur’s picture

@goron in #151:

It looks like the patch is modifying the province drop-down in the Form API "#process" function, whereas the docs suggest this should be done in the function that does the form building.

This means that, in the case of nodes, we'll probably want to do this in some kind of implementation of hook_form_BASE_FORM_ID_alter. We'll probably want to leave the call to location_get_provinces() in function _location_process_location(), but set the updated "country" value using the form_state array() in the form_alter that intervenes in the main form builder function... if that makes sense.

ankur’s picture

Status:Needs work» Needs review
new14.87 KB

Here's another patch. It moves the rebuild logic to the form building functions in location_node and location_cck (meaning it should work for both location_node and location_cck locations). It adds the 'delta' of a location to the wrapper div's class attribute for the div that wraps the province drop-down being updated when a country selection is updated, so as to make sure the correct province drop-down is updated if there is more than one location form in the current form. It leaves the logic of the province-list generation in the function _location_process_location().

I think it handles all the errors previously mentioned, but I'd like to see some testing to make sure it doesn't cause any other unwanted side-effects.

HyperGlide’s picture


goron’s picture

Patch looks nice! Thanks for tackling that. I haven't had the chance to test, but I will soon.

orenbus’s picture


Why is this so difficult? All I want to do is have a drop down for the United States, "states", you know Al. That's all, I don't want to know or have to hack through the inner workings of this module. I just want to be able to add a drop down that allows a user to pick one of the fifty states of the United States for province/state field instead of a autocomplete field that doesn't even work and just allows user error when entering in data that will need to be queried on. Why is it so difficult to just have an option or at least switch a flag that populates a drop down of these values:


This is so dumb that people have to wade through hours and go through hours of researching this issue on the web and trying different approaches.

Someone that speaks American please help me!!!! Don't make baby jesus cry. Thanks.

djdevin’s picture

@orenbus, this is what the patch does. It adds an option on the state widget to select autocomplete or dropdown. By default it is set to autocomplete.

It is a little more complicated than just adding a dropdown, since Location also has to support international addresses. We've been using this patch in production to do what you want, so give it a try.

orenbus’s picture

@djdevin, which patch should I apply?

I'm on drupal 7 would the patch still be good for me?

orenbus’s picture

Ok I was able to install patch location_province_dropdown_d7-364287-149.patch that ankur posted up in #149

By just doing a wget and doing
git apply -v location_province_dropdown_d7-364287-149.patch

Now I have the state dropdown on the registration page hurray!

Ok now I go to create an exposed filter and it is still set to autocomplete field for province. I noticed earlier in this thread someone saying that this patch doesn't address views province/state select, is this still the case? If this patch only addresses registration and profile state selection through drop down how can I make the changes to view so that users can select the appropriate state through a exposed filter?

Thanks in advance for any link you can provide or any words of advice.

orenbus’s picture

OMG Whoever came up with autocomplete for province/state instead of drop down for this module needs to die a violent death.

Still searching for a way to allow users to pick state through a view without the gmap dissapearing soon as I make exposed filter available for province/state which is still set to autocomplete text field.

At this point I would be happy just with one search text box that would go through all my view filters and provide the filtered results.

ankur’s picture

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

Glad to see the patch is working for those who applied it. I went ahead and committed it to the 7.x-3.x branch. I'm not sure if this patch applies cleanly to the 7.x-4.x branch or if its obsolete in that branch altogether. However, we'd obviously want to see this functionality passed on to that branch as well. So, I'm changing the version of this to 7.x-4.x

KeyboardCowboy’s picture

Is there a way to change the Views exposed filter for the Province field to a select list? If anyone has an idea about this I'd love to hear it. I'll try to apply the 7.x-4.x patch above to the views hooks and post it here if I can get it to work.

KeyboardCowboy’s picture

Issue tags:+location, +views, +auto-complete

Oops, I think I screwed up the tags on the issue. Fixing...

ankur’s picture

Status:Needs review» Closed (fixed)

Since the time of this patch, the 7.x-4.x branch has been abandoned in favor of the 7.x-5.x branch.

The issue of making the state/province selection on a view a select instead of a textfield is a thornier issue that should have it's own ticket. If there's still interest in that, please open a separate ticket, or bump an existing one that specifically addresses that issue.

bryancasler’s picture

jeff h’s picture

Category:feature» bug
Priority:Normal» Major
Status:Closed (fixed)» Active

I'm sorry, is this issue rectified in the latest 7.x-3.x-dev or not? It doesn't work for me, using the latest of everything available as at 14 March 2012.

I have marked the priority major, since I'm using the only public release for D7, and since it is very broken user-facing functionality i.e. if you choose a country from the select list, an ajax call appears to happen, but nothing changes in the State/Province drop down.


clint.beacock’s picture

As with Jeff, I'm also using the latest 7.x-3.x-dev and seeing the same things. If I save with a new country selected, and set the province to 'not listed', when I reload the page, the proper provinces are shown, but that's obviously not the intended functionalitly.

I should mention that I'm using the User Locations module, and taking in the location information on registration of new users. When an anonymous user tries to change the country, this error comes up: "An illegal choice has been detected. Please contact the site administrator"

For the time being, I suppose I'm going to just have to manually add the country select list and use the Conditional fields module to show one province list or the other depending on the country selected. (thankfully, I only need Canada/US for the site I'm working on, so this is a pretty easy interim solution)

To all the module contributors: Thanks for all your work so far. I'm sure your focus is on rebuilding for the 7x-5.x version, and I look forward to seeing a release.


akmalfikri’s picture

Can someone do this patch for D6?

aze2010’s picture


wemmies’s picture

After implementing the patch in #154 I ran into the following problem:

A location field is setup with city (text), country (dropdown), province (dropdown). A couple of fields further down I have an Image field with setting unlimmited.
on node creation I enter city, select a country and select a province. Then I upload a photo and than a second one that's where I get an error (an illegal choice has been made). The location field is still populated with the city, country I selected and the province I selected (also the dropdown still shows the correct provinces for that country) I'm guessing the validation is getting the initial values for province to check against and forgot I selected another country. This might be due to the use of AJAX for image?

When the images are added first and the location is enterd second, no problem occurs. Due to useability for my users I connot use this option as I would when I would be the only one entering data.

wemmies’s picture

Proxy double post - sorry

wemmies’s picture

Proxy tripple post - sorry

wemmies’s picture

I'm trying to build in something like this http://drupal.org/node/339730#comment-2871966 or this http://drupal.org/node/339730#comment-4582034 but I have no joy yet

mavaddat’s picture

I fixed this problem (the country change not being reflected in the province dropdown) by modifying the _location_country_ajax_callback fucntion on line 1096 of location.module (7.x-3.0-alpha1) from:

function _location_country_ajax_callback($form, $form_state) {
  // The isset() checks, ideally, wouldn't ever have to happen because, ideally,
  // this code would never get called, because, ideally, we wouldn't add an
  // ajax call to the country field.  Unfortunately, however, there's no easy
  // way to check whether or not the province is being collected when putting
  // together the country form element in location_locationapi() when that
  // function is called with $op == 'field_expand'
  if (arg(2) == 'locations' && isset($form['locations'][arg(3)]['province'])) {
    return $form['locations'][arg(3)]['province'];
  elseif (isset($form[arg(2)][arg(3)][arg(4)])) {
    return $form[arg(2)][arg(3)][arg(4)]['province'];


function _location_country_ajax_callback($form, $form_state) {
  // The isset() checks, ideally, wouldn't ever have to happen because, ideally,
  // this code would never get called, because, ideally, we wouldn't add an
  // ajax call to the country field.  Unfortunately, however, there's no easy
  // way to check whether or not the province is being collected when putting
  // together the country form element in location_locationapi() when that
  // function is called with $op == 'field_expand'
  if (arg(2) == 'locations' && isset($form['locations'][arg(3)]['province'])) {
    $form['locations'][arg(3)]['province']['#options'] = array('' => t('Please select'), 'xx' => t('NOT LISTED')) + location_get_provinces($form['locations'][0]['country']['#value']);
    return $form['locations'][arg(3)]['province'];
  elseif (isset($form[arg(2)][arg(3)][arg(4)])) {
    $form[arg(2)][arg(3)][arg(4)]['province']['#options'][]= array('' => t('Please select'), 'xx' => t('NOT LISTED')) + location_get_provinces($form['locations'][0]['country']['#value']);
    return $form[arg(2)][arg(3)][arg(4)]['province'];
fehin’s picture

Has anyone been able to get this to work?

rooby’s picture

Version:7.x-4.x-dev» 7.x-3.x-dev
fehin’s picture

Just upgraded to 7.x-3.0-rc1 and the drop down is working. Thank you!:)
I tried it in views filter but there is no setting to change it to a drop down.

openmode’s picture

Version:7.x-3.x-dev» 7.x-3.0-rc1

subscribing, in Better Exposed Filters I can't select a dropdown list on field Provincia

Media Crumb’s picture

Can we get this in views? Kind of a big deal.


skyredwang’s picture

Version:7.x-3.0-rc1» 7.x-3.1
Category:Bug report» Feature request
Issue summary:View changes
Status:Active» Closed (fixed)

The state dropdown is already avaiable in 7.x-3.1. Also avaiable in Views.

rituraj.gupta’s picture


I am using Drupal 7 with location and profile2 modules. When I choose country from dropdown, State / Province drop down changed according to country name. This is working fine on content type rather than profile2.

Can anyone please sort out this issue ? I also checked mavaddat #175 code. but it seems not working.