lundi 23 mai 2016

Ember validation is not working with ember-cli-materialize

I have a small form with several input fields. One of them is a computed field and I wan't to make some validation on it. Therefore I am using ember-validations, because it should work out of the box with ember-materialize. This is the input hbs template:



In the controller I have setup the observer like this:

import Ember from 'ember';
import EmberValidations from 'ember-validations';

export default Ember.Controller.extend(EmberValidations,{
  warrantyUntilComputedDidChange: Ember.observer('model.warrantyUntilComputed', function() {
    const errors = this.get('errors');
    console.log("hier");
    console.log(this.get('model'));
    let messages = [];
    if (!Ember.isPresent(this.get('model.warrantytUntilComputed'))) {
      messages = ['This'];
    }
    errors.set('warrantyUntilComputed', messages);
  })
});

When I look into the console I see that this method is called only once. (If I have a console.log inside the method)
How can I fix this observer/validiton?




Aucun commentaire:

Enregistrer un commentaire