I work on drupal 7, and create a page from views used 2 exposed filter. I want to display exposed selected values and also close button in exposed selected values. I found this solution for one hand:

Instead override views tpl file to include the code as needed. Consider view page named "Exposed Filter data". "Display output" file can be found under "advanced"->"Theme: information" setting of view. Select last name from "Display Output" as the tpl file name. For this example file name is "views-view--exposed-filter-data--page.tpl.php". Clicking on "Display Output", you will get current code of the file. Include following code after $exposed is printed & its condition ends. Here is the code that needs to be done for displaying exposed selected values of all four dropdowns. Considering Lamp, Color Temperature, Luminous Flex & Wattage as Taxonomy Term Reference fields, current view is loaded & current selected values are displayed with a cross anchor link.

Note that here "data-field" value on anchor field are same as id of the select list.

  $year = '';
  $category = '';
  $view = views_get_current_view();
  if (isset ($view->exposed_input['field_year_tid'])) {        
    $tid = $view->exposed_input['field_year_tid'];
    if (is_numeric($tid)) {
      $term_obj = taxonomy_term_load($tid);
      $year = '<a href="#" class="reset" data-field="edit-field-year-tid">X</a>' . $term_obj->name; 
  if (isset ($view->exposed_input['field_category_tid'])) {        
    $tid = $view->exposed_input['field_category_tid'];
    if (is_numeric($tid)) {
      $term_obj = taxonomy_term_load($tid);
      $category = '<a href="#" class="reset" data-field="edit-field-category-tid">X</a>' . $term_obj->name; 
  echo $year . '  ' . $category;

And then I am using JQuery for reseting the value of dropdown & submitting the form, when cross link is clicked. It does not work.

  jQuery('a.reset').live( 'click', function() {
    var datafield = jQuery(this).attr('data-field');
    jQuery( 'VIEW_EXPOSED_FORM_ID' ).submit();

I am not sure where I supose to put this script. Does it have to be inside PHP function? I am using the form_id (views-exposed-form-exposed-filter-data-page) that I found in the code, but am I doing something wrong? Where I should put the script? Here is the website http://zliks.cat/cabrianes/exposed-filter-data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.