thedersen/backbone.validation — Issue #16: Multiple error messages
Author: PeteMoran
Created: 2012-01-18 13:06:19+00:00
State: open

Great plugin BTW

One thing - would be great if each type of error could have its own message (similar to the way Jquery validation works).

E.g. if I have

validation: {
heading: {
required: true,
maxLength: 20,
msg: 'We need a heading'
},
description: {
required: true,
minLength: 1,
maxLength: 50,
msg: 'We need a description'
},
price : {
required: true,
pattern: 'number',
msg: 'Please enter a price'
}

},
With the validation errors

_.extend(Backbone.Validation.callbacks, {
valid: function(view, attr, selector) {
$('#' + attr + "_error").html("");
$('#' + attr + "_error").hide();
return true;
},
invalid: function(view, attr, error, selector) {
console.log(error);
$('#' + attr + "_error").html(error);
$('#' + attr + "_error").show();
}
});

If my 'heading is empty'

invalid produces 'We need a headingWe need a heading'

Ideally should stop on the first error