I'm using the selective filters options in my views and it is REALLY helpful.

Would it be possible to take this a step further and not display the entire exposed filter if there are no terms in the filter?



Requested feature:

- Default behaviour of module would be to disable the widget if there are no results.
- Additional checkbox in filter configuration that says "Hide if empty" that will completely hide widget instead of disabling.


infojunkie’s picture

Thanks for the request. I've also received another request to disable the filter if there are no terms. So I guess this will be an additional option.

xl_cheese’s picture


I'm using Product Attributes exposed filters. It displays all the options within the products in the result set of a particular attribute.

With this functionality I can keep the same taxonomy menu structure and be able to display products with different attributes cleanly. Not sure if that makes any sense, but it'll help me a TON.

infojunkie’s picture

Version: 6.x-1.0-beta1 » 6.x-1.x-dev
Category: support » feature
Status: Active » Fixed

Implemented in the latest dev. Please try t (12 hours from now) and let me know how it works for you.

xl_cheese’s picture

I've installed the latest dev. I'm not sure that I see any options to add this functionality? Should I see something when editing the exposed filter?


infojunkie’s picture

Maybe you downloaded the dev too early, before the new changes were integrated. I checked now and the new code is in. You should find an option "Hide if empty" inside the selective filter options.

xl_cheese’s picture

I have the option now. When I select it an save I get this error message on my view page.

I'm using product attributes exposed filter.

* user warning: Table 'thepinkg_drp1.content_type_exhausts' doesn't exist query: SELECT DISTINCT(field_manufacture_exhaust_value) FROM content_type_exhausts WHERE nid IN (1018,1017,1016,989,990,973,886,982,981,890,991,983,992,997,1001,861) in /home2/thepinkg/public_html/sites/all/modules/views_hacks/views_filters_selective/views_filters_selective.module on line 168.
* user warning: Table 'thepinkg_drp1.uc_product_options' doesn't exist query: SELECT DISTINCT(oid) FROM uc_product_options WHERE nid IN (1018,1017,1016,989,990,973,886,982,981,890,991,983,992,997,1001,861) in /home2/thepinkg/public_html/sites/all/modules/views_hacks/views_filters_selective/views_filters_selective.module on line 168.
* user warning: Table 'thepinkg_drp1.uc_product_options' doesn't exist query: SELECT DISTINCT(oid) FROM uc_product_options WHERE nid IN (1018,1017,1016,989,990,973,886,982,981,890,991,983,992,997,1001,861) in /home2/thepinkg/public_html/sites/all/modules/views_hacks/views_filters_selective/views_filters_selective.module on line 168.

xl_cheese’s picture

I'm actually getting these errors just from the update to dev rather than selecting the hide if empty box.

infojunkie’s picture

Check the settings again. Perhaps you need to explicitly choose a field to restrict the values? If you've upgraded from an old dev this might very well be the case.

xl_cheese’s picture

I initally left the restrict field to default. I've changed it to title, I do not get any limiting of the filters. It shows all possible. The errors do go away however.

I also seem to have some illegal choice errors that show an empty view. For this error I only have the limit option set to title and hide unchecked.

infojunkie’s picture

In order for the restrict field to work, it needs to exactly correspond to the values in the exposed filter. You can create hidden fields in the view, and select those to restrict the exposed filter values.

xl_cheese’s picture

So you're saying I should not be able to use a current field that's in the view? I need to have a hidden one for the limiting to work?

The only way I've been able to remove all the errors in the view is to completely turn off limiting.

Would you be able to post a screenshot showing which options I should select to get it to work?


infojunkie’s picture

For a field to be used as limiting value for an exposed filter, it needs to contain the same values that go into the exposed filter drop-down. For example, if you want to limit a user drop-down, you need to use a "User: Uid" field and set this as your limiting field. You will probably want to hide this field since the view display should not show it to the end-user.

Does that make more sense?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

GiorgosK’s picture

Version: 6.x-1.x-dev » 6.x-1.0-beta2

I am using views 6.x 3.x
with latest views hacks 6.x-1.0-beta2

and either I don't understand how this is implemented or its not working properly

I have enabled it for a taxonomy term
- Limit "Taxonomy: Term" values to result set
- Further limit values to active filters
- limiting field > default
- Hide if empty

and there are cases that some widgets are empty but still shown

I have also tried with creating a hidden "taxonomy term" of the same kind as the exposed filter
- Limit "Taxonomy: Term" values to result set
- Further limit values to active filters
- limiting field > (the hiden taxonomy field above)
- Hide if empty

but still I can see empty exposed filters
can you give an easy to follow example so that I know I am using it the right way ?

workaround is to modify the views-exposed-form.tpl.php to prevent empty widgets from showing up

<?php if (!empty($q)): ?>
    // This ensures that, if clean URLs are off, the 'q' is added first so that
    // it shows up first in the URL.
    print $q;
