user2846569
user2846569

Reputation: 2832

Backbone serious drawback

Consider following example:

http://jsfiddle.net/FxX7v/1/

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

Answers (1)

David Fleeman
David Fleeman

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

Related Questions