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.
Directions:
- Install Better Exposed Filters (BEF) as you would any other Drupal module. There are no configurations or permission to set for BEF.
- 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.
- Click the Expose button to reveal addition filter configuration options.
- Select the display option for this exposed filter.
A couple notes
There is abugin 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. view. This issue has been fixed.- The choice between radio buttons and checkboxes is controlled by the “Force single” setting: radio buttons if this setting is selected, checkboxes otherwise.
- 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?
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
Post new comment