diff --git a/can-validate/map/validate/validate.js b/can-validate/map/validate/validate.js index 0db51baf..b6eabaaf 100644 --- a/can-validate/map/validate/validate.js +++ b/can-validate/map/validate/validate.js @@ -235,16 +235,17 @@ can.extend(can.Map.prototype, { * * @param {object} item A key/value object * @param {object} opts Object that contains validation config. + * @param {object} otherItems Object that contains other attributes in the map * @return {boolean} True if method found that the property can be saved; if * validation fails and the property must validate (`mustValidate` property), * this will be `false`. */ - _validateOne: function (item, opts) { + _validateOne: function (item, opts, otherItems) { var errors; var allowSet = true; // run validation - errors = can.validate.once(item.value, can.extend({}, opts), item.key); + errors = can.validate.once(item.value, can.extend({}, opts), item.key, otherItems); // Process errors if we got them if (errors && errors.length > 0) { @@ -303,7 +304,7 @@ can.extend(can.Map.prototype, { can.each(computes, function (item) { item.compute.bind('change', function () { itemObj.value = self.attr(itemObj.key); - self._validateOne(itemObj, processedObj); + self._validateOne(itemObj, processedObj, self.attr()); }); }); @@ -325,7 +326,7 @@ proto.__set = function (prop, value, current, success, error) { // If validate opts are set and initing, validate properties only if validateOnInit is true if ((validateOpts && !mapIniting) || (validateOpts && mapIniting && validateOpts.validateOnInit)) { // Validate item - allowSet = this._validateOne({key: prop, value: value}, validateOpts); + allowSet = this._validateOne({key: prop, value: value}, validateOpts, this.attr()); } } diff --git a/can-validate/shims/validatejs.shim.js b/can-validate/shims/validatejs.shim.js index 0e83c994..b21acf54 100644 --- a/can-validate/shims/validatejs.shim.js +++ b/can-validate/shims/validatejs.shim.js @@ -51,7 +51,7 @@ var Shim = can.Construct.extend({ * @return {undefined|array} Returns undefined if no errors, otherwise returns * a list of errors. */ - once: function (value, options, name) { + once: function (value, options, name, otherItems) { var errors = []; var opts = []; var validationOpts = []; @@ -60,6 +60,7 @@ var Shim = can.Construct.extend({ if (name) { // Since name exists, use the main validate method but just pass one // property to it. Need to structure the objects it expects first. + opts = can.extend({}, otherItems); opts[name] = value; validationOpts[name] = processOptions(options);