lundi 7 novembre 2016

Ember: use this.get() in a validation function

I have a date validator for an input field:

export default Ember.Component.extend({
moment: Ember.inject.service(),
dateValidation: [{
    message: 'invalid date',
    validate: function(inputDate) {
      if (!inputDate) {
        return true; //allow empty date
      }
      return this.get('moment').moment(inputDate, 'YYYY-MM-DD', true).isValid();
    }
  }],
});

I use ember-moment to validate the date. Usually I use this.get('moment').moment(...) but in this function this.get() is not defined. I know that this refers to the function instead of my component, but how can I fix it? Using Ember.get() didn't worked for me.




Aucun commentaire:

Enregistrer un commentaire