Skip Navigation

[Resolved] Custom search – need help figuring out what to target for custom JS

This support ticket is created 2 years, 2 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 8 replies, has 2 voices.

Last updated by Diego Walter Ricciardi 2 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#2294553

Tell us what you are trying to do?

I'm trying to figure out how to hide empty search dropdowns. I made a custom JS it works in itself but not how well inside WP.

Is there any documentation that you are following?

Not really, it's just custom JS code, I haven't found what I needed looking through toolset docs.

Is there a similar example that we can see?

an already working one: hidden link

What is the link to your site?

hidden link

So, the idea behind my JS is to use a foreach to target the select, see if they're empty or not if they are remove them.

The JS in itself works, as we can see in this fiddle: hidden link

And I cant make it work badly in WP, but I need a reliable way of hitting the length or values of the selects. As of right now .length works in the fiddle and doesn't work in WP, .value works in WP but then it also removes the unselected choices in other populated dropdowns.

#2295121

Hello,

You are using AJAX search feature, please try trigger your custom JS codes with JS event "js_event_wpv_parametric_search_results_updated", for example:

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
	*/
	// Here setup your custom JS codes
});
#2295419

Hey!
It's still not working. I tried an example of the HTML (the actual one) in codepen and it works kinda, I guess it needs some polishing, but still, even using the jquery event doesn't work.

hidden link

#2295747

I've made it somewhat work.
The issues is as follows now since the triggers don't seem to be working:
First, the grid doesnt change when things are missing, if say X X X X Y X X it will only show a whitespace in Y. (should I be targeting a differente div? I'm targeting the grid cell already)
Second, even with the AJAX triggers, when you filter something all the removed grid cells come back, which is intended what's not intended is that the code doesn't retrigger and remove them again.

Any help would be appreciated

#2296035

According to our support policy, we don't provide custom codes support:
https://toolset.com/toolset-support-policy/

The JS event "js_event_wpv_parametric_search_results_updated" is triggered after you make a AJAX search
The JS vent Query(document).ready will be triggered after the page loaded, so you will need to trigger your custom JS codes twice:
- the page loaded
- user makes the AJAX search

Hope it helps

#2296551

I don't need code support, the code works perfectly. What I need is support in regards to Toolset.
I can't see how this is isn't solely related to Toolset blocks. I'm looking to know what to target, not for you to make the code for me.
As I've said even with the toolset triggers, the code doesn't refire.
I'm using both document.ready for the incial load and:
jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) for after the AJAX load but it doesn't retrigger.
In the previous toolset version, in Views and plain HTML without using Blocks, it was simpler to target html and have expected behaviour but now with blocks I cant tell what to trigger. Should I maybe change from Grids to Containers? Idk. But this is 100% related to toolset, if you want ignore the code, which works.

#2296557

The support policy:
"We cannot produce custom code solutions for you. When you need custom coding which extends Toolset functionality, we recommend contacting one of Toolset certified consultants."
I have made the code already.

#2298313

I have tried the JS event "js_event_wpv_parametric_search_results_updated" in my localhost with a fresh WP installation + the latest version of Toolset plugins, it works fine after the AJAX search results are updated, if you need more assistance for it, please provide a test site with the same problem, also point out the problem page URL and view URL, I can setup a demo for you.

#2298855

With the standard JS even didn't work, but with:

document.addEventListener("DOMContentLoaded", ejecutar);
jQuery( document ).on( 'js_event_wpv_parametric_search_form_updated', ejecutar);

at the end of the code, works like a charm.

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