<?php endif; ?>
<div class="views-exposed-form">
  <div class="views-exposed-widgets clear-block">
    <?php foreach($widgets as $id => $widget): ?>
      <?php if (!empty($widget->widget)): ?>
      <div class="views-exposed-widget views-widget-<?php print $id ?>">
        <?php if (!empty($widget->label)): ?>
          <label for="<?php print $widget->id; ?>">
            <?php print $widget->label; ?>
        <?php endif; ?>
        <?php if (!empty($widget->operator)): ?>
          <div class="views-operator">
            <?php print $widget->operator; ?>
        <?php endif; ?>
        <div class="views-widget">
          <?php print $widget->widget; ?>
      <?php endif; ?>
    <?php endforeach; ?>
    <?php if (!empty($sort_by)): ?>
      <div class="views-exposed-widget">
        <?php print $sort_by; ?>
      <div class="views-exposed-widget">
        <?php print $sort_order; ?>
    <?php endif; ?>
    <?php if (!empty($items_per_page)): ?>
      <div class="views-exposed-widget">
        <?php print $items_per_page; ?>
    <?php endif; ?>
    <?php if (!empty($offset)): ?>
      <div class="views-exposed-widget">
        <?php print $offset; ?>
    <?php endif; ?>
    <div class="views-exposed-widget views-submit-button">
      <?php print $button ?>
    <?php if (!empty($reset_button)): ?>
      <div class="views-exposed-widget views-reset-button">
        <?php print $reset_button; ?>
    <?php endif; ?>
GiorgosK’s picture

Category: feature » support
Status: Closed (fixed) » Active

its at least a support request

infojunkie’s picture

You're doing the right thing AFAICT. There's a condition that triggers the hiding of filters in views_filters_selective.module:

if ((empty($form[$filter_element]['#options']) || array_keys($form[$filter_element]['#options']) === array('All')) && !empty($settings[$filter_id]['vfs_hide_empty'])) {

Can you tell if the code goes inside this block? Use dsm('inside'); inside the block. Otherwise, please find out which condition prevents the code from going inside.

scuba_fly’s picture

I think I have the same problem.
The 'label' shows up if all terms of that vocabulary are hidden because there are no nodes of that term.

To make myself a bit more clear:
I have a vocabulary lets call it 'colors'.
I have a view that currently shows nodes of which none of them have a color assigned. but there might be a node with a color in the future.
So in that case i don't want to show the label for the vocabulary 'color'.

If i check the checkbox 'Hide if empty' in the exposed filter taxonomy term, the terms lets call them 'yellow, black, white' are hidden but the label 'color' still shows up.

I've installed the latest dev version from 2011-Jul-28 but that did not help either.

glintwine’s picture

Same problem, but I solved it.
When you add exposed filter, It is necessary to leave the default value in Filter identifier. For example: field_product_color_value_many_to_one. If it is cut to color, the label will not be hiding.

I was searching for a very long time this mistake.

scuba_fly’s picture

Thanks for your reply, but how do i find the default value if I've already changed it?

abugge’s picture

Version: 6.x-1.0-beta2 » 7.x-1.0-alpha2

Is this something that is conna be inccluded in the future 7.xx branch?
I desperatly need at solution to this problem.

1kenthomas’s picture

Issue summary: View changes

Looks like this would require a programmatic (template at least) solution in the 7.x branch (I just tested). I'll post example code here once (if) I have it.

infojunkie’s picture

Project: Views Hacks » Views Selective Filters
Version: 7.x-1.0-alpha2 » 7.x-1.x-dev
Component: General » Code

Changed the project as Views Selective Filters has moved to its own module.

david_garcia’s picture

Category: Support request » Feature request
Issue summary: View changes
Status: Active » Needs work

Updated issue description.

ConradFlashback’s picture


jakabadambalazs’s picture

Actually, it should be hidden/removed if empty or only one available choice is present for filter - there is not much use for a selective filter if there is only one option to select.

victoriachan’s picture

Agree with #25 that this would be great for D7! Thanks!

timwood’s picture

Any thoughts or work being done for this as a feature request for the 7.x version?

alisonjo2786’s picture

Here here! This would be fantabulous!!!!!!!!!!

lukasss’s picture

you can use a theming widget:

function YOURTHEME_preprocess_views_exposed_form(&$variables) {
  if ($variables['form']['#id'] == 'views-exposed-form-VIEWNAME-DISPLAYID' && empty($variables['form']['field_NAME_FILTER_selective']['#options'])) {  
adam1’s picture

I am looking for the same feature – is there any progress in this case?

Richard15’s picture

According to lukasss #29, I put in my template.php:

function PORTO_SUB_preprocess_views_exposed_form(&$variables) {
  if ($variables['form']['#id'] == 'views-exposed-form-VIEWNAME-DISPLAYID' && count($variables['form']['FIELD_FIELD']['#options']) < 2)

I flagged the option "Required" on Filter Criteria, so I don't have the option "Any".
In that case change "2" with "3" on the code.

Thanks again lukasss!

elizzle’s picture

#29 works great, thanks lukasss! Also thanks Richard15 for cleaning it up further.

MPeli’s picture

#29 works fine. Thank you!

wjhessels’s picture

Got it working with #29 and #31 Thanks!