Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation from documentation example doesn't work #99

Open
Skivmag opened this issue May 13, 2015 · 5 comments
Open

Validation from documentation example doesn't work #99

Skivmag opened this issue May 13, 2015 · 5 comments

Comments

@Skivmag
Copy link

Skivmag commented May 13, 2015

I'm trying to implement validation example from here
http://indexiatech.github.io/ember-forms/quickexample

Model:


`import DS from 'ember-data'`

User = DS.Model.extend
    username: DS.attr('string')
    email: DS.attr('string')

User.reopen
    validations:
        username:
            presence: true
            length:
                minimum: 5

`export default User`

Template:

{{#em-form model=model form_layout="inline"}}
            {{em-input property="username" value=model.username}}
            {{em-input property="email" type='email' value=model.email}}
        {{/em-form}}

But when I try to enter invalid text to username field - nothing happened

@danconnell
Copy link

You have to import and mixin EmberValidations onto the model

@Skivmag
Copy link
Author

Skivmag commented May 27, 2015

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

@danconnell
Copy link

If you're on the latest ember-validations, you have to extend EmberValidations.Mixin

@cimtico
Copy link

cimtico commented May 28, 2015

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"

@cimtico
Copy link

cimtico commented May 29, 2015

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}
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants