Return to Snippet

Revision: 22422
at January 13, 2010 11:12 by morningtime


Updated Code
function CUSTOM_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
        $form['reset'] = array(
           '#type' => 'markup',
           '#value' => '<input '. drupal_attributes(array('type' => 'button', 'value' => t('Reset') )) .'onclick="javascript:$(this.form).clearForm();$(this.form).submit();" class="form-submit" />',
    );
    }
}

Revision: 22421
at January 12, 2010 08:43 by morningtime


Initial Code
// 1. Put this jQuery snippet in a custom .js file you load with drupal_add_js('my_custom_js.js');

$(document).ready(function() {

  $('#views-reset').click(function(){
   $(this.form).clearForm();
   $(this.form).submit();
   return false;
  });

});

// 2. Put this PHP snippet in your CUSTOM.module
function CUSTOM_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'views_exposed_form') {
        $form['reset'] = array(
           '#type' => 'markup',
           '#value' => '<input '. drupal_attributes(array('type' => 'button', 'value' => t('Reset') )) .'id="views-reset" class="form-submit" />',
    );
    }
}

Initial URL
http://drupal.org/node/99370#comment-2465716

Initial Description
What it does: clears & submits exposed filters form via AJAX (if enabled, otherwise normal page refresh).

This is for Views 2.x. It works with the 'remember me' option.

You need to create a custom module. E.g. custom/custom.module and custom/custom.info. Enable your custom module via admin/build/modules.

Initial Title
Drupal Views AJAX Reset Button for Exposed Filters in

Initial Tags
ajax, jquery, drupal

Initial Language
PHP