Skip Navigation

[Resolved] Reset filters when search is changed

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by Minesh 6 years ago.

Assisted by: Minesh.

Author
Posts
#1210562

Hello,

I have a custom search with Text search and 3 filters.
I would like to reset filters when text search changes.
How is this possible please?

Best regards,
Ferdinand

#1210587

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - views offers the shortcode [wpv-filter-reset] that will help you to reset your filters.
=> https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-filter-reset

But this is not something will run when every time you change the text search keywork. This needs to be handled using some custom javascript.

#1210600

Hello,
thaks for answer.
I know there is a reset option, but this will reset search as well(not only filters).
So there is no possibility to reset everything but search text?

If not is there a function(for custom javascript) that i could call and that will reset only what i want.

Could you please suggest an approach how to handle this?

Best regards
Ferdinand

#1210601

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - you can use the jQuery/javascript to reset the search box input value when it get focus.

For example - add following code to your view's "Search and Pagination" section's JS box:

jQuery(document).ready(function($){

jQuery("input[name='wpv_post_search']").focus(function() {
    $(this).val("");
});

});

#1210644

If I'm not mistaken this will erase search text input on focus.

I'll play around with this and see.
What i need is to trigger it on submit not on focus. I hope it won't be a problem, but i'm afraid that it will trigger multiple reloads of search.

I'll see tomorow. Thank you and please leave this issue opened for now. I'll close it tommorow if I don;t need any more assistance with this.

Thanks again.

#1211026

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

If I'm not mistaken this will erase search text input on focus.
==> Yes - that is correct.

What i need is to trigger it on submit not on focus. I hope it won't be a problem, but i'm afraid that it will trigger multiple reloads of search.
==> Yes - thats correct as well, on submit is not the recommended way.

#1211222

Hello,
so I figured out a solution.
This does what i wanned. Triggers more or less on submit and triggers only one ajax call.
There was a little mistake in your code. Due to fact that you replace input and selects tags on ajax(don't know why), listener will be removed so i added listeners on form tag which is not replaced.

I still have one issue. It's a small one. After I errase values, selects are just empty(not default label) and it appears after data are loaded. Is there any way to prevent this?

This is my code(in case anyone needed this functionality :))

jQuery(document).ready(function() {
  jQuery(".wpv-filter-form").on('keydown', "[name='wpv_post_search']", function(event) {
    if(event.which == '13') {
      removeFilters();
    }
  });
  jQuery(".wpv-filter-form").on('click', ".search-button", function(event) {
    removeFilters();
  });
});

var removeFilters = function() {
  jQuery("[name='wpv-collection']").val("");
  jQuery("[name='wpv-producttype']").val("");
  jQuery("[name='wpv-style']").val("");
};
#1211287

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thank you for sharing the code. Can I have problem URL so that I can see how select fields displayed?