Multiple error messages #16

PeteMoran opened this Issue Jan 18, 2012 · 4 comments


None yet

3 participants


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) {


If my 'heading is empty'

invalid produces 'We need a headingWe need a heading'

Ideally should stop on the first error


Hi I have a branch that pretty much does this as I needed this functionality too

I've submitted a pull request, hopefully it will be merged in. Also see this thread about it


It allows you separate each validation check which lets you have specific messages for each :

MyModel = Backbone.Model.extend({
    validation: {
        name: {
            required: true,
            msg: "Please enter a player name"
        email: [{
            required: true,
            msg: "Please enter an email address"
            pattern: "email",
            msg: "Please enter a valid email"

@GarethElms No worries, I will pull it in:) Just been a couple of crazy days lately.

@PeteMoran Thanks for the feedback, will fix this issue next time I get to do some work on this.


Pretty sure that I fixed the double error problem in my branch while I was at it. It returns a string if there is just one error, or an array of errors if there are multiple errors

@thedersen thedersen closed this Jan 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment