U
U
urfinjazz2015-09-27 23:59:48
JavaScript
urfinjazz, 2015-09-27 23:59:48

How to return false on autocomplete in google maps when pressing down key?

Hello!
You have to customize Google Maps to suit your needs.
Perhaps this question only applies to Javascript, not to the Maps API.
When using autocomplete, when you press the "down" key, the value from the list is substituted into the input. How to get rid of it?


...
if(e.which == 40) {
return false;
}
...

that doesn't help.
Help me please!
PS I catch the event

$('#id').keydown(function () { ... });

or
google.maps.event.addDomListener(input, 'keydown', function(e) { ... });

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
urfinjazz, 2015-10-25
@urfinjazz

So:

var input = document.getElementById('input');
autocomplete = new google.maps.places.Autocomplete(input);

google.maps.event.addDomListener(city_input,'keydown',function(e){
        if (e.keyCode == 40){
            google.maps.event.clearInstanceListeners(input);
        }
    });

just keep in mind that at this moment the autocomplete will be completely disabled,
you need to add a check for the state of the autocomplete (enabled / disabled) in the code, and
enable it again when necessary
new google.maps.places.Autocomplete(input);

R
Rikcon, 2015-09-28
@Rikcon

e.PreventDefault();
There is ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question