-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (41 loc) · 1.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import DS from 'ember-data';
import Ember from 'ember';
import BufferedMixin from 'ember-buffered-proxy/mixin';
import EmberValidations from 'ember-validations';
var validationProxy = function(key, validations) {
return Ember.computed(function() {
return Ember.ObjectProxy.createWithMixins(
BufferedMixin,
EmberValidations.Mixin, {
content: this.get(key),
validations: validations,
container: this.get('container'),
_validate: function() {
return this._super();
}
});
});
};
export default Ember.Controller.extend({
myModel: null,
form: validationProxy('myModel', {
name: {
presence: true
}
}),
init() {
this.set('myModel', this.store.createRecord('foo'))
},
actions: {
validate() {
this.get('form').validate()
.then(() => {
this.get('form').applyChanges();
console.log(this.get('myModel').toJSON());
})
.catch(() => {
console.log('Invalid', JSON.stringify(this.get('form.errors')));
})
}
}
});