-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
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
Labels
No labels