Lullabot Ideas
We know stuff. We empower you to know stuff too.
Module Monday: Views Dependent Filters
Article by Jeff EatonFebruary 20, 2012 - 10:00am
Since version 2.0 of the Views module shipped back in 2008, site builders have been able to use its Exposed Filters feature to create slick user-filterable lists without writing a lick of code. Unfortunately, complex views with lots of exposed filters can easily become cluttered -- some filtering options only make sense when others are also selected, for example. Views Dependent Filters solves that problem, allowing to hide and show exposed filters based on other filters' values.

Configuring the module is a bit opaque: using it requires adding a "Global Dependent Filter" to your existing view, then positioning it between the two exposed filters whose behaviors should be linked. For example, you might add an exposed Content Type filter, then the Global Dependent Filter, then an second exposed filter that's only applicable to one of the content types. The Dependent Filter's configuration options will allow you to choose which values from the first filter should hide or show the second exposed filter.

Once the filter has been set up, Views Dependent Filters does what it says on the tin. Exposed filters appear and disappear automatically, and your complex view gets simpler.
Developers familiar with Drupal's FormAPI and the new States system will recognize what's going on under the hood: the same tricks can be done in a custom module with careful use of hook_form_alter(). Using Views Dependent Filters, though, means that the visibility tweaks are an inherent part of the view, and can be exported and saved cleanly. If you're looking for a way to simplify complex, user-filterable views, check it out!

Comments
See also...
As always a lovely write up, Jeff! Thanks for introducing us to Views Dependent Filters.I hadn't heard of this module before but will certainly use it on many a project from now on.
In the context of Views filters I feel it's worth mentioning two additional filter modules: Better Exposed Filters and the recent Views Global Filter. Both add different useful dimensions to the usage of filters in Views.
Great tips!
Better Exposed Filters is a great module, and one of the reasons I like the Views Exposed Filters module is its smooth integration with B.E.F; the two work very nicely with each other. I'll have to check Global Filter out as well, thanks for the tip!
Thanks!
Man, is Matt H ever right: "it's funny in the Drupal world how a module like this comes along just when you need it."
Views Global Filter is EXACTLY what I was looking for yesterday for a project I'm working on. You just saved me a lot of work!
Super nice!
Cool, super nice module - it's funny in the Drupal world how a module like this comes along just when you need it.
We're just starting a project that requires a lot of exposed filters and this module will be a great help in keeping our UI tidy.
Thanks for posting.
Thanks & problem
Hi Jeff!
Thanks for the tip, I was looking for it!
But I have a problem... Exposed filters don't appear and disappear automatically... is it depend on the kind of filter or ...? I'm a bit lost...
Thanks a lot!
Post new comment