Skip Navigation

[Resolved] Require the Location Field, if it’s empty and a distance is submitted to the search query

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

Problem:

Assume a View, where we display a Maps with Markers.
The View has a Custom Search by distance.

When we use this Search, the "intuitive" workflow is to first enter a "distance from" value.
Then, we would choose the "KM/MI" selector and finally enter a location.
Then, we would submit the search and get results.

This is fine as long the View is not updated by AJAX.
As soon you activate "AJAX results update when visitors change any filter values", entering as much as "100" in the "distance from" field, will trigger the search.

But, we did not yet enter a "Location"!
Our expectation here would (technically) be a "No results found" or at least a "This field cannot be empty" warning and no results triggered yet.

Solution:

Toolset does not have a sense of "combined" filter controls.

This means that the sentence "AJAX results update when visitors change any filter values" means literally that: when any control changes its value.

That works for the distance and also for the location.

We might be able to introduce such a concept, but it will demand time and planning.

We suggest adding your voice for this feature to https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

This support ticket is created 6 years, 10 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 12 replies, has 2 voices.

Last updated by Beda 6 years, 5 months ago.

Assisted by: Beda.

Author
Posts
#619021
screenshot.6.jpg
screenshot.7.jpg
screenshot.5.jpg

I am trying to:

Integrate distance search in my site, where the user can select the search radius.

Link to a page where the issue can be seen:

hidden link

I expected to see:

2 posts near Rust, which is within 100 km to Vienna shown on the map.

Instead, I got:

Nothing is found and the map also shows a post in Ireland.

The filter controls set URL parameters, but only toolset_maps_distance_center is actually used. toolset_maps_distance_radius is ignored and the fixed distance in the Query Filter is always used. The Query Filter does not offer any possibility to set the URL parameter to be used, except the center (see attached screenshot).

When I set the distance in the Query Filter to 100 instead of 5, the filter works and the 2 posts are shown correctly. But this makes the filtering controls completely useless. It would be necessary to be able to set the radius and the distance unit URL parameters in the Query Filer too.

I wonder how this could have ever worked for anybody.

#619336

This works fine for me in my local and online tests (for reference, hidden link)

It seems the URL parameter on your install is not respected.

I need to see the query generated and narrow down why this may happen.

I am relatively sure that if you remove the plugin and settings of "WP Google Map Pro", this issue may be gone.

You should never use 2 Google Maps services on the same install.

Can you confirm that this is a compatibility issue as I suspect?

In that case, I'd need a copy of the Plugin conflicting, and some steps to replicate the issue.
But I believe we discussed that already in another thread of yours, where we will try to contact the plugin's authors.

Let's see if this is the same issue source.

If not, I'd need a copy of the site if possible, to debug this locally.

#620061

Your View ("Filter Posts") seems to query native Posts.

There are three native Posts in the list, each with an address, 2 of them in Austria.

Both Posts are returned fine in the Post List here:
hidden link

But, the third post is as well present in the loop no matter the search.

All URL parameters are present:
toolset_maps_distance_center is Vienna
toolset_maps_distance_radius is 100
toolset_maps_distance_unit is KM

The query is correct; the results are incorrect.

The thing here is, you use a particular way to add the search and the map as results.

When you display a Map with markers, you must insert this in a View.
But, the map ShortCode is completely missing from this View.
Instead, only the marker is added, and the map is missed completely

In the second inserted View there is again an Address search field.

I have set up a View for you (Toolset Test View) where you can take reference how to construct a Custom Search with results plotted as markers on a map and a list of posts.
This works, if you insert it into the same page as your View and for example search for the same (100 km within Vienna):
hidden link

I assume since you nested 2 Views with the same query, and no map as far I see, the Query conflicts and falls back to all results.

Can you confirm that with my new view the issue is solved?

#620106
screenshot.9.jpg
screenshot.8.jpg

I tested your view and it does not work for me! This is really strange.

The map is there in my view, but as I want to show it in an extra column at the side, I put it in the "Filter and Loop Output Integration Editor" instead of before the loop, which works perfectly well for any other filter.

I use a separate view to show the posts at the suggestion of Minesh as a solution for the problem, that the pagination, when in the same view as the map, acts as a filter too, only showing the posts in the current page on the map. But I do not want this in this page. The map should always show the filter results and the pagination is only used to browse through the filtered posts. I am not happy about this workaround anyway, as there will be a performance penalty, when there are more posts, as the database will be queried 2 times. It would be much better to have a pagination option to toggle the behavior of the pagination control between filtering the posts and not filtering them.

