Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
At date the filter is exposed at the top of the view page, and consume a valuable space. I'm wondering if the expose filter could be configured to collapse to save view's real estate. That's, in the same manner as advanced search works.
Regards,
Comment | File | Size | Author |
---|---|---|---|
#19 | views-6.x-2.x_exposed_filters_in_a_fieldset.199991.patch | 2.02 KB | roball |
#12 | views-exposed-form.tpl_.php_.zip | 780 bytes | roball |
#6 | Nyhetersarkiv _ Svenska Bågjägare Förbundet.jpg | 123.59 KB | Metusela |
#2 | collapsed.JPG | 22.12 KB | VascoW |
#2 | expanded.JPG | 66.52 KB | VascoW |
Comments
Comment #1
sdsheridanI'd love to be able to do this too!
Comment #2
VascoW CreditAttribution: VascoW commentedHi!
I had the same issue for my project and I helped out with an override like:
(please change VIEWSNAME and HEADING on your needs)
It workes fine. There is only one problem so far: the status of collapse is not remebered. So if the users leave the page and came back, the filter will be collapsed, even if the user expand it and filter the page. But for me it is usable so far.
Comment #3
zmove CreditAttribution: zmove commentedThe problem I see with your tweak is that the form is contained in the fieldset. Which is not XHTML valid. The fieldset have to be in the form.
Comment #4
catchYou should be able to do this easily enough with a small module and hook form alter.
http://api.drupal.org/api/function/hook_form_alter/5
However I doubt this'd get into 1.x since many people might want the filters not collapsed.
Also note that whether using form_alter or patching, fapi generates fieldsets with collapsible and collapsed settings, you don't need to use #prefix and #suffix
http://api.drupal.org/api/file/developer/topics/forms_api.html/6
Going to leave this open, since a fieldset around the filters (but not collapsed) would make it easier to collapse them in a form_alter
Comment #5
sdsheridanI'm a bit confused. I've implemented the code above, but nothing is clickable for collapse or expansion. Am I missing some code or js somewhere? Is this all that has to be done, or is there something else?
Comment #6
Metusela CreditAttribution: Metusela commentedHi!
I'm looking for the exact same feature. But I can't get it right.
I got so far to have the fieldset appear, and collapse and expand as I want it to. But it comes after the actual form. Why?
I tried with adding a fieldset tag myself. This works, almost, fine. I get a fieldset around the form just as I want to, but it's not collapsed.
This is the code i have in my template.php:
Comment #7
sdsheridanCheck http://drupal.org/node/296855. That's how I round up doing it.
shawn
Comment #8
Metusela CreditAttribution: Metusela commentedI found a solution for this.
The variable
$rows_theme
, which I use to theme each exposed filter, I set as the value for the$form['view']
variable. So when the$form['view']
is rendered by Drupal the form is included inside the fieldset with the settings declared for$form['view']
.Comment #9
merlinofchaos CreditAttribution: merlinofchaos commentedThis will not be done in Views 1.
Comment #10
MoSaG CreditAttribution: MoSaG commentedMy first entry
as always, in drupal I have many ways to solve problems ;)
I searched for this topic too, but I'm not a geek in php or in drupal (I have my first project in drupal), so I've found a simple (but perhaps dirty) solution for me. I collected some code snippets and read different forums for that. Perhaps it is useful for someone or someone can make a better solution based on mine.
I've copied the views-exposed-form.tpl.php from the views module wich themes the exposed filters, to my theme folder and do the following changes:
after the
I deleted the rest of the file and replaced it with the following code
and it works. Not solution I think, but it works ;)
Perhaps someone has a cleaner or easier solution, I'll be happy.
(sorry for my bad english, I'm from germany) -- seen to late, my solution works on drupal 6.x, don't know if also for 5.x
Comment #11
roderikWell. to me it looks like this is the best easy solution.
One thing, though:
If you have an exposed filter on a 'number' field, that exposed filter needs to be post-processed by JavaScript. (Some textboxes need to be made invisible, because 'less/more than' has one textbox and 'in between' has two.)
This fails when the textboxes are in a collapsed fieldset.
The solution: make it non-collapsed and include some JS to collapse the fieldset at the very end:
$element['#collapsed'] = FALSE;
drupal_add_js("$(document).ready( function () { Drupal.toggleFieldset($('#SOME_IDENTIFIER fieldset')); });", 'inline');
I created code where the filters are only put in the collapsed fieldset if they have no values, i.e. you always see the already-filled filters:
http://drupal.org/node/682014
Comment #12
roball CreditAttribution: roball commentedAttached is the entire "views-exposed-form.tpl.php" template file for Views 6.x-2.x, with the changes from reply #10, but with cleaned up code (to validate against Coder) and with the fieldset's default state set to expanded. Works fine for me!
Comment #13
roball CreditAttribution: roball commentedComment #14
dawehnerBut this is not a patch, right?
With pluggable exposed forms you could make a plugin which does this.
Comment #15
roball CreditAttribution: roball commentedNo, it's not a patch. The file inside the attached .zip archive is meant to be a replacement of the shipped views/theme/views-exposed-form.tpl.php file of Views 6.x-2.x. Being able to collapse the exposed filters above the views results is essential if you have more than let's say maybe 3 exposed fields, and it doesn't harm at all. Just a must-have for me and I think many others.
Comment #16
dawehnerWhat i missed to say: You don't have to replace the existing one: copy your new tpl to your theme. Thats it.
Comment #17
roball CreditAttribution: roball commentedYeah, that's exactly the way I did it. Nevertheless, I still consider it as an advantage if that template would ship with the Views package per default.
Comment #18
dawehnerIf you want this... make a patch
Comment #19
roball CreditAttribution: roball commentedHere it is. Thanks for considering it!
Comment #20
dawehnerI wouldn't implement it this way... I suggest to add a new exposed form plugin
Comment #21
roball CreditAttribution: roball commentedSorry, but I'm not used to Views plugins - so I can't do your suggested solution at this time. Maybe someone with good expertise in this field (it seems that are you...) may want to do that.
Comment #22
merlinofchaos CreditAttribution: merlinofchaos commentedSorry, I am not going to make exposed features be in a fieldset by default.
I am sure that it is a must have for you, and you've found a way to do that. That is excellent and I am happy that you have done it. But that is not how exposed filters are used the vast majority of the time, and that is not something I will do by default.
Comment #23
roball CreditAttribution: roball commentedThat is 100% fine to me - so people who want the fieldset just need to grab the ZIP file attached to #12, and put its content into the default theme directory.
Comment #24
eugen80 CreditAttribution: eugen80 commentedIs it possible to group some fields into collapsable fieldsets and other leave outside the fieldset?
Comment #25
roderikIt's possible. See link and last sentence in comment #11 above, for an example, which puts only the 'empty' fields into a collapsible fieldset.
Comment #26
johnhesston CreditAttribution: johnhesston commentedGreat man..works well for me. thanks so much...you dont know how much this saved me!
Comment #27
anrikun CreditAttribution: anrikun commentedFor those who prefer to use a preprocess function, here is another solution:
Comment #28
cajmcmahon CreditAttribution: cajmcmahon commentedThis last solution (preprocess) worked perfectly for me in D6 but not in D7. I've tried a few things but with no success. Any suggestions...?
Thank you!
Comment #29
anrikun CreditAttribution: anrikun commented@cajmcmahon:
This issue is marked as applying to 6.x-2.x-dev.
You should post any request applying to 7.x separately.
Comment #30
cajmcmahon CreditAttribution: cajmcmahon commentedPosted separate D7 issue here: - http://drupal.org/node/1224284
Comment #31
davidwhthomas CreditAttribution: davidwhthomas commentedD7 Wrap views exposed filters in fieldset
http://drupal.org/node/1224284#comment-4946712
Comment #32
blackspiraldancer CreditAttribution: blackspiraldancer commentedAnother interesting and effective approach would be to put in a block the exposed filters, and then use block visibility to control where and when the exposed filter would show up, and some modules like Collapsiblock http://drupal.org/project/collapsiblock to control the status of the module collapse.
Over the theme preprocess approach, this will apply just where and when you'll need it, and you'll even be able to control the initial status of the collapse (open/collapsed).
Comment #33
tbrowninfinitymark CreditAttribution: tbrowninfinitymark commentedWas this "feature" included at some point by default in Drupal Commons? I'm building my first Commons site, and exposed filters are inherently implemented this way (with a collapsible fieldset set to collapsed by default with no apparent way to change that default). I think it is very unintuitive to have the word "Filters" just sitting at the top of the page and would really like to just show my exposed filters the old fashioned way.
I've looked at views-exposed-form.tpl.php within the /sites/all/modules/views/theme folder, and it doesn't even contain the word "collapsible" or "filter" so I'm not able to simply edit this file.
Any suggestions are very much appreciated.
Comment #34
codesidekick CreditAttribution: codesidekick commentedtbrowninfinitymark: see http://drupal.org/node/1460198 if you're still in need of answers to how fieldsets are implemented in Drupal Commons.
Comment #35
HAKLO CreditAttribution: HAKLO commented#27 anrikun. The code you provided will change all Views. How can I set that code for specific Views only? For example, I wanna use this on ViewsA only.
Comment #36
pog21 CreditAttribution: pog21 commented@CocoSkin,
You might be able to do something like this in a small module, if it's an exposed form: