I have a collection: conditions. In a view, after returning an HTTP 403 error response, I want to obviously NOT create the model:
var attributes = ...;
conditions.create(attributes, {
error: function (model, response) {
conditions.trigger('error');
var response = JSON.parse(response.responseText);
console.log(response);
}
});
The error callback is being called correctly. The response is logged correctly. But backbone still adds the (broken) model to the collection! When I look at conditions.toJSON(), there is a new model with some broken attributes.
I returned an error from the server, how do I insist that Backbone not add the new model to the collection?
I can do conditions.remove(model) in the callback, but should I have to?
You can pass
{wait: true}to thecreatemethod.http://documentcloud.github.com/backbone/#Collection-create