lundi 16 novembre 2015

preventDefault in emberjs

Hi I am using Ember place autocomple addon I want to modify below two behaviors of addons. 1. When used in form on pressing enter form gets submitted (dont want this). 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);
    PLACE_CHANGED_FLAG: false
  },
  keyUp: function(e){
    if(e.keyCode === 13 && !this.get('PLACE_CHANGED_FLAG')){
      e.preventDefault();
    }
  },
  actions:{
    placeChanged(){
      this.toggleProperty('PLACE_CHANGED_FLAG');
    }
  }
});




Aucun commentaire:

Enregistrer un commentaire