[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.
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?
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 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?
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 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.
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.