Hi I am using Ember place autocomple addon I want to modify below two behaviors of addons. 1. My places autocomplete textbox is inside a form. when I press enter key while filling autocomplet textbox form gets submitted.(even if I have not selected option from google suggestion) 2. if no places is selected and enter is pressed the first option should get selected.
I though extending the addon will help. so i tried the below code avoid submission of form but it didnt work.
import Ember from 'ember';
import PlacesAutocompleteField from 'ember-place-autocomplete/components/place-autocomplete-field';
export default PlacesAutocompleteField.extend({
init(){
this._super(...arguments);
},
keyUp: function(e){
if(e.keyCode === 13){
e.preventDefault();
}
},
actions:{
placeChanged(){
this.toggleProperty('PLACE_CHANGED_FLAG');
}
}
});
Alternate way I tried was just to see if it works I added this
google.maps.event.addDomListener(this.$().children()[0],'keyUp',function(){
console.log('keyup...');
console.log(e);
});
inside the addon it self. so the new code is
autocompleteCallback: Ember.on('didInsertElement', function() {
this.getAutocomplete();
this.get('autocomplete').addListener('place_changed', () => {
this.placeChanged();
});
google.maps.event.addDomListener(this.$().children()[0],'keyUp',function(){
console.log('keyup...');
console.log(e);
});
}),
still it doesnt work Jsbin enter "d" donot select any suggestion and press enter.
UPDATED as @GJK suggested using $(inputElement) works. Direction to choose suggestion on pressing enter if user does not choose anything
$(inputElement).keydown((event) => {
if (event.keyCode === 13) {
let o = $('div.pac-container').children().first();
event.preventDefault();
}