Sandy Sandy - 2 months ago 14
jQuery Question

backbone validate method doesn't trigger in my case

I'm new to backbone.

var Person = Backbone.Model.extend({
defaults: {
name: '',
age: 30,
occupation: 'fireman'
validate: function(attrs) {
console.log(attrs) // this won't trigger? since the model's attr changed;
run: function() {
return this.get('name') + ' is running';

var p = new Person({name:'James'});

I change the model's property but somehow I did not see the console. Why?


You need to tell the set method to validate by passing validate option.

p.set({age: 25}, {validate: true});