Skip Navigation

[Resolved] Toolset Map is not instantiated when there are no results in AJAXified Search

This support ticket is created 3 years, 8 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/Karachi (GMT+05:00)

This topic contains 5 replies, has 2 voices.

Last updated by smileBeda 3 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#1990243

This is already reported but unfortunately not as precise as it could have been reported:
https://toolset.com/forums/topic/empty-search-results-deletes-map/

The situation in that ticket is logically solved by putting the map outside the no-items-found section, which is obvious as a requirement.
However there is more to it.
First, the issue happens only with AJAX searches and second, it is not always the case that a Map is in the loop.

Consider that you want a structure where you display the Map, then the Search inputs, and then the loop (stacked below each other)
In this case your only choice is to insert the Map in the Filter Editor, which is perfectly possible and working fine - as long there are some results.

When there are no results, the entire Map is hidden (the HTML is still there, but contents of it are stripped)
This is most likely because the code that instantiates the map (JS) is not fired when there are no results, which is wrong, since the map should still display when there are no results, just without markers.

The simple replicable minimal steps are:
1. Create a View with a Map and search with AJAX update when values change
2. Make it so that the search inputs appear after the map (this means, you must include the map somewhere in the Search editor before the actual search fields)
3. Load the View in the front end and trigger a search that does not display the map

The map disappears.

Do the precise same with a Search that updates without AJAX and it is solved.
This is the main reason for it to be a BUG, I think, since the search and map should work the same wether AJAX or no AJAX is used.

So I think the easy solution here is to re-fire the map when the AJAX event happens
Can you please A) Let me know what JS Function I need to re-fire to re-instantiate the map after AJAX events and B) probably ask the developer to actually fix this and make it default, as it is not expected we need to "fix" Views with ajax event hooks, those are rather intended to be used when we want to fire custom elements again.

Thanks!

#1991841

Hi Beda,

Based on your report, I can reproduce the behavior that the map is not instantiated in the case of AJAX search that produces no results, but for me, the map doesn't disappear. It keeps showing the markers from the last query that showed any results.
(and yes the map's shortcode is placed in the "Search and Pagination" section)

Here is a screencast: hidden link

I can report this inconsistency between the AJAX and non-AJAX view's handling of the "no results found" case to the concerned team and ask for a JS function to instantiate the map after we've sorted this difference.

regards,
Waqar

#1992219

Yes please
Wether the map disappears or still shows results from the previous query- actually both is wrong.

What should happen is what happens when you do this without Ajax - a map without markers and centered in the default location (generally somewhere in the ocean)

Also I’d be really needing the js method to reinit the whole thing so i can fix this in the current project.

Thanks!

#1993089

Hi Beda,

Thanks for confirming and I've passed this report to the concerned team.

Since I couldn't find a function that can re-initiate the map in this case, I've also requested some guidance in this matter as well.

I'll keep you updated through this ticket.

regards,
Waqar

#1993343

Thank you for waiting.

Nigel helped me with this code, that re-initiates the map when the search results have been updated through the AJAX:


jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
  WPViews.view_addon_maps.reload_map( 'map-1' );
});

Note: Please replace "map-1" with your map's ID.

Since this happens only with very specific requirements and steps, I hope we can agree that the code snippet should be enough without the need for any further escalation.

#1993669

Excellent, tested and confirmed it works.
So simple - thanks Waqar and Nigel for sharing the method.

This should be IMO just working out of the box, after all Maps is inbuilt part of Toolset but having a solution like this is also good for me.

I am not sure exactly what will happen once (if, which doesn't seem to be the case) Toolset incorporates that in core, but I guess I will find out 😛

Thanks again!