Skip to content

Commit

Permalink
taking changes from #36
Browse files Browse the repository at this point in the history
  • Loading branch information
ccummings committed Sep 22, 2016
1 parent b98fb39 commit 0bdf1ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 5 additions & 4 deletions can-validate/map/validate/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,17 @@ deepAssign(canMap.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 = canValidate.once(item.value, deepAssign({}, opts), item.key);
errors = canValidate.once(item.value, deepAssign({}, opts), item.key, otherItems);

// Process errors if we got them
if (errors && errors.length > 0) {
Expand Down Expand Up @@ -307,7 +308,7 @@ deepAssign(canMap.prototype, {
canEach(computes, function (item) {
item.compute.bind('change', function () {
itemObj.value = self.attr(itemObj.key);
self._validateOne(itemObj, processedObj);
self._validateOne(itemObj, processedObj, self.attr());
});
});

Expand All @@ -324,7 +325,7 @@ proto.__set = function (prop, value, current, success, error) {
var mapIniting = this._initValidate;

if (checkValidate !== false) {
validateOpts = resolveComputes({key: prop, value: value}, validateOpts);
validateOpts = resolveComputes({key: prop, value: value}, validateOpts, this.attr());
// If validate opts are set and not initing, validate properties
// If validate opts are set and initing, validate properties only if validateOnInit is true
if ((validateOpts && !mapIniting) || (validateOpts && mapIniting && validateOpts.validateOnInit)) {
Expand Down
3 changes: 2 additions & 1 deletion can-validate/shims/validatejs.shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var Shim = 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 = [];
Expand All @@ -61,6 +61,7 @@ var Shim = 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);

Expand Down

0 comments on commit 0bdf1ef

Please sign in to comment.