Open Skivmag opened 9 years ago
You have to import and mixin EmberValidations onto the model
Generally, I did so
`import DS from 'ember-data'`;
`import EmberValidations from 'ember-validations'`;
User = DS.Model.extend(EmberValidations,
username: DS.attr('string')
email: DS.attr('string')
)
User.reopen
validations:
username:
presence: true
length:
minimum: 5
`export default User`
But validation still doesn't work
If you're on the latest ember-validations, you have to extend EmberValidations.Mixin
I'm running into this issue also. I have the following definition
import DS from 'ember-data';
import EmberValidations from 'ember-validations';
var User = DS.Model.extend(EmberValidations.Mixin, {
firstName: DS.attr('string'),
});
User.reopenClass({
FIXTURES: [],
validations: {
firstName: {
presence: true,
length: {minimum: 5}
}
});
export default User;
however it seems validations are being ignored completely. I'm using:
"ember-cli": "~0.2.5",
"ember-idx-forms": "0.6.0",
"ember-data": "1.0.0-beta.16.1",
"ember-validations": "^2.0.0-alpha.3"
I found what the problem was. It seems that adding the validations on the reopenClass doesn't work. It should be done on reopen instead.
var User = DS.Model.extend(EmberValidations.Mixin, {
firstName: DS.attr('string'),
});
User.reopenClass({
FIXTURES: [],
});
User.reopen({
validations: {
firstName: {
presence: true,
length: {minimum: 5}
}
});
I'm trying to implement validation example from here http://indexiatech.github.io/ember-forms/quickexample
Model:
Template:
But when I try to enter invalid text to username field - nothing happened