But this sub view also works perfectly well, if the filters are set the same as in the parent, for all other filters.

I put in the map in front of the loop, as in your example and as it would be the normal thing to do and also commented out the sub view, so it can not have any influence. And it still does not show the correct result on the map. If I use "Rust, Austria", which is less than 5 km from two of the posts, everything is OK.

So it must be some bug in the distance filter. Also: Why is there no possibility to set the name of the URL parameter for the radius and the unit, while you can set the one for the center. You can set all 3 parameters in the control (and I assume they should be exactly the same)! So the 5 km or whatever is set in the filter definition is used and the URL parameter ignored. I confirmed this by setting it to 100 instead of 5 and suddenly the Vienna filter worked. This is a clear indication, that the radius URL parameter is ignored! And most probably the unit would also be ignored.

The filter overview says "Show posts within 5km radius of address/coordinates provided using toolset_maps_distance_center URL parameter" and this is exactly how it behaves for me.

PS:

I tried it again by setting the distance first and then pasting in the coordinates 48.1778847, 16.3629612 (Vienna) and then clicking on the distance again to make the filter start filtering (if I press enter after pasting the coordinates, they field is empty and nothing happens!). This works also in my view with the map on the side. The only thing is, that I also tried a few times before and it did not work at all!

It still does an empty result in the sub view, though the sub view gets all the URL parameters and the filter is set the same. And this works, when I search from Rust within the 5 km.

I call this very inconsistent and buggy behavior!

#620117
screenshot.11.jpg
screenshot.10.jpg

Now it also works with addresses, but only rust is also filtered correctly on the sub view. If it is not supposed to work with sub views, why does it work, if it is within 5 km?

#620147

Let's go step by step, and one issue a ticket.

I tested your view and it does not work for me! This is really strange.

Can you try this (In the View I created):
- first set the location (Vienna, then choose from the autosuggest)
- Now AJAX will kick in - let it do
- Now, choose 100 km instead of 5

That works, right?
I believe I can also confirm, on your site, that if you do it the "intuitive" way (means first you set km, then location), it seems to fail, while if you do as above outlined, it works.

That can be due to a BUG we have in Maps which does not appear consistently on all browsers.
https://toolset.com/errata/distance-filter-on-safari-loses-focus-for-location-input-field/

Now, first, we need to narrow down the correct functioning in a simple View where a Map is inserted the correct and suggested way.

After, we can analyse how to produce the output you wish - but as the current setup is, this cannot work.
The Map is inserted nowhere alike suggested.
The Map and marker have their expected place because the View's Loop is not just a raw return statement, but it wraps several HTML around the actual loop and its output layout.
So, if the map is not where it's "supposed to be" we may get into unexpected results.

We can analyse this later, as for now, I still have a different result locally - mainly we need to find out what breaks this search on your site.

For this I was about to deploy the package shared here:
https://toolset.com/forums/topic/distance-search-uses-fixed-radius/#post-619396

But, I do not have any access it seems.
It returns an XML response, those Links, whereas it tells me I have no access.

Can you elaborate on the usage of those links?

Thank you!

#620166

The steps worked, though after entering the 100, I have to be careful not to press enter, as would be intuitive (this would submit the form by inserting the current location). To make anything happen I have to click outside of the form somewhere on the page.

Then it works, but no normal users would ever understand this.

When I put the map where it is supposed to be, it does not make any difference, as I said. But I will just accept it as you say.

I really appreciate how hard you try to help me and will cooperate with you to solve the problem, though I am pretty sure, that I will just skip using the distance filter as it is now. It is not more than a nice-to-have and the UI is not intuitive, even if it would work as expected. And everything else works after all.

The links should give you access to a backup of my site, but they are expired. I can send you links to the latest backup, if you want to install it in a private message and also the password required for restore. It should be easy to do. But for now I am almost late for a doctors appointment. I can do it right afterwards in 2 hours.

Thank you very much for your support.

#620174

Great, I enabled the private answers again.
I will be back only tomorrow, please can you allow the files to stay online until I confirm back here?

