Active
Project:
Views (for Drupal 7)
Version:
7.x-3.x-dev
Component:
exposed filters
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
25 Aug 2010 at 18:45 UTC
Updated:
9 Oct 2017 at 09:57 UTC
Jump to comment: Most recent
Comments
Comment #1
dawehnerit's fapi so it has to work :) You probably doing something wrong here.
Comment #2
dabblela commentedI would think so too but I cannot seem to make it work. If I make a view with just NID and Node Title exposed filters, set NID to come before Title in the UI but make $form['title']['#weight'] higher than the nid weight in my alter, there is no change.
Comment #3
dawehnerThe problem is that there is some theming on exposed form. You would have to override it, sadly.
Comment #4
esmerel commentedComment #6
LGLC commentedHas anyone got an example of how to do such theming? I'm really struggling trying to get new form elements to the the top of exposed filter forms.
Thanks.
Comment #7
dabblela commentedYes, all of it is handled in views-exposed-form.tpl.php, which you can override in your theme to print out your fields manually. IIRC, the extra fields are gonna be in the $button variable in that template, so you might want to do some preprocessing in template.php
Comment #8
LGLC commentedThanks for your help, manatwo. I finally managed to do it after reading your post. Thank you.
Comment #9
kgthompson commentedI was able to alter the order without overriding the template. I am using Views 3, but I think this will work in Views 2 as well.
Alter the order of the filters in $form['#info'] in your form_alter and this should alter the order the widgets print out in the template without having to do any custom templating.
Comment #10
maciej.zgadzaj commentedA small update on this, if someone faces similar problem in the future, as I just did myself, trying to place my new exposed form item in-between "widgets" generated automatically by the view - the solution is to turn that new form item into a widget, and then re-order widget array in the
$form['#info'].In my case I was adding new
communityform item into Views exposed form, and then wanted it to be displayed as a second element in the form, right afterfilter-titlegenerated by the view:Obviously the code responsible for re-ordering
$form['#info']will look different depending on where the new form item should be displayed.Comment #11
MixologicIm re-opening this as Im hoping somebody with deeper views experience can chime in on the best way to handle this.
I too needed to shim in a #markup bit in between various exposed filters, and I did exactly what maciej.zgadzaj did above. All the while I was wondering why a form alter, or even a form #afterbuild seems to require such jostling of form['#info'] just to reorder the widgets. Is there a better way to accomplish this?
Comment #12
d0t15t commentedthe solution from maciej.zgadzaj in #10 worked great for me - thanks!
Comment #13
lpeabody commented#10 worked for me as well. Totally weird...
Comment #14
blacklabel_tom commented#10 worked for me too.
Any plans to get the form to respect #weight?
Cheers
Tom
Comment #15
michaellenahan commentedThank you very much maciej.zgadzaj for #10!
Here is some code for putting an element into an exposed form at a certain position.
In this case, $insert_index = 2 means that the new element will go after the second element.
Comment #16
leex commentedYou can use normal weights if you're willing to ignore templating, which for me was totally acceptable. I set weights on exposed filters using form_alter:
Then to ignore templating, just put an empty theme hook in template.php:
Yes this is not a very ideal way of doing it as it removes templating from all views exposed filter forms, but it was much quicker for me than doing the ordering properly.
Comment #17
profak commentedMaciej.zgadzaj's solution is great!
Thanks!
#weight still not supported. It looks fine because of way widgets render and work.
Comment #18
drupalshrek commentedThank you very much michaellenahan for your code in #15 as this works great!
Comment #19
drupalshrek commentedMoving the code from michaellenahan into a function:
Example of call to the function to add 2 fields.
Comment #20
DrCord commentedThank you drupalshrek, maciej.zgadzaj and michaellenahan!!
Comment #21
jedihe commented#15 worked great for me! thanks!
Comment #22
bas.bakker commented#15 worked like a charme
Comment #23
sebi commentedIf you dont care about theming, you can simply set the parent element
['#theme']to an empty string to reset formatting and handle weights.In my case...
Comment #24
jfraz commented#15 FTW. Thanks michaellenahan!
Comment #25
ropic commented#23 works too, great !
Comment #26
konst_8 commentedYou can use drupal element_sort function, applied to $form['#info'] array:
Comment #27
riddhi.addweb commentedComment #28
lissy commentedkonst_8, You made my day. ;-)
#26 works perfekt for me.
Comment #29
Meera.b commentedComment #30
Meera.b commented#10 worked perfectly.
Comment #31
Collins405 commentedTried everything, 26 was the only one that worked for me. Thanks!
Comment #32
sushantpaste#10 Works fine !
Thank you.
Comment #33
sergey-shulipa commentedThanks to all! But any solution as-is not worked for me properly.
Problem was in all widgets, corresponding to $form['#info'] array elements, which was below new widget in $form['#info'] array. So, these widgets appeared inside new widget.
My solution:
I've combined #10 and #26, but added operator to new $form['#info'] element:
Comment #34
mustanggb commentedSeveral people reporting the same thing, seems more like a bug at this point.