Views Dependent Filters
Allows the presence of exposed filters on a Views display to be controlled by values in another exposed filter. Dependent filters are hidden when not relevant.
views_dependent_filters
Install
composer require 'drupal/views_dependent_filters:8.x-1.4'
Overview
Views Dependent Filters provides a mechanism to create conditional visibility for exposed filters in Views. When you have a view with multiple exposed filters, this module allows you to show or hide certain filters based on the values selected in other filters.
The module works by adding a special 'Dependent filter' handler to your view that acts as a bridge between a controller filter and one or more dependent filters. When users select specific values in the controller filter, the dependent filters become visible. When the controller filter values are changed or cleared, the dependent filters automatically hide, creating a cleaner and more intuitive user interface.
The module uses Drupal's Form API #states system to handle the visibility toggling on the client side, providing instant feedback without page reloads. It supports various form element types including textfields, checkboxes, radio buttons, and select lists (both single and multiple).
Features
- Control visibility of exposed filters based on values selected in other exposed filters
- Supports multiple condition modes: trigger on specific values or when filter is not empty
- Compatible with Views basic exposed form and Better Exposed Filters module
- Supports various widget types: textfield, checkboxes, radios, and select elements (single and multiple)
- Negate condition option to invert the visibility logic (hide instead of show when condition is met)
- Multiple instances can be added to create complex filter dependency chains
- Integrates with Facets module for faceted search dependencies
- Client-side visibility toggling using Drupal Form API #states for instant response
Use Cases
Product catalog with type-specific filters
A view displays multiple product types (e.g., cake, bicycles, books). An exposed filter allows users to select the product type. Using this module, you can add type-specific filters that only appear when relevant: cake flavour filter appears only when 'cake' is selected, bicycle size filter appears only when 'bicycle' is selected, and book genre filter appears only when 'books' is selected.
Content type conditional fields
A view shows nodes of multiple content types. When the user selects a specific content type in the type filter, additional filters for fields that only exist on that content type become visible, avoiding confusion from irrelevant filter options.
Hierarchical location filtering
A view has country and city filters. The city filter can be made dependent on the country filter, so cities only appear after a country is selected, improving user experience by reducing the number of initially visible options.
Faceted search enhancement
When using Facets module with Views, this module can create dependencies between facet filters, showing secondary facets only when primary facets have selections, creating a guided filtering experience.
Form simplification
A complex view with many exposed filters can be simplified by hiding advanced filters until users indicate they need them by selecting certain values in basic filters, reducing initial cognitive load.
Tips
- Position the Dependent filter handler carefully in the filter order - it can only use filters before it as controllers and filters after it as dependents
- You can add multiple Dependent filter handlers to create complex dependency relationships between multiple filter groups
- Required exposed filters cannot be set as dependent filters since they must always be visible
- When selecting both values that show a dependent filter (e.g., 'cake' AND 'bicycle'), dependent filters for both will show, but Views query logic means results matching BOTH criteria would need to exist
- The negate option inverts the behavior - use it when you want filters to hide rather than show when conditions are met
- For Facets integration, you'll need to manually enter the raw facet values (as they appear in URLs) rather than selecting from a list
Technical Details
Hooks 1
hook_views_data_alter
Registers the 'views_dependent_filter' filter plugin with Views by adding it to the global 'views' table data
Troubleshooting 4
Verify that JavaScript is enabled and there are no JS errors in the browser console. Check that the filter order is correct: controller filter must be before the Dependent filter handler, and dependent filters must be after it.
The module supports textfield, checkboxes, radios, and select widgets. If you see a warning about unsupported widget type, consider changing the exposed filter's widget to a supported type in the Views filter settings or Better Exposed Filters configuration.
There is a known Drupal core issue (#1149078) where Form API #states uses XOR instead of OR logic for multiple select elements. This may cause unexpected behavior with dependent filters controlled by multi-select elements.
This is expected Views behavior. When filtering by multiple criteria (e.g., cake flavour AND bicycle size), results must match ALL criteria. Unless your content has both attributes, no results will be returned.