Skip Navigation

[Resolved] I want to add CSS class to AJAX filter, but the class is deleted when the results are updated

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to add a CSS class to a filter in my custom search View, but when the results are updated with AJAX the class is removed.

Solution: Use the front-end events button in the Search and Pagination panel's JS editor to re-apply your custom CSS class after the filters or results have been updated.

Relevant Documentation:
https://toolset.com/documentation/user-guides/front-page-filters/advanced-settings-custom-search/

This support ticket is created 5 years, 6 months 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Junichiro Taira 5 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1236624
img.jpg

I created this with view plugin.
As you can see, there is a filter and view template section (AJAX).

I want to change color when the viewer selected a radio button like the attached image. However, AJAX reloads filter section and can not be added custom class.

Here is JS I added.

jQuery(document).ready(function($){
$(document).on('click','.wpv-filter-form .radio', function(){
$('.radio').removeClass('active');
$(this).addClass('active');
});
});

Would you help me?

#1236681
Screen Shot 2019-04-28 at 11.46.17 AM.png

Hi, you can use the Frontend events button in the JS panel under the Search and Pagination editor to create event hooks for search events and pagination events, including search form updates and search results updates. You can call your own JavaScript within the event hook callbacks as needed.

#1236770

Sorry. I've never used this. Would you teach me how to do it?

#1237034

Depending on how your View is set up, you may need to use more than one event listener to achieve the effect you're looking for. Click the button, then select the event. The system will create a code template with an event listener already set up for you, something like this:

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
	/**
	* data.view_unique_id (string) The View unique ID hash
	* data.layout (object) The jQuery object for the View layout wrapper
	*/
	
});

Inside the callback function, you can add your own custom code to be executed when the event is triggered. You should use the namespace jQuery instead of $ inside your callback function. The comments inside the callback describe a few of the important attributes of the callback parameters that are available to you.

#1238915

My issue is resolved now. Thank you!