Skip Navigation

[Resolved] AJAX search filter update closes an accordion

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

Problem:

The issue that this user is having is that their Accordion is closing each time there is an AJAX action.

Solution:
You will need to make use of callback functions to open the accordions. The reason why this is happening is because you have the live filters enabled, so your view is filtering as you select an option.

This means that this entire section is getting refreshed with a new div and the javascript that is responsible for the accordion this the accordion is the same.

So you will need to callback the function in order for you to have it open again.

If its the bootstrap accordion then add this to your JS section of the filters section of your view.


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
    */
 jQuery('.collapse').collapse()
 
     
});

This should reopen the Accordion after the results of your view is updated.

This support ticket is created 5 years, 5 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 8 replies, has 2 voices.

Last updated by johnB-43 5 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#1283425

I am trying to:
Create an AJAX search with filters. The filters are meant to be hidden by default and open with an accordion.

Link to a page where the issue can be seen:
hidden link

I expected to see:
When I update a filter, I'd like the refreshed page to keep the advanced search accordion open

Instead, I got:
The accordion closes with every filter update, which is very frustrating as typically people will want to apply more than one filter.

#1283513

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi John,

The best way to work around this is to set your view to only filter once the search button is pressed.

This would mean that you would need to change the setting in your views custom search settings section and then add the search button itself.

Please let me know if this helps.

Thanks,
Shane

#1283943

Thanks! I'd rather avoid that if possible, as it adds more clicking. Is there perhaps some other alternative, something else than using an accordion perhaps?

#1284097

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi John,

You will need to make use of callback functions to open the accordions. The reason why this is happening is because you have the live filters enabled, so your view is filtering as you select an option.

This means that this entire section is getting refreshed with a new div and the javascript that is responsible for the accordion this the accordion is the same.

So you will need to callback the function in order for you to have it open again. Could you let me know where you got this accordion code from ?

Thanks,
Shane

#1284181

Thanks for the explanation. This may be a naive question, but would it not be possible for the AJAX refresh to only refresh the view and not the filter? They are in separate containers, couldn't the <form> just not get refreshed when the option is changed?

In any case, the accordion is an adapted bootstrap one: hidden link.

I imagine I can call on the JS in the view's Custom Search Settings - but won't that lead to the accordion closing and opening again in the process?

#1284281

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi John,

Add this to your JS section of the filters section of your view.

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
	*/
 jQuery('.collapse').collapse()

	
});

If this doesn't work then there is a frontend events button on the JS editor that you can add other frontend events callback. All you have to do is add jQuery('.collapse').collapse() to the appropriate one.

Thanks,
Shane

#1287607

Thanks for the code. The problem is that now the page reloads with the accordion closed and then quickly opens it. I mean, it does the job, but just looks quite bad. If there is no better way to approach this, I might need to resign of the accordion after all, or think of some other way to filter the results.

#1287673

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi John,

Yes this is actually a limitation and what is going to happen.

Its because the function needs to be called back after the page has finished loading and the search was completed.

Thanks,
Shane

#1287859

Thanks! I guess I'll just find another way.
Perhaps this could be a feature request: an AJAX search that only refreshes the results, not the search filter.