Hi,

I have two exposed filters : region and sub-region.
I want to hide the sub-regions until the user selects a region.
I also want to update the available sub-regions according to the selected region.

I have been able to hide the exposed filter thanks to Views Exposed Filters.
I am able to update the available sub-regions according to the selected region thanks to some custom code using the "#ajax" attribute of the Drupal Ajax Forms API.

However, I cannot make them work both at the same time. Both behavior - the hiding and the update - work the first time, but then only the hiding works and my custom update does not trigger anymore.

Any idea why and/or how I could deal with that?

Comments

Nicolas Bouteille’s picture

Still haven't found why there was a conflict and how I could solve it, but in the mean time decided to hide / show the sub-regions manually using jquery in order to move on.
Here's my code if anyone needs it someday:

<?php

if ( $("select#edit-region").find('option:selected').val() == 'All' ){
  $("div#edit-territoire-wrapper").hide();
}
		
$("select#edit-region").change(function(){
  		
  if ( $("select#edit-region").find('option:selected').val() == 'All' ){
    $("div#edit-territoire-wrapper").hide();
  }
  else {
    $("div#edit-territoire-wrapper").show();
  }
});
?>
InternetDevels’s picture

Are You sure that used wrapper id in #ajax wasn't changed in html after first ajax call? Drupal uses drupal_thml_id() function to prevent id duplicates on the page after ajax call. Sometimes it can change id used in 'wrapper' ajax property. Can You please post an example of your code?

Nicolas Bouteille’s picture

Status: Active » Closed (won't fix)

Hi,

Yes I am pretty sure the id did not change, that's one of the things I checked because it had already happened to me once.
My code is documented here http://bouteillenicolas.com/expertise-drupal/views-ajax-dynamic-dependen...
But you know, now that I implemented my own code above I am not going to use Views Exposed Filters anymore. Plus, I might actually use Simple Hierarchy Select in the end, which does both the filling and the hiding. Right now a bug in Views regarding the Content : has taxonomy terms (with depth) functionality is preventing me from using it http://drupal.org/node/1961368
But that's definitely where I am heading so I don't want you to waste some time on this current issue.

Thanks for the help anyway!

swim’s picture

Sorry for bumping this issue,

We faced a similar problem with manipulating exposed filters from a form_id_alter. The way around this was simple but required a little digging.

/**
* Implements form_FORM_BASE_ID_alter()
*/
function MYMODULE_form_views_exposed_form_alter(&$form, $form_state, $form_id) {
  if (strpos($form['#id'], 'views-exposed-form-example-view-name-') !== false) {
    // Manipulate the exposed form here.
  }
}

Wouldn't it be more appropriate for views to provide it's own hook for exposed forms? Always keeping the correct/ relevant $form['#id']?

swim’s picture

Issue summary: View changes

to two