3

I have a view with a few exposed filters and it uses ajax. It is set to remember their last selection. Is there any way to ensure that the user is aware the the view still has applied filters? (i.e. Some users may not be ware that the list is still filtered and they need to hit the reset button).

Edit

To further clarify:

The issue is that if the user is not aware that the list is in a filtered state that they should reset it before starting another drill down

Basically I need it to say "Hey you! this list is in a filtered state. You need to hit the reset button before doing another search!"

4 Answers 4

3
+25

In views, to remember the user entry, Views uses sessions. It uses different variables for each view. If you print the $_SESSION variable you can see that.

function MODULENAME_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#id'] == 'views-exposed-form-test-page'){ //your exposed form's id

      print_r($_SESSION);
   }
}

Now you can see that a structure like below

[views] => Array
    (
        [test] => Array
            (
                [default] => Array
                    (
                        [title] => Page
                    )

            )

    )

So if you check value exists for this variable, you can perform your task

ie:

if ($form['#id'] == 'views-exposed-form-test-page'){
//check is it exists, if so perform your task
 if($_SESSION['views']['test']['default']['title'] != ''){
    // "need to reset";
          //here using jquery or css, show or hide your message
        $script="(function ($) {
                //action to do here
        })(jQuery);";
        drupal_add_js($script,'inline');
 }
}

Hope this may helps you

1

Install Better Exposed Filters and you will have an option in the exposed filters settings to include a reset button (make sure you choose "Better Exposed Filters" in "Exposed form style" first).

4
  • Sorry I should have clarified. I am aware that there is a reset button that can be enabled on BEF (as well as basic exposed filters). I have done that already. The issue is that if the user is not aware that the list is in a filtered state that they should reset it before starting another drill down. Commented Oct 12, 2012 at 20:47
  • then why not just use JS to check if your exposed form fields have values selected and if they do, display the message?
    – Stefan
    Commented Oct 13, 2012 at 9:50
  • Easier said than done. :) Commented Oct 13, 2012 at 15:07
  • any way to just add a class to the view through the views UI, so I can target it with css and use a different colour background to signify that this list is in "filtered state" Commented Oct 17, 2012 at 19:25
0

This can be acheived by jquery.For example take test case with admin/content/node page.

$(document).ready(function(){
  if($('#node-admin-filter #edit-reset').length){
    alert("Hey you! this list is in a filtered state. You need to hit the reset button
 before doing another search!");
  }
});

Try this code using firefox console. In your case replace #node-admin-filter with a parent div specific to filter div.

0

I have used this solution in Drupal 6. It should work in D7:

/**
 * Implementation of hook_views_pre_render().
 */
function MYMODULE_views_pre_render(&$view) {
  if ($view->name == 'my-view') {
    // Check view URL arguments or exposed filters
    if (count($view->args) > 0 || count($view->exposed_input) > 0) {
      if ($view->total_rows) {
        drupal_set_message("Hey you! this list is in a filtered state.", 'status');
      }
    }
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.