thedersen/backbone.validation — pull request #42 by dim0xff (2012-04-16 12:46:14+00:00)
Title: Custom errors and errors messages in events

Hello!

# Custom errors
You can still use built-in messages (in example below password has build-in messages). But also can use your own (username field has your own error messages):

validation : {
username : {
required : {
value : true,
msg : 'username.required'
},
minLength : {
value : 4,
msg : 'username.min.length'
},
fn : {
value : function ( value, attr ) {
if (value && !value.match(/^[a-z0-9\-]+$/i)) {
return true;
}
},
msg : 'not.allowed.chars'
}
},
password : {
required : true,
}
}

# Error messages from events
So you can catch error messages in your model via 'valedate' and 'validate:state' events:

model.on('validated', function (model, invalidAttrs, errorMessages) {
// Your code here...
});