Validation extension to Gisele model library
Adds validation capabilities to any Gisele.Model instances
Usage
var User = GiseleModel; var bob = name: 'Bob' age: 15; // runs the validation rules of each fieldbob$$; console;// true console;// {// name: { minlength: true },// age: { min: true }// }
Validation of custom fields
New field types must implement a validate()
method that either returns true
(is valid) or an object with the validation errors.
In the builtin fields they are key/value pairs with the key being an error and the value being true, as same as bob.$$errors
above.
Example:
Field { return value; } { // any validation rule can be applied if thisrequired && value instanceof Foo return required: true ; return true; } GiseleField;