mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Merge pull request #2388 from tgriesser/validateError
Adding options.validationError
This commit is contained in:
@@ -549,7 +549,7 @@
|
||||
attrs = _.extend({}, this.attributes, attrs);
|
||||
var error = this.validationError = this.validate(attrs, options) || null;
|
||||
if (!error) return true;
|
||||
this.trigger('invalid', this, error, options || {});
|
||||
this.trigger('invalid', this, error, _.extend(options || {}, {validationError: error}));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -438,7 +438,7 @@ $(document).ready(function() {
|
||||
equal(model.collection, collection);
|
||||
});
|
||||
|
||||
test("create with validate:true enforces validation", 1, function() {
|
||||
test("create with validate:true enforces validation", 2, function() {
|
||||
var ValidatingModel = Backbone.Model.extend({
|
||||
validate: function(attrs) {
|
||||
return "fail";
|
||||
@@ -448,6 +448,9 @@ $(document).ready(function() {
|
||||
model: ValidatingModel
|
||||
});
|
||||
var col = new ValidatingCollection();
|
||||
col.on('invalid', function (collection, attrs, options) {
|
||||
equal(options.validationError, 'fail');
|
||||
});
|
||||
equal(col.create({"foo":"bar"}, {validate:true}), false);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user