Closed (fixed)
Project:
Views (for Drupal 7)
Version:
7.x-3.x-dev
Component:
exposed filters
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
23 Nov 2006 at 16:09 UTC
Updated:
31 Aug 2015 at 17:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
mshaver commentedThat would be a nice addition. I modified the theme_views_filters function in my template.php file to add
l('reset', $view->url). Very simple, but it works great!Comment #2
Keith Adler commentedCould you explain just how you did that ... it's a great piece of functionality. Thank you in advance.
Comment #3
mshaver commentedAdd this code to your template.php file and it should work for you. You can see, I simply added a link to the original view. This essentially resets it to the default values. There are probably better ways to do this, but it worked for my purposes.
Comment #4
Keith Adler commentedThanks for much for the response; it is really appreciated. I've taken what you've done and mixed in a little from here http://drupal.org/node/40857 to come up with something I think others may find useful as well ... a reset button that looks just like the submit button; I will link to this on the Views Group.
Note: Because I'm on 5.x I had to replace form_render with drupal_render as well:
I simple added that to my template.php file as presto! ... a much desired reset button.
Thank you.
Comment #5
mrgoltra commentedGood Day,
I tried this but it shows 2 reset button on my exposed filters. Any ideas why?
Thank you,
Mark
Comment #6
Alan_C commentedYes, I can confirm the bug:
I tried it in Drupal 5.2 and I see 2 reset buttons.
Someone can kindly fix it?
Many thanks
Comment #7
mauro72 commentedI'm having the same problem, a workaround that I find is to add a class to the reset button, and hide it using CSS. If you look in the HTML code, you'll see that the 2 buttons have differents CSS path, one is inside the table and the other is outside of it, so you can choose which one to hide.
Anyway, I think that will be much better to have a solution through php code.
I found a solution through php code in this node http://drupal.org/node/79302#comment-624631, if you need more details let me know.
Comment #8
pgrunzjr commentedI'm still looking into it further to find out exactly whats making it happen, but it seems that anything passed to drupal_render is removed from the array or changed so that i cannot be rendered again. For whatever reason though the reset button does not get removed initially, so it is displayed not only when theming the $row array, but again when $form is passed to drupal_render().
To fix the double reset button error remove the final drupal_render($form) from the return statement. The code should be as follows:This is old code, use the stuff below
Maybe someone with a bit more knowledge of drupals API can better explain whats happening.
EDIT:
A better option may be to just move the creation of the reset button array to outside of the drupal_render() call and create it just prior. That way the $form array can still be rendered, in case it may be needed do display any other data. That and it makes the code a little easier to read =)
I suppose you could also just send the reset button directly to drupal_render() without adding it to $form and avoid the issue all together, but either way, for those having trouble this should fix it.
Comment #9
merlinofchaos commentedThis would be a fantastic candidate to be put into the Views documentation section. Anybody willing to create a documentation page about this?
Comment #10
NeuZeitgeist commentedI added your code to my template.php and it worked for me.
Thank you.
I think it would be nice to add this function to stundart version of Views
Comment #11
sunComment #12
tian commentedI can't make it work with D6. I added pgrunzjr's code to the beginning of my theme's template.php, but no button :(
Comment #13
webchickHere's how I did this in D6 with Views 2. Replace CAPITAL letters accordingly.
This gets pasted into a custom module someplace.
Comment #14
ilfelice commentedSubscribe
Comment #15
tian commentedI did the same thing (found the code in an other thread), but this creates a link, not a button :(
Better than nothing, though...
Comment #16
psynaptic commentedYou can also use the page from the view rather than hardcoding:
Comment #17
attheshow commentedThis works to make a "real" reset button, I believe:
Comment #18
alexh commentedAll this code only puts a link to the view (disguised as a button).
This does not help at all, if exposed filters are set to "Remember the last setting" (D6 Views 2).
Any idea how to make a real, real reset button?
Comment #19
attheshow commentedI realized that my snippet didn't take into account the current display that was being shown. A change to the code is shown below.
Comment #20
my-family commentedIs the following version of code correct?
It seems to work right for me (D6), even with "Remember the last setting" option.
The assumption is, that the URL of the view does not change with the filter, which is my case.
Comment #21
attheshow commentedThat looks like pretty much the same thing to me, just a bit simplified.
Comment #22
dnewkerk commentedThanks for the great code snippets! Can anyone give a little advice on how to apply this technique to get a Reset button or link in the case of an AJAX-enabled view? I tried out all of the suggestions mentioned thus far, and in the case of the AJAX view, clicking Reset instead forwards to the front page of the site rather than resetting the filters. Thanks! :)
Comment #23
my-family commentedTo Keyz: I use AJAX as well and my module (#20 above) seems to work right for me (e.g., http://www.my-family.cz/?q=view-atrakce-sport-wellness)...
BUT, when I use $view->url, instead of arg(0), "reset" button goes always to frontpage... I don´t understand, why.
Comment #24
beginner commentedThis is affecting project_issue.module, too.
#426086: Add a "Reset search" button/link
Comment #25
dww@merlinofchaos: Are you sure you just want to document this, instead of providing a mechanism for this in, for example, the settings for the display handler? There's already the setting about "Put the exposed form in a block". Why not another setting right next to that with "Provide reset link for exposed form"? If you said "go", I'd be happy to write such a patch. I just don't want to spend time on it if you're opposed in principle to giving views the power to provide this functionality out-of-the-box via the admin UI. Your wish is my command. ;) Thanks.
Comment #26
easp commentedI had the same problem adding a reset button that actually reset the form so that it would work with the "remember" setting.
What I ended up doing, was to set the reset button to submit "empty" and "any" values for the exposed filters.
Here is a sample of my code:
It may not be perfect, but it works with exposed filters with the "remember" option. It is set to work with a specific view with exposed filter: career_scholarship_fellowship. The window location is the path to the view with arguments that set the exposed filter's values. You can get the arguments by submitting your search and getting the values from the url. Use AJAX must not be set.
Comment #27
webchickI agree with dww that this ought to be part of the settings. It's obviously something that people need, given the popularity of this issue, and the sheer number of various solutions floating around make it really confusing.
Comment #28
my-family commentedI would like to add one more related question to it. By exposed filters in D5, when the filter was not obligatory, the option "all" appeared in the select box. Unfortenately, there is no such option in D6. I think that it would help a lot. I put this question into this issue, because the functionality is (at least partly) similar to the reset button.
Comment #29
snorkers commentedI'd love to see dww's offer taken up. I was on the cusp of delving into code (not my favourite way to end the week), but would rather have something that could (in theory) be maintained as the complexity of Views grows.
Comment #30
gustavosg commentedWhere do I have to put these codes using D6?? I tried in template.php but nothing happens. Please help me, I'm lost
Comment #31
my-family commented@gustavosg: you should put the code into your own module. You should create only my_module.info file and my_module.module file. You will put the code into the my_module.module file.
Comment #32
gustavosg commented@my-family: I've found this out 5 minutes before you post...heheh
But Thank you so much for you help.
Comment #33
tirdadc commentedSubscribing.
Comment #34
dnewkerk commentedFor anyone who doesn't have (or yet understand) how to have their own personal module with which to use hook_form_alter, here's a version of the code that can work in template.php. Since I wasn't sure how to use the $form_state here the way I do in my module's version, I have used the path arguments to identify the correct pages to affect (if anyone can correct this to use $form_state that would be cool). In my case the paths are media/photos and media/videos. I also have adjusted the submit button's label (which you can remove if you want). As usual, do not include the PHP open/close tags, and change YOURTHEME to the correct name of your theme. Rebuild the theme registry after adding the snippet.
Comment #35
Architeck commentedI am having trouble getting any of the snippets on this page to work. some are close but will not reload the correct view.
Here is a temporary javascript solution, based on this post.
To use this solution add this code to your views header.
Then make changes to the formReset function to clear your form values.
The solution below works to clear date field dropdowns and text search.
Comment #36
Vahalaman commentedIf you don't want your page to refresh when you click the 'reset' button - this works..
This goes in a custom module - not the template.php file. This post will help you quickly create a custom module for this function.
http://drupal.org/node/416986
Comment #37
jrabeemer commentedAgree with webchick #27, this needs to be a feature added.
Rebasing...
Comment #38
jenpasch commentedUsing Attheshow #19 code, things are good. Grazie!
However, as this is a multilingual site, I need to adjust this code so that the url called when the "reset" button is pressed is language aware...
Should I be doing something in the view arguments to achieve this?
Or is there some way to force the url to be en/... when the english version page is reset and fr/... when the french page is reset?
Comment #39
slotid commented../modules/views/theme/theme.inc
add
before
and add the function to your scrips.js file
Comment #40
julianna commentedSubscribe
Comment #41
Bilmar commentedsubscribing
Comment #42
merlinofchaos commentedNow that we have exposed plugins with better control of settings, I would like a patch that makes this an option on the base exposed filter plugin. Upping to critical as this is a Desired Feature.
Comment #43
rburgundy commentedsubscribing - this would be a great feature!
Comment #44
dagmarHere is a patch using exposed form plugin.
This patch works only if views has Ajax disabled. Why? Because $form_state['values']['op'] is missing when ajax is enabled.
I'm marking this as "needs work" until the ajax issue be fixed.
To test this patch you need to apply also:
#645150: Call to undefined method views_plugin_display_page::get_exposed_form_plugin()
#639094: Exposed Forms do not work?
Comment #45
Bilmar commentedMy testing results:
- all patching was successful
- checked 'Include reset button' under settings at Exposed form style
- tested by using exposed filters, then resetting to clear the search filters. Worked Great!
- as you mentioned above, with use AJAX set to Yes it did not work.
Thanks for the great work! I will be ready to test any future patches =)
Comment #46
merlinofchaos commentedOk. I ended up having to clean up a few things unexpectedly, so this patch is a little messy. I went ahead and committed the reset button, because it seems to be working well both with and without AJAX.
As a future patch, we should probably allow the text to be modified in the UI.
The patch is attached for porting to 7.x, and I'm sorry but some of it simply will fail to apply. Hopefully the parts that fail to apply won't matter too much.
Comment #47
merlinofchaos commentedComment #48
sunerrr. Is it possible that most of this patch are different line endings?
Comment #49
resynthesize commentedSubscribing
Comment #50
marcushenningsen commentedI tested this with the 6.x-3.x-dev version. The reset filter button works, but the date filter doesn't which makes it useless in my case.
I'm not sure which of the proposed code snippets is the best to use with 6.x-2.8. Both #19 and #20 doesn't reset the filters when set to remember.
For now I'm using #19 without setting the remember option on the filters.
Marcus
Comment #51
merlinofchaos commentedSome form of this line should unremember settings during reset:
($this->view might have to be just $view or something like that)
Comment #52
merlinofchaos commentedsun: Yes it is possible, admin.inc incorrectly had windows line endings. I corrected this in 6.x-3.x. It may well still need to be corrected in 2.x and 7.x-3.x
Comment #53
Bilmar commentedI noticed an issue with the reset button with 6.x-3.x-dev and thought to mention it here first and open a new issue if required.
With AJAX set to YES, the search result does reset but the exposed filter selected choices do not reset.
The exposed filters do not have 'Remember' checked.
With AJAX set to NO, everything works great!
Comment #54
merlinofchaos commentedOdd, I tested that. I shall have to have another look.
Comment #55
Anonymous (not verified) commented(cut)
see next post
Comment #56
Anonymous (not verified) commentedI needed a real AJAX 'clear form & submit' button that worked on every form, with remember-me capability.
Add this to your custom module:
That's it!
See a live example for my client: http://www.mastersranking.com/pages/masters-finance.html
Comment #57
dawehneryear and fixed. Works fine in preview
Comment #58
marcushenningsen commentedDoes this work for 6.x too?
Comment #59
dawehnerIts commited to the DRUPAL-6--3 branch, which is not stable yet.
Comment #61
nodecode commentedI hate to be a pain in the butt, but could this be committed to 6.x-2.x-dev?I say this because this issue is 3 years old now and i have no idea when Views 6-3 will be stable. Maybe someone can enlighten me.Nevermind, I dont care anymore. See post #63.
Comment #62
bkyan commentedInstead of having to update server code, I just stuck the following javascript code into my view's footer
$(document).ready(function(){ $("").insertAfter("#edit-submit-NAMEOFTHISVIEW"); });to insert a reset button right after the Apply button. If you use this snippet, please be sure to change
NAMEOFTHISVIEW to the actual name of your view.
Comment #63
nodecode commentedI actually resolved this by creating my own module using a combination of post #19 and #36. Neat! thanks to all those experienced Drupal users who contributed to this thread. I gained a larger understanding of how Drupal works with this simple module creation.
Comment #64
daniel wentsch commentedThanks a lot @morningtime. Your code (#56) worked very well for me.
All other suggestions I tried brought me no luck.
Comment #65
aac commentedSubscribing!!
Comment #66
roball commented@nodecode: could you please post your module for Views 6.x-2.x mentioned in #63?
Comment #67
nodecode commentedOk, since users keep asking me about this... Here is the module. Please note, YOU MUST EDIT THE MODULE to work with your specific setup (see below).
Instructions:
1. Unzip the folder to your local computer
2. On line 7 of the file "views_filters_reset_button.module" you should see the following code:
$exposed_views = array('view_1', 'view_2', 'view_3');3. Replace any of the values in the array (eg: 'view_1') with the names of the views where you want to see a "reset button"
4. Save the edited file "views_filters_reset_button.module"
5. Upload the views_filters_reset_button" folder in your contributed modules folder (where you put all your other modules).
6. Now on the Modules page of your website you should see an option titled "CUSTOM Views Filters Reset Button" under the "Views" category. Check the checkbox by this option and click "Save Configuration"
This is just a temporary solution i created for myself until we get this integrated properly into Views. It works with Views 6.x-2.8 and i dont see why it couldn't work with 6.x-2.10.
@dereine: Which solution did you commit to the 6.x-3.x branch? Does it reset the entire page like this module or just the filter values? Has it been thoroughly tested by users? I ask because I don't see one clear solution above that has reportedly worked for more than a few people on this thread. Just checking to make sure a good solution is implemented.
If it helps, the array in this module could be populated from a query that pulls exposed views that are somehow marked to include a "reset button" from within in the Views UI. I don't know how to do this but it seems fairly straightforward.
Comment #68
nodecode commentedwhoops, didn't mean to change the status.
Comment #69
roball commentedThank you nodecode. The version you posted did not work on the site I was going to implement it (where Drupal is installed in a sub directory). Thus I fixed that, enhanced it further and uploaded it to #781480: Module for adding a reset button to forms created by Views 2.x with exposed filters.
Comment #70
sharplesa commentedAdding to comment #56, to also reset date fields, I added one more thing to the onclick. My onclick looks like this:
'onclick="javascript:$(\'[name^=date_filter]\').val(\'\');$(this.form).clearForm();$(this.form).submit();" 'Note that this'll reset all the date filter fields on the page, not just the ones in this form. There's probably a narrower selector I could use. In my case, I only have one date filter on the page, so this works just fine for me.
Comment #71
grahamvalue commentedHi,
(To #56)
This code works great but only if I change clearForm() to reset()
Is clearForm() a standard js function?
Sorry, I'm quite new to Drupal.
reset only resets the forms to the remembered values.
I would ideally like a button that clears all the filters altogether
Any idea?
Thanks! :)
Comment #72
grahamvalue commentedOk, didn't have AJAX enabled on the view.
Code works like a charm. Thanks! :)
Comment #73
roball commentedshaurya1, did you try the module posted at #781480: Module for adding a reset button to forms created by Views 2.x with exposed filters?
Comment #74
lhernon commentedThank you so much. This is such a handy feature.
Laura
Comment #75
ari-meetai commented#56 is the way to go for the time being. Cheers!
Comment #76
druvision commentedThe 'views_filters_reset' module of the Views Hacks project does it for drupal 6.
Comment #77
roball commentedYes, the "Views Filters Reset" module that is now part of the Views Hacks package does the job well for me.
Comment #78
stuart.crouch commentedI created a views-exposed-form.tpl to do this in the theme (all the others seem to cover creating or installing extra modules).
Its basically a copy of the default one from views, with a jquery clearForm function added, and a reset button that calls the clearForm function and then submits the form.
Comment #79
koppie commentedI've found the easiest solution is to stick in a custom header on the view, with a simple html link back to the view. That resets the page for me.
Comment #80
tanma commentedJust wondering if this can't also be committed to the DRUPAL-6--2 branch?
Not sure how it's meant to work but 6.3 branch seems a long time coming.
Comment #81
marleo commentedstuart.crouch: Thanks. Works a treat.
tanma: Agree. 6.2 would be great.
Comment #82
msathesh commented#36 solution works for me.. its was easy though.. Thanks @Vahalaman ..
Comment #83
geek-merlinfor all thet first cant find it like me:
i can get a reset button on 7.x-3.x-dev by activating it in exposed form style > settings
Comment #84
freestone commentedUsing Views 6.x-2.12 the only thing for me that worked is #26
Thanks easp
I have 5 views that need the reset button so I simple repeated the if test .....changing the view name and the URL that reset the view to "all" value of all exposed filters. It worked for both text fields and for exposed Taxonomy with depth.
After 4 hours of trying these option this works in V2 for me with HS and lots of other modules
My custom module is below....notice that for each repeated IF the name of the view is tested on and the window.location value changes to the URL of a search done with all the text fields blank and the taxonomy field set to "any".
Hope this helps other..... easp you rock!
Comment #85
agileadam#56 worked great for me, and seems to be completely compatible with Better Exposed Filters.
Comment #86
clsturgeon commentedI tried #56. On two sites (one web hosted, the other local on my machine [using WebMatrix]) and they both work fine. On a third, same web host, different instance (same theme and modules) does not work. With Ajax set to yes on the view the page redirects to homepage. Page code looks like this...
...and Reset button fails with... Object has no method 'clearForm'.
When Ajax setting is no... Apply button works properly (no redirection) and Reset is no change, still get the error "Object has no method 'clearForm'.
While editing the View, in the Preview, Apply and Reset buttons work as they should no matter what the AJAX setting is.
Any ideas?
Update: The error I see in Chrome dev tools is "Uncaught TypeError: Object #
has no method 'clearForm'". Thanks in advance.Comment #87
dawehnerI'm sorry but the reset button is not part of views2. You shoudl also paste the full javascript error as context helps always.
Comment #88
acPlease don't open fixed issues, tag them and then assign them to yourself. If you have a support request then open a new issue instead of usurping this one. This feature is part of 7.x and I don't think it will ever be ported to 6.x and released.
Comment #89
maedi commented+1 for #56 as a quick fix.
Comment #90
Mark Vincent Verallo commentedBetter Exposed Filters is all you need for this. Just install it and select Better Exposed Filters from the Exposed form style section. Then check the "Include reset button" checkbox.
Comment #91
aakanksha commentedIt works perfectly... :)
Comment #92
hectorelgomez commentedButton exposed reset view Drupal dont works:
Perfect, but in plain html format is more easy:
Thanks, it works.
______________
Botón exposed reset view Drupal no funciona:
Muchas gracias, pero es más sencillo de esta otra manera si estás acostumbrado al html plano.
Tuve serios problemas con el botón de reset en las views de Drupal, al final cambiar los atributos por uno en HTML creado con este fin. Te ahorras recargar la página, pues al usuario suele no gustarle para una acción tan sencilla. Además luego le puedes poner los estilos que te parezca.
../modules/views/theme/theme.inc:
Saludos y gracias de nuevo
Comment #93
anybodyHere you can find a solution that replaces the default reset functionality by an AJAX version: http://julian.pustkuchen.com/node/659 I hope it helps some of you.
Comment #94
summit commentedHi,
better exposed filters module has a reset button.
greetings, Martijn