Drupal Views and exposed filters - how to reset optional drop-down list filter, or allow “all” selection

StackOverflow https://stackoverflow.com/questions/4209300

Question

I have a view with a filter by country. Country is an optional CCK text field with drop-down list selection from a predefined list.

When I expose the field as an optional view search filter, I can select a country on the filter form just fine, but how can I handle no selection? I want the user to be able to "un-select" any previously selected value so that the query runs for all countries (or, to be more precise, does not constrain the results by country). I cannot add "all" as a value to the CCK field for obvious reasons. Selecting all countries in the drop-down on the search filter is not very user-friendly and causes the page to time out (there are over 200 countries in the list, and I can only imagine the resulting SQL query). Whats the best way to handle this?

I found this View Filters Reset hack which could be helpful. The desire to memorize the last selection adds another complication - when configured in the View properties, and once the (persistent) cookie is set, there is no way to get rid of the selection (short of manually deleting the cookie).

Was it helpful?

Solution

The answer was to check "Force Single" on the filter properties. This made <any> show up as a selection in the country filter drop-down. It kind of makes sense, because <any> in a multiple-selection list could be seen as ambiguous. Still, I can think of valid reasons why a multiple selection filter might be optional. Drupal surprises me every day.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top