Skip to content

Validation scopes #17

@ghost

Description

It would be really useful if the library offered the ability to specify scopes for a particular set of validations.

Example:

App.User = Ember.Object.extend(Ember.Validations, {
  validations: {
    scope: {
      login: {
        password: {
          presence: true
        }
      }
      editProfile: {
        password: {
          presence: true
        }
        passwordConfirmation: {
          presence: true
        }
      }
    }
    // Normal, unscoped validations, which always applies.
    name: {
      presence: true
    }    
  }
});

And then you validate the model like so:

var user = App.User.create({
  username: 'user',
  password: 'password',
  passwordConfirmation: null
});

user.validate(); // true
user.validate('login'); // true
user.validate('editProfile'); // false

I grant that the example is not very plausible (one would not store a password in a model) but it does illustrate the general idea.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions