Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps autocomplete always select first item
    primarykey
    data
    text
    <p>I'm using Google Maps Places V3 autocomplete. I would like to have a functionality where if a user starts typing into the searchfield, the first item from the autocomplete drop down is automatically selected. </p> <p>Similar to the search function in Facebook. </p> <p>I already updated the Google maps autocomplete with the help of these 2 threads: </p> <ul> <li><p><a href="https://stackoverflow.com/questions/11388251/google-autocomplete-enter-to-select">Google Autocomplete - enter to select</a></p></li> <li><p><a href="https://stackoverflow.com/questions/7865446/google-maps-places-api-v3-autocomplete-select-first-option-on-enter">Google maps Places API V3 autocomplete - select first option on enter</a></p></li> </ul> <p>But I cannot find a solution for this new issue.... </p> <p>I posted my code here: <a href="http://jsfiddle.net/Chazz09/YfPv3/5/" rel="nofollow noreferrer">http://jsfiddle.net/Chazz09/YfPv3/5/</a> </p> <pre class="lang-js prettyprint-override"><code>$(document).ready(function(){ var pac_input = document.getElementById('searchfield'); // prevents enter key to submit form// $('#searchfield').keydown(function (e) { if (e.which == 13 &amp;&amp; $('.pac-container:visible').length) return false; }); // prevents enter key to submit form// (function pacSelectFirst(input){ // store the original event binding function var _addEventListener = (input.addEventListener) ? input.addEventListener : input.attachEvent; function addEventListenerWrapper(type, listener) { // Simulate a 'down arrow' keypress on hitting 'return' when no pac suggestion is selected, // and then trigger the original listener. if (type == "keydown") { var orig_listener = listener; listener = function (event) { var suggestion_selected = $(".pac-item.pac-selected").length &gt; 0; if (event.which == 13 &amp;&amp; !suggestion_selected) { var simulated_downarrow = $.Event("keydown", {keyCode:40, which:40}) orig_listener.apply(input, [simulated_downarrow]); } orig_listener.apply(input, [event]); }; } // add the modified listener _addEventListener.apply(input, [type, listener]); } if (input.addEventListener) input.addEventListener = addEventListenerWrapper; else if (input.attachEvent) input.attachEvent = addEventListenerWrapper; })(pac_input); $(document).ready(function() { function initialize() { var options = { types: ['geocode'], componentRestrictions: {country: "fr"} }; var autocomplete = new google.maps.places.Autocomplete(pac_input, options); } google.maps.event.addDomListener(window, 'load', initialize); }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload