I'd like to save an altered model to the database (set before). If the save succeeded redirect to another page (as example, could be any other action).
Model.save can have two optional properties. First is a hash of properties, and the second are options (like the success and error callback). http://backbonejs.org/#Model-save
somemodel.set({foo: 'bar'});
//lots of other logic and misc steps the user has to do
somemodel.save(); //on success should go here
Since the attributes are already set, I only need the callback.
In the past I did:
somemodel.save(somemodel.toJSON(), {
success: function() {
//other stuff
}
);
or passing the values again to the save method
somemodel.save(
{ foo: this.$('input').val()},
{ success: function(){}
);
I'm looking for a way to clean this up. The documents state, the model will fire a change state if there are new properties. But I'd want to redirect the user anyway (saving on new content or old/unaltered).
this does not exist:
somemodel.on('success', function(){});
and this, is only for validation:
if(somemodel.save()) { //action }
also "sync" is the wrong event (since it also works for destroy)
Any help?