Reputation: 2832
Consider following example:
Zoo = Backbone.Model.extend({
validate: function() {
console.log('val');
return "error";
},
url: '/save/'
});
var artis = new Zoo( { name: 'Artis' } );
console.log(artis.get( 'name' ) );
artis.save({name:'Artis2'})
console.log( artis.get( 'name' ) );
If you try to save changes to a model, but validation fails.
But you can see in the example that data is changed in the model.
Is this really a drawback or I am missing something?
Upvotes: 1
Views: 80
Reputation: 2648
The data will change in this example because you are not forcing validation. If you want to force validation prior to the modification of the client-side model, you must use the set method like this:
artis.set({name:'Artis2'}, {validate: true});
Upvotes: 3