I will narrow down the issue and suggest the appropriate fixes to the developers - and yes, I agree that the GUI produced on the front end lacks satisfactory customization possibilities.

And - even if it works as I outlined, that was just to confirm that we see the same.
I 100% agree that this is not how it's supposed to work, and since I cannot replicate this yet locally, I will use your duplicator to do that.

I am quite sure I will be able to find how to produce the issue on a clean install afterwards, which will enable us to fix this problem for good.

I will also try our patches, and develop version, directly on the package you will submit to me, as there has been development works in exactly that area of the feature.

I will do my best to present you either a proper workaround that makes sense or a timely fix/erratum for this issue.

I always appreciate your patience with us.

#620247

Thanks.

Private message enabled again for you to supply the links in the morning.

#620558

OK, this is due to the update of Toolset Maps 1.4.2

If you downgrade to 1.4.1 it works fine (but obviously this will bring back some issues)

This is the only workaround I can offer right now.

I can replicate part of the BUG, not all thou.

Something is additionally stripping the URL parameter value on your site.
Wien, Österreich becomes "wien".
That is wrong, and not happening locally.

But locally, I can see the issue that you also see:
Query by 100 KM from Wien, and even if Wien stays "Wien, Österreich", it does show all results unless I reload the View.

Hence, another workaround should be to not use AJAX search update.

I escalated this problem because there are several small detail problems too.
Like for example, if you choose 100 km the view already updates (if using AJAX)
Logically I did not yet set a location, hence what to expect?
Actually, I would expect some error, or some message, that I need to specify a location too.
But nothing happens.

If you now also add the location you get different results if you press enter or just outside the field.
All this is not consistent and makes a poor impression that I will try to escalate with some priority.

Thank you for your patience on this.
You can delete your copies if you want.

#620650

Thank you very much for the update.

Can you use the local installation for debugging the incompatibility too?

What shall we do about the problem of the sub view not recognizing the URL parameters, though the filter is the same. It works with the other filters after all.

Also why does the distance search work, if I use Rust as the center (where the default 5 km would be OK). Then also the sub view shows the correct result.

Shall I make an extra feature request about the pagination filtering the map results? You suggested something like this in one of the earlier posts.

#625300

I created 2 usability issues internally, the first is to unify and fix all behaviour and misbehaviour on AJAX updated Distance Filters.
This includes the issues with the differences of enter/click, the wrong loading of the result if the distance is filled first and then only the location, and as well it includes some other issues I reported like that we should require a location if only a distance is submitted.

For now, the only proper solution I see is to not use AJAX.
Then, the user will usually fill and submit that form with all information filled out and then the results and behaviour are correct.

If you want to proceed using AJAX right now, the only I can think of is a detailed instruction on the Front End to the end user on how to properly use this search, but that is most likely not what you want.

Related to the subview, I assume this fails because the URL parameters/results are actually not correct, as we found out during the process of this ticket, hence I assume this will work once the issue is solved, or you update manually (not with AJAX).

We cannot handle several different issues in one ticket, hence I suggest that for each concern or request, you would open a new ticket.
Please acknowledge that the bugs reported here, as said will have an effect once solved or workaround-used.

When you disable the AJAX update, these issues should be gone.

Once we fix the problems, you could then re-activate AJAX.

#924956

Toolset Maps 1.5 solves now this issue:

The Toolset Maps distance search on a map, when updated by AJAX "AJAX results update when visitors change any filter values", will work only if:
- you first enter the location, then the distance, and never hit ENTER but always just click on the Fields.
- you enter first distance OR location and then the other, but press ENTER each time.

If you, for example, happen to enter the distance first, then you CLICK (not enter) into the Location field, and fill that out too, and then click outside that field or even just pick from the auto-suggested location (it still/already triggers the search), the results will be not properly updated (all entries are shown instead).

So in the broken version of Maps you could use the Distance Filter with "AJAX results update when visitors change any filter values" working only if the user is perfectly aware to use ENTER each time, or you add a Submit button.

This is now solved in 1.5
The usability issue/request about "Require the Location Field, if it's empty and a distance is submitted to the search query" is still under review.
This last remaining "issue" means, that the sentence "AJAX update when change in any filter value" literally means: when ANY control changes its value.
That works for the distance and also for the location.

We might be able to introduce another concept to adjust that, but it will demand time and planification.

Hence, we can close this ticket if you agree.