Google Autocomplete Places API not triggering event on change via TAB

后端 未结 3 360
情话喂你
情话喂你 2020-12-16 07:10

Per the Google Autocomplete Places API documentation, the getPlace() call should return a Places object with all the location data, or, if that place doesn\'t e

3条回答
  •  清酒与你
    2020-12-16 08:11

    The following expands on @MrUpsidown's solution but tries to avoid messing with the user when they click on an item in the dropdown as mentioned by @Jkk.jonah

    // Trigger search on blur
    google.maps.event.addDomListener(document.getElementById("pac-input"), 'blur', function() {
      if (jQuery('.pac-item:hover').length === 0 ) {
        google.maps.event.trigger(this, 'focus', {});
        google.maps.event.trigger(this, 'keydown', {
            keyCode: 13
        });
      } 
    });
    

提交回复
热议问题