Skip to content

Validations #2

@the-swerve

Description

@the-swerve

Here's what I was very generally thinking with validations:

Declare validations and defaults:

var is_email = function(email) {
  // custom check that an email is valid
};

var Post = Model({
  title: {
    type: 'string',
    required: true,
    max_length: 40,
    default: 'New Post'
  },
  author: {
    name: 'string',
    email: {
      validate: is_email,
      message: 'Please enter a valid email'
    }
  }
});

Errors:

var post = Post();
post.errors; // {}
post.title; // 'New Post'
post.title = '';
post.errors; // {'title': 'title required'}
post.set_default('title');
post.author.email = 'hi';
post.errors; // {'author': {'email': 'Please enter a valid email'}};

Error events could be emitted in the form of 'error property' or 'error object.property', and some kind of templating or form library could take those events and render them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions