Skip to Content

Better Exposed Filters for Drupal Views

Drupal’s Views module is hugely powerful, but not always pretty.  Exposed filters are no exception.  The Views Filter Pack claims to do this but has some serious problems, including a lack of activity in the issue queue for the past three months.  This article gives a quick look into a new module I built to help improve the user’s experience with exposed filters.

The main problem comes up with exposed filters that allow multiple selections.  Rather than something pretty and user-friendly, like a list of checkboxes, Views gives you a multi-select box.  Here, try one out:

Imagine telling a client that they just need to click on the first option, then scroll to the next one and Ctrl+Click on that (don’t just click, you’ll lose your first selections…) and to unselect an option you have to Ctrl+Click on it again.  The client starts to wonder why they’re paying you so much!  But everyone understands checkboxes:







Normally you can use hook_form_alter() to flip the #type to checkboxes, but due to the vagaries of the Forms API and Views, it doesn’t work.  Sure you get checkboxes, but they don’t work properly.  Leaving all checkboxes unchecked should be the equivalent of selecting “Any” but instead returns no results.

Ben Buckman posted his solution to the problem: handle it at the theme layer!  It was such a simple and elegant solution to a long standing problem that Ben probably heard the thwack as I smacked my forehand.  And so I introduce the Better Exposed Filters module.

Click the Expose button for more options
Set BEF's display options

Directions:

  1. Install Better Exposed Filters (BEF) as you would any other Drupal module.  There are no configurations or permission to set for BEF.
  2. Edit an existing view of create a new one.  Add a filter to the view or configure an existing filter.
    • If you’re using a CCK-based field for the filter, be sure to select the “Allowed values” option, otherwise the filter is rendered as an auto-complete textbox.
  3. Click the Expose button to reveal addition filter configuration options.
  4. Select the display option for this exposed filter.

A couple notes

  1. There is a bug in the current implementation that causes inherited filter settings not to show the real value for the BEF display setting.  The workaround is to edit the Default view rather than the Page/Block/Feed/Attachment/etc. viewThis issue has been fixed.
  2. The choice between radio buttons and checkboxes is controlled by the “Force single” setting: radio buttons if this setting is selected, checkboxes otherwise.
  3. BEF only works on filters that are rendered as select boxes.  That’s why you have to choose the “Allowed values” version of CCK-based fields.

Suggestions, bugs and feature requests

Yes, please!  Though the place to do it is in the BEF issues queue.

Update: 12 Feb., 2010

I've added a Select All/Select None toggle as an option with Better Exposed Filters.  There is also an optional description field -- just as you normally get when adding fields Drupal's FAPI.  Both were added in Beta 4, but it's best if you download the -dev release as that includes bug fixes for IE and multiple filters on the same page.

this is in the views only.. merge with node edit form?

Hi- Great idea, and I love it already. I saw you take some flack for reproducing some other efforts already, but I was wondering what it would take for you to reproduce a little more? :D There's a module, Taxonomy Super Select, which works well but is on the node edit side of things. It would make sense (to me) to have a single module handle both possibly. Any thoughts on this? Thanks for sharing your progress with the community! -Bronius

BEF is Views specific

Hi Bronius,

Thank you for your comment.  Unfortunately, Better Exposed Filters is very closely tied to Views -- it'll probably be a Views plugin for Views 3.x -- and wouldn't transfer well to node edit side.  Sorry.

For what it's worth, I use Content Taxonomy regularly to manage large taxonomies.  Actually, I use it to manage small taxonomies as well!  I find it has a much better interface than the default Taxonomy interface.

Great module

Really nice module, Mike. I'll be following this one -- super-useful for lots of sites!

Nicely done with BEF. I was

Nicely done with BEF. I was looking for this while reading  Ben Buckman's blog. It's very useful. 

 

Thanks.

 

CliffordX

great!, this module is what i

great!, this module is what i need :)

thanks

BEF with table wizard imported fields

Hi

I looked at the spec of your module and it was just what I needed Ilike many others I'm guessing).

