[support] Views filter block without "send" button

Earl Miles merlin at logrus.com
Sat Jan 24 18:41:32 UTC 2009


Marolijo / Pol Maresma wrote:
> Hello, does anybody know how to modify the form to avoid the necessity 
> of the submit button.
> My customer prefer the onchange method on the select list.
>  
> Thank's!


This is a script I was playing with. It's not really very well tested, I 
didn't really finish what I wanted. In particular it needs more smarts 
with textfields, I think, but if everything you have are select/radios 
then it works fairly well.

Add this to your theme via the 'scripts' command of the .info file:

--- views-exposed.js ---
/**
  * Allow exposed filters to submit on change, rather than when the apply
  * button is clicked.
  */

Drupal.ExposedViews = {};

// This contains a list of views to apply this to.
Drupal.ExposedViews.views = [
   // This is in the format of 'form#views-exposed-form-VIEWNAME-DISPLAYID
   // and that all _ are converted to - in CSS IDs.
   'form#views-exposed-form-fugazi-block-1',
   'form#views-exposed-form-exposed-test-page'
];
// You can add as many views as you like to that list, but remember that
// the last one should not have a comma after it, but all others should,
// like this:

// var views = [
//   'view1',
//   'view2'
// ];

/**
  * Attach change behavior to forms.
  */
Drupal.behaviors.ExposedViews = function(location) {
   for (i in Drupal.ExposedViews.views) {
     var $view = $(Drupal.ExposedViews.views[i], location);
     $view.filter(':not(.views-exposed-processed)')
       .addClass('views-exposed-processed')
       .each(function() {
         var $form = $(this);
         $('input[type="submit"]', $form).hide();
         $('select, input', $form).change(function() {
           $($form).trigger('submit');
         });
       });
   }
}



More information about the support mailing list