Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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?
Thanks.
------------------------------------------------
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.
Comment | File | Size | Author |
---|---|---|---|
#56 | vsf-hide-empty-select-field-943724.patch | 1.92 KB | cozzamara |
Comments
Comment #1
infojunkie CreditAttribution: infojunkie commentedThanks 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.
Comment #2
xl_cheese CreditAttribution: xl_cheese commentedGreat!
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.
Comment #3
infojunkie CreditAttribution: infojunkie commentedImplemented in the latest dev. Please try t (12 hours from now) and let me know how it works for you.
Comment #4
xl_cheese CreditAttribution: xl_cheese commentedI'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?
Thanks.
Comment #5
infojunkie CreditAttribution: infojunkie commentedMaybe 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.
Comment #6
xl_cheese CreditAttribution: xl_cheese commentedI 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.
Comment #7
xl_cheese CreditAttribution: xl_cheese commentedI'm actually getting these errors just from the update to dev rather than selecting the hide if empty box.
Comment #8
infojunkie CreditAttribution: infojunkie commentedCheck 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.
Comment #9
xl_cheese CreditAttribution: xl_cheese commentedI 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.
Comment #10
infojunkie CreditAttribution: infojunkie commentedIn 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.
Comment #11
xl_cheese CreditAttribution: xl_cheese commentedSo 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?
Thanks.
Comment #12
infojunkie CreditAttribution: infojunkie commentedFor 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?
Comment #14
GiorgosKI 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
Comment #15
GiorgosKits at least a support request
Comment #16
infojunkie CreditAttribution: infojunkie commentedYou're doing the right thing AFAICT. There's a condition that triggers the hiding of filters in views_filters_selective.module:
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.Comment #17
scuba_flyI 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.
Comment #18
glintwine CreditAttribution: glintwine commentedSame 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.
Comment #19
scuba_flyThanks for your reply, but how do i find the default value if I've already changed it?
Comment #20
abugge CreditAttribution: abugge commentedIs this something that is conna be inccluded in the future 7.xx branch?
I desperatly need at solution to this problem.
Comment #21
1kenthomas CreditAttribution: 1kenthomas commentedLooks 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.
Comment #22
infojunkie CreditAttribution: infojunkie commentedChanged the project as Views Selective Filters has moved to its own module.
Comment #23
david_garcia CreditAttribution: david_garcia commentedUpdated issue description.
Comment #24
ConradFlashback CreditAttribution: ConradFlashback commented+1
Comment #25
jakabadambalazs CreditAttribution: jakabadambalazs commentedActually, 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.
Comment #26
victoriachan CreditAttribution: victoriachan commentedAgree with #25 that this would be great for D7! Thanks!
Comment #27
timwoodAny thoughts or work being done for this as a feature request for the 7.x version?
Thanks!
Comment #28
alisonHere here! This would be fantabulous!!!!!!!!!!
Comment #29
lukasss CreditAttribution: lukasss commentedyou can use a theming widget:
Comment #30
adam1 CreditAttribution: adam1 commentedI am looking for the same feature – is there any progress in this case?
Comment #31
Richard15 CreditAttribution: Richard15 commentedAccording to lukasss #29, I put in my template.php:
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!
Comment #32
spelcheck CreditAttribution: spelcheck commented#29 works great, thanks lukasss! Also thanks Richard15 for cleaning it up further.
Comment #33
MPeli CreditAttribution: MPeli as a volunteer commented#29 works fine. Thank you!
Comment #34
wjhessels CreditAttribution: wjhessels commentedGot it working with #29 and #31 Thanks!
Comment #35
Engineer_UA CreditAttribution: Engineer_UA commented#29 How to build the proper " Foreach (): endforeach; " structure in case of more than one widget?
Comment #36
cozzamara CreditAttribution: cozzamara commentedPlease insert the code #29 into the module to make it easy....Thanks
Comment #37
cozzamara CreditAttribution: cozzamara commentedIf the module's manteiner can add the property "#access" to the selective fields, the hiding of empty field can do with
with this code:
Please review and test it. The hook can be called also by View Selective Filter module.
Comment #38
cozzamara CreditAttribution: cozzamara commentedThis code works only with select field, but can be applyed also to the others that have "#access" property.
But the property is a "must have".
Comment #39
cozzamara CreditAttribution: cozzamara commentedAfter too many test I finally found a code that seam works good:
Please some one test it
Comment #40
cozzamara CreditAttribution: cozzamara commentedI'm sorry but #39 not work properly.....failed on test
Comment #41
lukasss CreditAttribution: lukasss commented#36 - I think this is custom problem.
Comment #42
cozzamara CreditAttribution: cozzamara commentedWhy #41 @lukasss? Adding this code into the module I think is better so you can avoid to change
template.php
.I tested SUCCESSFULLY THIS CODE and now works very good on my site. Please test it
I would to change the status in "needs review" but I'll wait the maintainer will do.
Comment #43
cozzamara CreditAttribution: cozzamara commented...and this code works with ALL selective field empty and you have not specify one by one.
Comment #44
lukasss CreditAttribution: lukasss commentedthen you'd better add a patch for this
Comment #45
cozzamara CreditAttribution: cozzamara commentedIt's ok...the patch you asked for...
Comment #46
cozzamara CreditAttribution: cozzamara commentedPlease empty cache after apply it
Comment #47
lukasss CreditAttribution: lukasss commentedPlease correct the error of coding standards
https://www.drupal.org/docs/develop/standards/coding-standards
Comment #48
cozzamara CreditAttribution: cozzamara commentedI'm sorry for the mistake.. Try this new one and please remember to empty the cache after apply it. Thanks.
Comment #49
lukasss CreditAttribution: lukasss commentedI'm afraid that not all errors have been fixed
do you use a dreditor when see this patch in the browser?
Comment #50
cozzamara CreditAttribution: cozzamara commentedI'm sorry...I review again and then post another one.
Comment #51
cozzamara CreditAttribution: cozzamara commentedOn this file no errors are reported by Drupal Coder.
I hope is the final. Thanks
Comment #52
lukasss CreditAttribution: lukasss commentedspace in 67 line and more...
Comment #53
lukasss CreditAttribution: lukasss commenteddsm($form)
it seems superfluous
Comment #54
cozzamara CreditAttribution: cozzamara commenteddsm($form) is commented out. Not evaluated in php, and is indifference. I can also remove but nothing happen.
About #52 Drupal Coder not warning me. I checked it again.
Comment #55
lukasss CreditAttribution: lukasss commenteduse dreditor! This is plugin chrome browser
Comment #56
cozzamara CreditAttribution: cozzamara commentedComment #57
cozzamara CreditAttribution: cozzamara commentedIt's ok now also "dreditor" doesn't report errors. I wait for response.
Comment #58
lukasss CreditAttribution: lukasss commentedComment #59
jvieille CreditAttribution: jvieille commentedThis did not work for me as filters do not necessarily show up at the first level in the form array (I uses view_ef_fieldset).
Here is my code in views_handler_filter_selective.inc