[Pkg-javascript-commits] [backbone] 06/37: fixes #907 - `save` with `wait` succeeds without `validate`
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 17:02:46 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.9.1
in repository backbone.
commit db95e2c1fb9846a713685d35b12c9c4ce91d58f1
Author: Brad Dunbar <dunbarb2 at gmail.com>
Date: Tue Jan 31 09:46:23 2012 -0500
fixes #907 - `save` with `wait` succeeds without `validate`
---
backbone.js | 27 +++++++++++++--------------
test/model.js | 6 ++++++
2 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/backbone.js b/backbone.js
index d6a0aa9..bca4595 100644
--- a/backbone.js
+++ b/backbone.js
@@ -226,7 +226,7 @@
if (options.unset) for (attr in attrs) attrs[attr] = void 0;
// Run validation.
- if (this.validate && !this._performValidation(attrs, options)) return false;
+ if (!this._validate(attrs, options)) return false;
// Check for changes of `id`.
if (this.idAttribute in attrs) this.id = attrs[this.idAttribute];
@@ -299,7 +299,7 @@
}
options = options ? _.clone(options) : {};
- if (attrs && !this[options.wait ? '_performValidation' : 'set'](attrs, options)) return false;
+ if (attrs && !this[options.wait ? '_validate' : 'set'](attrs, options)) return false;
var model = this;
var success = options.success;
options.success = function(resp, status, xhr) {
@@ -420,18 +420,17 @@
// Run validation against a set of incoming attributes, returning `true`
// if all is well. If a specific `error` callback has been passed,
// call that instead of firing the general `"error"` event.
- _performValidation: function(attrs, options) {
- var newAttrs = _.extend({}, this.attributes, attrs);
- var error = this.validate(newAttrs, options);
- if (error) {
- if (options.error) {
- options.error(this, error, options);
- } else {
- this.trigger('error', this, error, options);
- }
- return false;
+ _validate: function(attrs, options) {
+ if (!_.isFunction(this.validate)) return true;
+ attrs = _.extend({}, this.attributes, attrs);
+ var error = this.validate(attrs, options);
+ if (!error) return true;
+ if (options.error) {
+ options.error(this, error, options);
+ } else {
+ this.trigger('error', this, error, options);
}
- return true;
+ return false;
}
});
@@ -650,7 +649,7 @@
var attrs = model;
options.collection = this;
model = new this.model(attrs, options);
- if (model.validate && !model._performValidation(model.attributes, options)) model = false;
+ if (!model._validate(model.attributes, options)) model = false;
} else if (!model.collection) {
model.collection = this;
}
diff --git a/test/model.js b/test/model.js
index 594fffa..f30da6c 100644
--- a/test/model.js
+++ b/test/model.js
@@ -583,4 +583,10 @@ $(document).ready(function() {
ok(model.hasChanged());
});
+ test("save with `wait` succeeds without `validate`", function() {
+ var model = new Backbone.Model();
+ model.save({x: 1}, {wait: true});
+ ok(lastRequest[1] === model);
+ });
+
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list