I'm trying to add autosubmit functionality to a exposed hierarchical taxonomy filter. I used the code on a standard filter before and it works fine

$(document).ready(function()
{
$("form#views-exposed-form-venues-page-1 #edit-submit-venues").hide();
$("form#views-exposed-form-venues-page-1 select#edit-area-hierarchical-select-selects-0").change(function() {
  $("form#views-exposed-form-venues-page-1").submit();
});
});

but I get this error

warning: Invalid argument supplied for foreach() in sites/all/modules/location/hierarchical_select/includes/theme.inc on line 372.

Does anyone have any suggestions on how to get this to work.

Comments

wim leers’s picture

Status: Active » Postponed (maintainer needs more info)

No clue. What code is on that line?

marcus178’s picture

At that line it's

foreach ($choices as $key => $choice) {
    $key = (string)$key;
    if ($value_valid && (!$value_is_array && (string)$element['#value'] === $key || ($value_is_array && in_array($key, $element['#value'])))) {
      $selected = ' selected="selected"';
    }
    else {
      $selected = '';
    }

the full function that's part of is

function _hierarchical_select_options($element) {
  if (!isset($choices)) {
    $choices = $element['#options'];
  }
  // array_key_exists() accommodates the rare event where $element['#value'] is NULL.
  // isset() fails in this situation.
  $value_valid = isset($element['#value']) || array_key_exists('#value', $element);
  $value_is_array = is_array($element['#value']);
  $options = '';
  foreach ($choices as $key => $choice) {
    $key = (string)$key;
    if ($value_valid && (!$value_is_array && (string)$element['#value'] === $key || ($value_is_array && in_array($key, $element['#value'])))) {
      $selected = ' selected="selected"';
    }
    else {
      $selected = '';
    }

    // If an option DOES NOT have child info, then it's a special option:
    // - label_\d+ (level label)
    // - none ("<none>")
    // - create_new_item ("<create new item>")
    // Only when it's a level label, we have to add a class to this option.
    if (!isset($element['#childinfo'][$key])) {
      $class = (preg_match('/label_\d+/', $key)) ? ' level-label' : '';
    }
    else {
      $class = ($element['#childinfo'][$key] == 0) ? 'has-no-children' : 'has-children';
    }

    $options .= '<option value="'. check_plain($key) .'" class="'. $class .'"'. $selected .'>'. check_plain($choice) .'</option>';
  }
  return $options;
}
wim leers’s picture

Title: Autosubmit for exposed filters using jquery » Autosubmit for exposed filters using jQuery
Component: Code - Taxonomy Views » Code - Content Taxonomy
Assigned: Unassigned » wim leers
Status: Postponed (maintainer needs more info) » Fixed

Sorry, I had misread it: I thought it was core's theme.inc. My bad!

Also, you shouldn't use jQuery's change event. Because the HTML you're binding to is being replaced and manipulated by JS, I'm not sure what it'll behave like.

You should use HS' own events. It's documented in API.txt.

Do something like:

  $('#hierarchical-select-1-wrapper')
  .bind('change-hierarchical-select', function() {
    // …
  });

That should work just fine :)

marcus178’s picture

Sorry I'm not very good with JS and can't work out what to do from the API

If tried

  $(document).ready(function()
{
$("form#views-exposed-form-events-page-1 #edit-submit-events").hide();
$('#hierarchical-select-29-wrapper').bind('change-hierarchical-select', function() {
  $("form#views-exposed-form-events-page-1").submit();
});
});

but the form is not submitted

wim leers’s picture

I told you how you can do it. You repeat exactly what you said in the first post. That's not constructive.

I gave you the answer you needed, that took some of my time. Spend your time wisely and just learn the basic JS you need to know for this. I can't spoon-feed everything.

marcus178’s picture

I haven't repeated what I put in may first post

My original code was

