ENH: Collections (update) (#40)

Fixes #36
This commit is contained in:
Matthew Ryan Dillon 2017-10-07 17:37:24 -07:00 committed by GitHub
parent e1abc5e4cb
commit f41f4caccd
17 changed files with 221 additions and 77 deletions

View file

@ -1,5 +1,6 @@
import Ember from 'ember';
import Changeset from 'ember-changeset';
import lookupValidator from 'ember-changeset-validations';
const { Component } = Ember;
@ -7,6 +8,7 @@ export default Component.extend({
init() {
this._super(...arguments);
const model = this.get('model');
this.set('changeset', new Changeset(model));
const validations = this.get('validations');
this.set('changeset', new Changeset(model, lookupValidator(validations), validations));
},
});

View file

@ -0,0 +1,14 @@
import Ember from 'ember';
const { Component, computed, get, isEmpty } = Ember;
export default Component.extend({
classNames: ['form-group'],
classNameBindings: ['isValid::has-error'],
isValid: computed('changeset.error', 'property', function() {
const changeset = this.get('changeset');
const property = this.get('property');
return isEmpty(get(changeset, `error.${property}`));
}),
});