It appears to do everything it says on the tin with basic Drupal fields and with CCK created fields but I used the table wizard module to import fileds from a database table and while views2 shows the usual filter options for these fields the check box / radio button options dont appear.

Any idea why this might be.

help with node reference exposed filter

Hi All

 

I'm having trouble to find a module that can create a explosed filter using content type

 

for example I've a art that have a node reference gender ( e.g landscapes, religious) an I need create a view with exposed  node reference filter

 

Could anyone help me

 

king regards

Filter by price

Hi and Thanx for this great module. I would like to use it in order to filter product by price, i'm using ubercart and the way to handle price is by adding price from the edit side. When i add the price filter and expose it, the only possibility i get is to let users write price, for instance, 2000 will show them products below 2000. What i need, is to let users select from a select list the price range. I'm guessing i can handle it through Taxonomy, add a Price vocab with terms such as 0-1000, 1000-2000, etc But it quite painful for the admin who will add producs, too many steps. Is there a way to simplify it? Thx

Issue queue...

Hi Ismail,

I appreciate you dropping by and leaving a comment, but this would be a better question to post in the BEF issue queue (mark it as support request, or feature request if you would like something added to BEF).

For one, more people than the few that come to my site will see it and there's good odds that one of them has already figured out the answer.  More importantly, when it does get resolved/fixed/added, more folks will see the result.

But, either way, I'll look into it -- I haven't used BEF with Ubercart yet.

Thanks.

Taxonomy Synonyms

Hi Mike, I've been using the Better Exposed Filters module for a while on a site I'm developing and it's fantastic. Unfortunately for me there is one thing still missing from my exposed filters and I can't get it working. In search results I show your check boxes for taxonomy terms (which is great) but before ANY filters are applied, there are simply too many categories to display this way so I have a text box instead. What I would LOVE would be that when someone types in that box, it matches not only the term names but also synonyms of that term, is this something you've ever got working or seen elsewhere? Even if it were ONLY looking at synonyms (and not looking at terms at all) that would be okay, it would just mean that the term name would need to be added as a synonym of itself. Cheers, Mark.

PS

I would add it to the BEF issue queue as a feature request, but I'm not sure whether this should be within the scope of BEF or not!

thanks

Thanks for this great module. I have been breaking my head with views exposed filters with Checkboxes & Select elements lately. Your solution to checkboxes is very good. Hope something comes up like BEF for select elements to have a way to display price range with Min.Price and Max.Price with single views exposed field Price. I had actually solved the select element by creating my own module instead. Just a very basic one. Anyways thanks very much dude. I appreciate for your time.

Hello, all of the check boxes

Hello, all of the check boxes are check by default on page refresh. How can I make it so they're all unchecked by default? Thank you.

Check the issue queue...

There were a couple of items similar to this is the BEF issue queue.  Specifically this issue and the solution  posted in comment #5.  Also see this issue regarding heirarchical taxonomy filters. Note that both of those are strictly cosmetic fixes -- they manipulate the UI with Javascript. To have the initial results reflect all checkboxes checked, you'll need to select all the options in the Configure filter form.

For what it's worth, having all options selected is very similar to having none selected.  If no filter options are selected, the Views ignores the filter.  If all are selected, Views returns rows with any of the selected options meaning only rows with NULL for that field will be removed. So, for required fields (eg: Node:Type), selecting all and selecting none are equivelent.

Initial Default Value

Rather than "any," I'd like to use a default taxonomy term in an exposed filter. Any ideas?

Default values

I need to point out that this would be better discussed in the BEF issue queue so that any resolution would be more widely available for others to see.

Having said that, you can sort of set the default value of an exposed filter: if the "Limit list to selected items" checkbox is unchecked, you can select a single item from the list of options and that will be the default filter option. If you want both a default option and to limit the filter options, you're out of luck...

This is a limitation with Views and there are already a bunch of issues in the Views queue about this. Alas, most end like this. Feel free to add this to the BEF issue queue as a feature request, but I won't have time to work on it for a while.

Post new comment

The content of this field is kept private and will not be shown publicly.