Skip Navigation

[Resolved] HTML Accordion with elements and AJAX filter updates

This support ticket is created 3 years, 7 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.

Our next available supporter will start replying to tickets in about 2.37 hours from now. Thank you for your understanding.

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 1 reply, has 2 voices.

Last updated by Minesh 3 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#2036107

Hi guys,

A few years ago, Shane assisted me with the Bootstrap accordion solution and AJAX filter events. The issue was that using filters collapsed the Bootstrap accordion after filter updates. The snippet works nicely and I am very thankful for it:


jQuery( "#filter-button").click(function() {
  if(window.state === undefined){
       window.state = true
  }
 else{
       window.state = !window.state
  }

});
jQuery( document ).on( 'js_event_wpv_parametric_search_form_updated', function( event, data ) {
    /**
    * data.view_unique_id (string) The View unique ID hash
    * data.view_changed_form (object) The jQuery object for the View form after being updated
    * data.view_changed_form_additional_forms_only (object) The jQuery object containing additional forms from other instances of the same View inserted using the [wpv-form-view] shortcode
    * data.view_changed_form_additional_forms_full (object) The jQuery object containing additional forms from other instances of the same View inserted using the [wpv-view] shortcode
    */
if (window.state === true){
  jQuery('.collapse').collapse('show');
}
  else{
      jQuery('.collapse').collapse('hide');

  }
  
  jQuery( "#filter-button").click(function() {
  if(window.state === undefined){
       window.state = true
  }
 else{
       window.state = !window.state
  }

});
});

I have realized recently that there is an elegant and very simple HTML solution for accordions, which has several advantages: using <details><summary> elements. Browser support is very good:

hidden link

However, there is of course the same issue that the accordions close after filter updates... I tried to adapt the snippet but I failed...
I would be very grateful if you could assist me.

Here is an example site that uses several <details><summary> accordions and another WordPress AJAX filtering plugin:

hidden link

The accordions work very nicely and don't use Bootstrap, but pure HTML... I just can't figure out how they prevent accordion collapsing after filter updates.

Greetings,
Tom

#2036423

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Toolset Views/Blocks offers the "Frontend Events" that you can use to add a call-back event after view is updated using Ajax.
=> https://toolset.com/documentation/programmer-reference/adding-custom-javascript-code-to-views-that-use-ajax/

If you are using Toolset Blocks - you can find the Frontend Events button with Custom JS section.:
=> https://toolset.com/course-lesson/adding-custom-javascript-to-views-templates-and-archives/#steps-for-adding-javascript-to-a-view