Set the Drupal Views filter as on / off to enable / disable the filter

I have a Drupal view that filters a taxonomy field. I would like to be able to turn on / off a filter by opening a checkbox in the "Open Filters" form. To illustrate the problem, say, for example, the vocabulary is fruits and the terms are apples, pears, oranges and lemons. I can select the citrus content by creating a filter that says Fruit is one of (oranges, lemons). Now I would like to provide a filter so that I can choose whether to apply my citrus filter. How do I add a checkbox to open filter forms that will apply the filter when selected and ignore the filter if not selected?

+3


source to share


4 answers


Assuming you are using BEF and that you have checked the "Checkboxes / Radio buttons" option for your open filter in the BEF parameters, a way to set checkboxes instead of radio buttons is to check "Allow multiple selections" in the configuration dialog for your open filter in views.



+3


source


This is possible:

  • Add a filter to the appropriate field (term reference to Fruit in your example).

In the Configure Filter dialog box:

  • Set the "Filter Type to Display" to "Grouped Filters".
  • Check the box "Allow multiple choices"
  • Set "Widget Type" to "Radio".
  • You probably want to remove "Label".
  • Remove all but one of the filter sets in the table below.


In this remaining set of filters:

  • Fill in the label ("Citrus Fruit" in your example).
  • Set "Operator" to "One of".
  • In the "Value" section, select the values ​​you want to filter (oranges and lemons in your example).

This gives you 1 checkbox that says "Citrus Fruits". Thus, the user interface. Unfortunately issue [# 2224601] prevents it from working as it results in an invalid request, but a working patch is available.

+3


source


You would assume Views would do this out of the box. This is not true. Use the Enhanced Open Filters module → http://drupal.org/project/better_exposed_filters

It even has nested checkboxes / radio buttons for taxonomy with hierarchy.

Here are some docs pertaining to what you are trying to do ...

Checkboxes / Radio Buttons: This option is available for any filter with a limited number of parameters. Check the Power Single option to use radio buttons, disable it for checkboxes.

Nested flags / Buttons with radios. Although this parameter shows for any filter that shows a regular checkboxes parameter, it is really only used for taxonomic filters with hierarchy. If you are using a taxomomy filter with the selection type set to Dropdown and Show in the dropdown, these filters will appear as nested, unordered lists. Check the Single option to use nested switches "

+1


source


I think no answer here answers the question. "I want to show one checkbox which, when checked, enables / allows the filter, and when unchecked, ignores / disables the filter. I don't think Better Exposed filters let me do that."

You do not need "Advanced Filters" for this. You need to use grouped filters.

  • Click this visitor filter.
  • Disclosure Filter Type: Grouped Filters
  • Check "Advanced"
  • Check "Widget type: Radio"
  • Check the box "Allow multiple choices"
  • Remove / remove "Shortcut" if necessary
  • At the bottom you will have a few lines where you can set each one as you wish. If you only want one, remove all but one
  • Click "Apply"

This answer is very late. But I hope this helps someone.

+1


source







All Articles