Forums › Forums › Search & Filter Pro › Reset Filters on search results page
Tagged: searchform checkbox reset v3
- This topic has 10 replies, 3 voices, and was last updated 6 years, 4 months ago by Anonymous.
-
Trevor(Private) July 18, 2018 at 1:58 pm #182849
Do you mean that you make a search and the results show, but the form still shows the search selections, and you would like them to be reset but for the results to be correct for the last search, OR do you need a way to reset the form (which will reset the results to ALL)?
Anonymous(Private) July 18, 2018 at 2:10 pm #182851When a make a search, I check 2 or 3 categories for example. I don’t want to use Ajax, so page is changed to my result page, and my selection still shows the search selection, which I don’t want.
I want to have all my search options available so I can run a new search.
let me know if you understand, thanksTrevor(Private) July 18, 2018 at 2:36 pm #182859That is what I had thought. This is not an option in our plugin.
Our plugin detects the filter selections and sets itself to match. You would have to write a custom javascript that runs on document load to clear the selections. Of course, you cannot have Auto Submit, as if you did, as soon as the form showed no selections from running the script, it would change the results. Thus you must also use a Submit button.
Trevor(Private) July 18, 2018 at 3:27 pm #182866Our filters and actions are detailed here:
https://searchandfilter.com/documentation/action-filter-reference/
But I do not think you need them. I do not have a example of a script to clear the selections. You would need to code that yourself.
Ross Moderator(Private) July 19, 2018 at 4:30 pm #182966Hi Paule
We don’t actually have a javascript api as such, which is why there is no documentation on it (coming in v3).
So to get this picture clear, you perform a search, which takes you to a search results page, with a search form on it, however you want to this form to be blank / unset.
There is no simple way to do this as its going against how the plugin is supposed to work but I’ll describe possible approaches:
1) as Trevor mentioned, on page load you can unset all the fields. you would beed to loop through all inputs and unset / clear the various fields. For checkboxes this would be setting
.prop('checked', false)
. However, I still think there could be some issues surrounding this if you have auto cont enabled.2) we do provide an api to manipulate fields/values, but this is PHP based – https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object
Take a look at the full fledged example, what you’ll want to do is empty the ‘defaults’ array under certain conditions (ie, check current page before applying your changes) so that nothing is set.
The only thing is, our search form is intrinsically tied to the current search query in order to provide auto count / dynamic fields, so there may still be some hiccups with this approach for what you want to do.
Im away until next week due to family matters so can’t test this theory myself.
As a final idea, we do have a reset field, which has the option to reset the form but not the query/results.
Its possible this piece of JS code might work for you, Ill have to dig it out on my return when Im back at my dev PC.
Thanks
Ross Moderator(Private) July 25, 2018 at 1:28 pm #183441Hi Paule
I had a quick play and figured we can access the JS reset function:
var searchForm = {}; $('body').append("<button id='sfreset'>RESET</button>"); $('#sfreset').click(function(){ resetForm(); }); function resetForm(){ searchForm.resetForm(false); } $(document).on("sf:init", ".searchandfilter", function(e, data){ searchForm = data.object; });
This just appends a basic button demonstrating the functionality.
The only issue you’ll have is, if you are using “auto count”, although the form is cleared, the form is not fully reset, an the filters still have a relationship with the results (so the showing / hiding of options based on selections won’t update).
I think this is not what you were looking for, I’ll take this on board and see if we can add support for this in v3.
Thanks
-
AuthorPosts