Forums › Forums › Search & Filter Pro › Reset Button Functionality
- This topic has 5 replies, 2 voices, and was last updated 3 years, 12 months ago by Trevor.
-
Anonymous(Private) November 26, 2020 at 11:02 am #267905
Hi, how can I call the reset button functionality within a condition? Basically, I wanted to check if the category search term is present
_sft_category
then, I would like to reset the search query to be able to remove the_sft_scene_category
on search term.Thanks!
Anonymous(Private) November 26, 2020 at 12:55 pm #267925Hi Trevor,
Sorry, I think there was a typo on the category search term. I wanted to have an if statement that will check whether the search query has
_sft_category
. Then if that is true, I wanted to automatically reset the query to remove everything including the_sft_category
.Currently, I have this code as a start but was stuck on how to call the reset function.
global $searchandfilter; $sf_current_query = $searchandfilter->get(1184)->current_query(); if ( $sf_current_query->get_field_string("_sft_category") ) : // reset the search query here endif;
Thanks!
Trevor(Private) November 27, 2020 at 9:07 am #268012The problem, is that resetting the query will return the form to its original state, and the results to their default (all) state. So, in effect, what would happen is that, if a user selected a category, the form and results and reset to default.
I was trying to understand WHY you wanted to do this?
Did you want to remove the query string from the URL, or simply return the form to its default state, but leave the results still filtered?
If either or both of these, I am sorry, but that is not possible.
Anonymous(Private) November 27, 2020 at 11:27 am #268039Hi Trevor,
We are planning to have another taxonomy that we would like to include as search query, but if a user have that taxonomy as search query we would like to simply return the form to its default state. But of course we wanted the reset to trigger after a new search query is being added.
Trevor(Private) November 27, 2020 at 3:09 pm #268074I am not entirely sure how you envisage that. I assume you have two fields in the form. Are you meaning that if the user selects a certain taxonomy term in one field, the other field then needs to set a certain value, and clear the choice the user makes?
If that is what you want, I am not sure a reset is needed, or even the best solution. Instead, it might be best to have Auto Submit OFF, add a submit button to the form, and then create some JavaScript that monitors the field to see a certain choice has been made, and if it is, then reset that one field, and set the required value on the other field, then the user can submit the form as usual with the button, or indeed you could have the javascript trigger the submit button for you.
That javascript would be custom and would have to be written by you. To trigger the submit, using JavaScript like (assuming the form has an ID of 1234) this:
$('.searchandfilter[data-sf-form-id="1234"]').submit();
-
AuthorPosts