148 Posts
3 years ago

Hi dear Community,

I am using the field for a distance search. It works well. But I have a problem with the input: when typing something into the field, Google auto suggestions appear and I can choose a location from the list. The search works. But typing a location and then pressing Enter without selecting a location from the list do not work. The search only works if I select a location from the list. Any idea?

Kind regards

Get a VIP membership
148 Posts
3 years ago
Level 1

I have no idea why but it seems to work with the code from here (little modified) adding in the plugin file after:

var autocomplete = new google.maps.places.Autocomplete($el,{'.$opts.'});

var pac_input = document.getElementById("geo_search");

(function pacSelectFirst(input){
var _addEventListener = (input.addEventListener) ? input.addEventListener : input.attachEvent;

function addEventListenerWrapper(type, listener) {

if (type == "keydown") {
var orig_listener = listener;
listener = function (event) {
var suggestion_selected = $(".pac-item-selected").length > 0;
if (event.which == 13 && !suggestion_selected) {
var simulated_downarrow = $.Event("keydown", {keyCode:40, which:40})
orig_listener.apply(input, [simulated_downarrow]);

orig_listener.apply(input, [event]);

_addEventListener.apply(input, [type, listener]);

if (input.addEventListener)
input.addEventListener = addEventListenerWrapper;
else if (input.attachEvent)
input.attachEvent = addEventListenerWrapper;


var autocomplete = new google.maps.places.Autocomplete($el,{'.$opts.'});

Get a Book for SEBLOD