Here is what I did,
1. Created a Page with list of nodes - It works

2. Enabled and exposed filter Country (equals, optional, single) - It works
3. Enabled and exposed filter City (Starts with, Optional, single) - It works

4. Enabled and exposed filter Province (Optional, Single) - Wrong

More clearly, the Issue is that :
If you have the Province filter enabled-It always have this
(location.province = '') in the Query generated. It doesnt matter if or what we select.

CommentFileSizeAuthor
location-bug.jpg447.68 KBraj47i

Comments

hutch’s picture

If the country you are working with does not have a province list in a function location_province_list_xx where xx is the country code then no lookup can be done. the file this function should be in is in the supported folder.

If the above is there then there might be a bug in handlers/location_handler_filter_location_province.inc. If you can try sticking some watchdog lines in to see if the data is being collected or not
BTW best to work with dev if you can, it really is much better.

raj47i’s picture

I am not very sure that is the problem-
In the node location add/edit page, the Province auto-complete works well.

And even in this view page, the auto-completion do come up (Probably not very correctly)

1st I have to select United States, the click apply so that the correct states come up - otherwise auto complete will be for some other states.

So, I believe location_province_list_xx functions are there- The problem should be where the Condition Queries are generated -
I have not had a chance to dig into the views architecture, so I dont know how is it structured !?

I cannot use dev, as this is for Production use.

yesct’s picture

Priority: Critical » Normal

You can use dev... just test it on a copy of your site first before putting it on a live site. Then once you are sure it works, dont update dev again until you need a fix that might be in a new dev version.
Hopefully a new release will come out. But if this is fixed in the dev version, you wont see any movement on this issue (fixes are not being made against 3.0 at this time), and it will be considered fixed if dev works for it.

Please try the dev version on a test site, and report back if it fixes your problem. Thanks a lot for being patient while the new version is being worked on. If you can sponsor work to speed the release of a new version, please contact me.

John Carbone’s picture

I was working on something similar and ran into the same issue. My implementation is different, as I have an argumented View that filters by country, then on that page, you can filter by state. I attempted to fix the autocomplete version but abandoned it because the parameter in the URL wouldn't work. It sends the human name versus the two letter machine name for the state, which the query expects. Anwyay, here's my fix. Maybe it will help someone.

/**
 * Implementation of hook_FORM_ID_form_alter.
 *
 * Fixes location module's state filter. The
 * View is argumented and this function adds the state filter as a select form,
 * per argumented page, i.e. "/contact/ca" will have 
 * a select list for Canadian provinces. Note that we're switching from an 
 * autocomplete to a select list.
 * 
 * @see View "contacts"
 *
 * @return void
 */
function MYMODULE_form_views_exposed_form_alter(&$form, &$form_state) {
  
  $form_id = $form['#id'];
  
  //these can change from page to page so we're just checking the 
  //first part and letting the page number be variable
  if (substr($form_id, 0, 33) == 'views-exposed-form-contacts-page-') {
    $path             = explode('/', $_GET['q']);
    $country          = $path[2];
    //create an "All" option
    $options['']      = '<All>';
    $provinces        = location_get_provinces($country);
    $options          = array_merge($options, $provinces);
    $form['province'] = array(
      '#type' => 'select',
      '#options' => $options,
    );
  }
}

/**
 * Implementation of hook_views_query_alter.
 *
 * Location module sends a blank query to
 * Views for any state filter beyond the US, so we're piping our
 * missing argument in directly, using the form_alter data above.
 *
 * @see drupal.org/node/789258
 */
function MYMODULE_views_query_alter(&$view, &$query) {
  if ($view->name == 'contacts' && isset($_GET['province'])) {
      $query->where[0]['args'][3] = check_plain($_GET['province']);
    }
}
raj47i’s picture

thank you for your reply, This feature was not very crucial for my project so I completed it otherwise.
But I am sure, your fix will be useful to someone!

poorva’s picture

This problem is still appearing in "6.x-3.x-dev" version and also recommended "6.x-3.1" version.
View expose filter with location province does not work.

poorva’s picture

Can anybody help me to resolve this issue.

selwynpolit’s picture

We created a module to handle this. I thought it might be useful to share. The logic is:
1. build a list of provinces & countries that have been used so far.
2. Sort them and add an Any option
3. For my views form (the $form_id), change the provinces autocomplete form field to a select box and populate it with the list of provinces from above. In the code, I am using this for 3 different views.
4. For my views: when a selection is made, find the province field and fill it's 'where' clause value with the state/province selected and voila!

I hope this is useful for someone.

/**
* Implementation of hook_FORM_ID_form_alter.
*
* Fixes location module's state filter. The
* View is argumented and this function adds the state filter as a select form,
* per argumented page, i.e. "/contact/ca" will have
* a select list for Canadian provinces. Note that we're switching from an
* autocomplete to a select list.
*
* @see View "contacts"
*
* @return void
*/
function coutreach_location_form_views_exposed_form_alter(&$form, &$form_state) {
	$provinces = array();
	$result = db_query("SELECT DISTINCT province,country FROM {location} WHERE province != ''");
	while($record = db_fetch_array($result)) {
		$province_code = $record['province'];
		$province_name = location_province_name($record['country'], $province_code);
		$provinces[$province_code] = $province_name;
	}

	$form_id = $form['#id'];
	//there are a couple different pages with this functionality, so check each of them
  	if ($form_id == 'views-exposed-form-Events2-panel-pane-1'
  					|| $form_id == 'views-exposed-form-calendar-page-1'
  					|| $form_id == 'views-exposed-form-calendar-calendar-1'){
    	//create an "All" option
    	$options['']      = '<Any>';
		asort($provinces);	# sort province list by value
    	$options          = array_merge($options, $provinces);
    	$form['province'] = array(
      		'#type' => 'select',
      		'#options' => $options,
    	);
  	}
}

/**
* Implementation of hook_views_query_alter.
*
* Location module sends a blank query to
* Views for any state filter beyond the US, so we're piping our
* missing argument in directly, using the form_alter data above.
*
* @see drupal.org/node/789258
*/
function coutreach_location_views_query_alter(&$view, &$query) {
#	drupal_set_message('Info: searching in province '.check_plain($_GET['province']));
#	drupal_set_message('<pre>'.print_r($query->where,TRUE).'</pre>');
	if (($view->name == 'Events2' || $view->name == 'calendar') && isset($_GET['province'])) {
		$argidx = NULL;
		foreach($query->where[0]['clauses'] as $i => $clause) {
			if(preg_match('/province/', $clause)) {
				$argidx = $i;
			}
		}
		if(isset($argidx)) {
			$query->where[0]['args'][$argidx] = check_plain($_GET['province']);
		}
	}
}


legolasbo’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Closing old D6 issues as D6 is end of life