Skip Navigation

[Resolved] Limit the radius field in distance search

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 2 replies, has 2 voices.

Last updated by robertN-6 6 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#605929
SS -  2018-01-13 at 12.05.42 AM.png

Tell us what you are trying to do?
I would like to limit the control people have for the radius field in the distance filter. On the front-end this is the "Show results within" input box. I would like to know how to do the following and pick whichever is best for my case
A) set a max number
B) make it hidden so once I set the default in the back-end it can't be edited.

My code is as follows:
<div>[wpv-filter-start hide="false"]

<div class="row">
<div class="col-sm-9">[wpv-control-distance default_distance="100" default_unit="mi" compare_field="location" distance_center_url_param="toolset_maps_distance_center" distance_radius_url_param="toolset_maps_distance_radius" distance_unit_url_param="toolset_maps_distance_unit"]</div>
<div class="col-sm-3">[wpv-filter-submit output="bootstrap"]</div>
</div>

[wpv-filter-end]</div>

#605957

Within the GUI, you could set a default distance, and within the URL parameters, you could manipulate them with some JS on submit so even if the values are higher than you wish, the JS would revert them back.

Not the nicest solution.

I think the best would be to add a JS hook to the field and limit it with JS to the desired number, so you avoid the wrong values to be input at all.
There are several ways to achieve this:
https://stackoverflow.com/questions/18156824/restricting-an-input-box-to-only-numbers-0-9
https://stackoverflow.com/questions/469357/html-text-input-allows-only-numeric-input
https://stackoverflow.com/questions/1384074/limit-input-box-to-0-100

You could hook your JS to the Field from Toolset Maps:
toolset-maps-distance-value

Easier is the second task, to hide the form and pass a default value.
You simply pack the HTML portion of Filter into a hidden div, for example.
Pressing the Submit Button wills till get this URL parameters needed.

But - if you want to hide it, you can also simply add a Query filter only, without HTML Filter.
The View will always show only those results set in the Query Filter, where you can as well choose the distance and a source.

Please let me know if these possibilities help.

#608297

Thanks