diff --git a/js/model.js b/js/model.js index 752f084..6dce619 100644 --- a/js/model.js +++ b/js/model.js @@ -498,25 +498,29 @@ define([ }); Model.prototype._setOne = _.wrap(Model.prototype._setOne, - function(f, prop, newValue, currentValue, opts) { + function(f, prop, newValue, currentValue, opts, ctrl) { var i, l, args = Array.prototype.slice.call(arguments, 1), inFlight = this._inFlight.save; if (opts.noclobber) { if (this._changes[prop]) { - return; + ctrl.silent = true; } for (i = 0, l = inFlight.length; i < l; i++) { if (inFlight[i].changes[prop]) { - return; + ctrl.silent = true; } } + if (ctrl.silent) { + return; + } } if (opts.validate) { var field = this._fieldFromPropName(prop); try { field.validate(newValue); } catch (e) { - return e; + ctrl.error = e; + return; } } return f.apply(this, args); diff --git a/js/tests/test_model_consistency.js b/js/tests/test_model_consistency.js index 312b6eb..e82225f 100644 --- a/js/tests/test_model_consistency.js +++ b/js/tests/test_model_consistency.js @@ -1124,5 +1124,18 @@ define([ }); }); + asyncTest('setting changed value with noclobber doesnt trigger change', function() { + setup().then(function(c) { + var m = c.first(), changes = []; + m.on('change', function(eventName, changed) { + changes.push(changed); + }); + m.set('required_field', 'foobar'); + m.set('required_field', m.previous('required_field'), {noclobber: true}); + equal(changes.length, 1); + start(); + }); + }); + start(); });