$("form#views-exposed-form-venues-page-1 select#edit-area-hierarchical-select-selects-0").change(function() {

which I changed to your suggested

$('#hierarchical-select-29-wrapper').bind('change-hierarchical-select', function() {

which I assume means when the dropdown with the id of 29 is changed it should go and process

$("form#views-exposed-form-venues-page-1").submit();

However I have noticed something that could be causing this not to work. Every time I refresh the page the id is changing (incrementing by 1) which will mean the id in my code will never match and therefore not work. The id is now on 47 since I last posted. The exposed filter is in a block if that could have anything to do with it.

I can assure you that I am trying to work this out for myself, and have only posted because I have ran out of ideas.

robby.smith’s picture

following

dinwal’s picture

For the for each warning. Not sure if you are doing the same or not but sometimes the issue is too trivial and the solutions are too advanced to work. I kicked myself when I found the solution here:
http://amiatypist.blogspot.com/2010/04/invalid-argument-supplied-for-for...

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dgastudio’s picture

+1

rowanprice’s picture

http://drupal.org/project/views_hacks

"Views Filters Auto-submit
Auto-submit is initially off for all views. To turn it on, go to the Administer > Site configuration > Views Filters Auto-submit page (admin/settings/views_filters_autosubmit) and select the pages where auto-submit should be active, much like the blocks visibility settings.

Auto-submit supports Ajax-enabled views as well."

tobiberlin’s picture

When I activate the module "Views Filters Auto-submit" it works fine with other exposed filters but not with those Hierarchical Select enabled. I get the error "Received an invalid response from the server". Any ideas what can cause this error?

booyeeka’s picture

i can not find this one...

i have installed view module, but on page admin/settings/views_filters_autosubmit i can not found Views Filters Auto-submit page.

can you help me with this?

Aambro’s picture

I have managed to "enable" autosubmit on exposed filters with HS on my website by putting this code into template.php file under:

function xxxx_preprocess_page(&$vars, $hook) {

$autosubmit_js = "
$(document).ready(function() {

$('form#views-exposed-form-Contacts-page-1')
.bind('change-hierarchical-select', function() {
$('form#views-exposed-form-Contacts-page-1').submit();
});
});
";
drupal_add_js($autosubmit_js, 'inline');

}

gaurishankar’s picture

It's working for me for a single HS !!!!!!!!!!
If you have more than one HS then it not working for second one or third one, Only work for first one HS.

I faced that problem, I have two HS exposed so it working for first one good but not for second one. So please have you any ideas for more than one exposed HS ??

ANY ONE HAVE IDEASSSSSSSSSSS.....

Thanks Aambro

Sel_Space’s picture

Version: 6.x-3.1 » 7.x-3.0-alpha5
Status: Closed (fixed) » Active

I used this code in a file , the form is submited but the values aren't present on the $form_sate

(function ($) {

Drupal.behaviors.exampleModule = {
attach: function (context, settings) {

$(".hierarchical-select-wrapper").bind("change-hierarchical-select",function(){
console.log("Yes changed hierarchical-select");
// jQuery("#location-selector-form").submit();
$("#location-selector-form .form-submit").trigger("click");
})
}
};

})(jQuery);

kars-t’s picture

Assigned: wim leers » Unassigned
Status: Active » Fixed

Dear fellow Drupal enthusiasts,

this issue is now lasting for a very long time in the issue queue and was unfortunately never solved. As Drupal is a open source project everyone is helping on voluntary basis. So that this is was not solved is nothing personal and means no harm. But perhaps no one had time to deal with this issue, maybe it is too complex or did not describe the problem comprehensibly.

But this issue is not the only one. There are thousands of issues on Drupal.org that have never been worked on or could not be processed. This means that we are building a wave that is unmanageable and just a problem for the Drupal project as a whole. Please help us keep the issue queue smaller and more manageable.

Please read again, "Making an issue report" and see if you can improve the issue. Test the problem with the current Core and modules. Maybe the problem doesn't exist anymore, is a duplicate or has even been solved within this issue but never closed.

Help can also be found for it on IRC and in the user groups.

In order to remove this issue, I have set this issue to "fixed"

If there is new information, please re-open the issue.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jenlampton’s picture

Title: Autosubmit for exposed filters using jQuery » Autosubmit not working for exposed filters
Category: support » bug
Status: Closed (fixed) » Active

@Aambro - The solution in #14 works great on my Drupal 6 site. Thanks!

@Kars-T, I'm pretty sure changing the status here to "Fixed" was the wrong thing to do. Fixed means that there is code - that has been committed to the module - that fixes this problem. It does not look like that is the case.

If you are not willing to fix the issue, then "closed (won't fix)" might be the choice you were looking for.

If you are still waiting for someone to provide a patch (and are open to fixing the problem), then this issue should still be "active' until someone provides that patch - even if it is a very, very long time ;)

kars-t’s picture

@jenlampton

Hi Jen

please take a look here:

https://drupal.org/node/1989400

And at the module :)

This was an older version and I changed it.

I spoke to Wim and he agreed that we should close most D6 issues as we want to focus on D6. Still if the patch from #6 works should the issue be "needs review" or RTBC?

jenlampton’s picture

Version: 7.x-3.0-alpha5 » 6.x-3.x-dev
Status: Active » Closed (won't fix)

There's no patch on this issue, so "needs review" and "RTBC" statuses don't apply :/

The solution I was referring to (in #14) was a bit of a hack - some custom jQuery I added into my theme as part of a preprocess function:

  $autosubmit = "
  Drupal.behaviors.autoSubmit = function(context) {
    $('#views-exposed-form-whatever').bind('update-hierarchical-select', function() {
      $('#views-exposed-form-whatever').submit();
    });
  };";
  drupal_add_js($autosubmit, 'inline');

I understand that you are not willing to fix the old D6 bug - D6 usage is decreasing steadily. :) I'm re-categorizing as such. If someone else has this same problem in D7 (and it sounds like they shouldn't anymore) then they can locate the D7 issue where that bug was fixed, and gripe over there ;)

Thanks for your quick response @Kars-T! :)