adding a reset button to a exposed filter

One issue for views when you have an exposed filter is that once the selection is made (e.g. category selected), there is no way to unselect your category.  Your users will have to hit the back button, it's not intuitive to the user.

One way to resolve this is to incorporate a reset button in your form that would allow the user to reset the form.  I did a search on the drupal.org site and found just such a solution.  I am putting it here, with an slight adjustment of the css class name.  I added the following block of code to my custom modules hook_form_alter method.  The original solution was found at http://fleetthought.com/blog-post/adding-reset-button-exposed-views-filters

      if ($form_id == 'views_exposed_form') {
        $exposed_views = array('event_calendar', 'NAME_OF_VIEW2');
        if (in_array($form_state['view']->name, $exposed_views)) {
          $current_display = $form_state['view']->current_display;
          $form['reset'] = array(
            '#type' => 'markup',
            '#value' => '<input class="form-submit" type="reset"
    value="Reset" onClick="javascript:window.location=\'/'.
    $form_state['view']->display[$current_display]->
    display_options['path'] .'\';" />',
          );
        }
      }



Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options