Google Autocomplete - select first option on focus

2019-07-30 01:18发布

问题:

I have the following code:

var options = {
    types: ['(cities)'],
    componentRestrictions: {country: "pl"}
};
var input: any = document.getElementById('searchTextField');
this.autocomplete = new google.maps.places.Autocomplete(input, options);
this.autocomplete.addListener('place_changed', () => {
.....
});

$('#searchTextField').focusout(function (e) {
    $('.pac-container').find('.pac-item').first().click()
});

and the HTML:

 <input class="form-control" type="text" id="searchTextField" placeholder="City"/>

However, now, when user clicks out of the input, without seleciton, the place_changed event is not fired. How can I fire this event on focusout?