I had a similar issue (that anything in the given field should be valid Google Maps address), and built a solution inspired from this one, that may help you. The idea is :
- when the user does something else than click on a Google Maps suggestion
- trigger the event to move focus on the first suggestion
- trigger the event to select it
I copy the result for my own code (with Jquery) :
//// Ensuring that only Google Maps adresses are inputted
function selectFirstAddress (input) {
google.maps.event.trigger(input, 'keydown', {keyCode:40});
google.maps.event.trigger(input, 'keydown', {keyCode:13});
}
// Select first address on focusout
$('#content').on('focusout', 'input#xxx__zzz', function() {
selectFirstAddress(this);
});
// Select first address on enter in input
$('#content').on('keydown', 'input#xxx__zzz', function(e) {
if (e.keyCode == 13) {
selectFirstAddress(this);
}
});
For me it works, I hope it helps !