Skip Navigation

[Resolved] Keep Views filters open if selected but closed if not selected

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

Problem:

I have used the Collapse-o-Matic plugin to allow Sectors (filters) to be opened and closed, however, I would like the filter to stay open is one of the filters is selected. I have added the collapse_init js to make them close on js_event_wpv_parametric_search_results_updated
Is there some other js I can use to close only the Sectors (filters) that are unchecked and keep open those that are checked?

So, for example, if someone opens the Biology sector and selects Bio-imaging, once the results are rendered, I need the Biology sector to stay open while the others close.

Solution:

There isn't such a built-in feature within Views plugin, it needs custom JS codes, I suggest you try these: when user submit the form, use js_event_wpv_parametric_search_results_updated to trigger an custom JS function, in this JS function, check if there is any option is selected, then opens the related sector.

Relevant Documentation:

This support ticket is created 6 years, 3 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 6 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#603519

Tell us what you are trying to do? I am using Views filters here: hidden link. I have used the Collapse-o-Matic plugin to allow Sectors (filters) to be opened and closed, however, I would like the filter to stay open is one of the filters is selected. I have added the collapse_init js to make them close on js_event_wpv_parametric_search_results_updated
Is there some other js I can use to close only the Sectors (filters) that are unchecked and keep open those that are checked?
So, for example, if someone opens the Biology sector and selects Bio-imaging, once the results are rendered, I need the Biology sector to stay open while the others close.

What is the link to your site? hidden link

Thanks for your help!

#603653

Dear Laura,

There isn't such a built-in feature within Views plugin, it needs custom JS codes, I suggest you try these: when user submit the form, use js_event_wpv_parametric_search_results_updated to trigger an custom JS function, in this JS function, check if there is any option is selected, then opens the related sector.

#603862

Thanks for this info. A friend helped me figure it out. If it helps anyone else, here is my code:

`jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function() {

jQuery(".collapseomatic_content").each(function() {
var this_section = jQuery(this);
var any_checked = this_section.find("input[type='checkbox']:checked").length;

console.log(any_checked);

if( any_checked > 0 ) {
this_section.show();
} else {
this_section.hide();
}
});
});`

#604168

Thanks for sharing the codes.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.