Sergey Kudryashov
Sergey Kudryashov

Reputation: 721

Backbone Validation Add inputs to validation

I have one backbone model that includes validation object with list of validation parameters.

var SignUpModel = Backbone.Model.extend({    
  validation: {    
    firstname: {
        required: true,
         pattern: 'name'
    },
    lastname: {
        required: true,
        pattern: 'name'
    }    
  },

  addToValidation: function(){         
     // HOW TO DO THIS???
     this.validation.PUSH{
      country: {
         required: true
      },
      phone: {
        required: true,
        pattern: 'phone'
      }
    }
  }    
});

How to add to this object another object? I didn't find it in JS, but maybe this function exists in Backbone or Underscore?

Also maybe backbone has special thing for data keeping?

Upvotes: 1

Views: 71

Answers (1)

flochtililoch
flochtililoch

Reputation: 6206

_.extend(this.validation, {
   country : {
     required: true
  },
  phone: {
    required: true,
    pattern: 'phone'
  }
});

Upvotes: 2

Related Questions