mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
error events are now always passed the model as the first argument. You may now also pass an error callback to set() and save(), if the callback is passed, it will be called instead of the 'error' event getting fired.
This commit is contained in:
@@ -138,4 +138,28 @@ $(document).ready(function() {
|
||||
equals(lastError, "Can't change admin status.");
|
||||
});
|
||||
|
||||
test("Model: validate with error callback", function() {
|
||||
var lastError, boundError;
|
||||
var model = new Backbone.Model();
|
||||
model.validate = function(attrs) {
|
||||
if (attrs.admin) return "Can't change admin status.";
|
||||
};
|
||||
var callback = function(model, error) {
|
||||
lastError = error;
|
||||
};
|
||||
model.bind('error', function(model, error) {
|
||||
boundError = true;
|
||||
});
|
||||
var result = model.set({a: 100}, {error: callback});
|
||||
equals(result, model);
|
||||
equals(model.get('a'), 100);
|
||||
equals(lastError, undefined);
|
||||
equals(boundError, undefined);
|
||||
result = model.set({a: 200, admin: true}, {error: callback});
|
||||
equals(result, false);
|
||||
equals(model.get('a'), 100);
|
||||
equals(lastError, "Can't change admin status.");
|
||||
equals(boundError, undefined);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user