Sauter la navigation

[Résolu] HTML Accordion with elements and AJAX filter updates

This support ticket is created Il y a 3 années et 8 mois. 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)

Ce sujet contient 1 réponse, a 2 voix.

Dernière mise à jour par Minesh Il y a 3 années et 8 mois.

Assisté par: Minesh.

Auteur
Publications
#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:

lien caché

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:

lien caché

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

Les langues: Anglais (English )

Fuseau horaire: 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