From 01630e88d6eda9afc9843ca163db894a9638dfdb Mon Sep 17 00:00:00 2001 From: Matt Holmes Date: Sun, 11 Oct 2015 10:35:59 -0500 Subject: [PATCH 1/2] adding the model as an argument to the valid/invalid functions. This would allow users to leverage model properties (uuid, cid etc) the may be used on the DOM --- dist/backbone-validation.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/backbone-validation.js b/dist/backbone-validation.js index e1d10e10..eccc84f4 100644 --- a/dist/backbone-validation.js +++ b/dist/backbone-validation.js @@ -254,11 +254,11 @@ Backbone.Validation = (function(_){ _.each(attrs, function (attr) { error = validateAttr(this, attr, flattened[attr], _.extend({}, this.attributes)); if (error) { - options.invalid(view, attr, error, options.selector); + options.invalid(view, attr, error, options.selector, this); invalidAttrs = invalidAttrs || {}; invalidAttrs[attr] = error; } else { - options.valid(view, attr, options.selector); + options.valid(view, attr, options.selector, this); } }, this); }, this); @@ -298,10 +298,10 @@ Backbone.Validation = (function(_){ changed = changedAttrs.hasOwnProperty(attr); if(!invalid){ - opt.valid(view, attr, opt.selector); + opt.valid(view, attr, opt.selector, model); } if(invalid && (changed || validateAll)){ - opt.invalid(view, attr, result.invalidAttrs[attr], opt.selector); + opt.invalid(view, attr, result.invalidAttrs[attr], opt.selector, model); } }); }); @@ -706,4 +706,4 @@ Backbone.Validation = (function(_){ }); return Validation; -}(_)); \ No newline at end of file +}(_)); From fd897a7f80ffe39b3425171f413a29986ef4de6b Mon Sep 17 00:00:00 2001 From: Matt Holmes Date: Sun, 11 Oct 2015 10:38:46 -0500 Subject: [PATCH 2/2] adding the model as an argument to the valid/invalid functions. This would allow users to leverage model properties (uuid, cid etc) the may be used on the DOM --- dist/backbone-validation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/backbone-validation.js b/dist/backbone-validation.js index eccc84f4..7dd86864 100644 --- a/dist/backbone-validation.js +++ b/dist/backbone-validation.js @@ -429,7 +429,7 @@ Backbone.Validation = (function(_){ // Gets called when a previously invalid field in the // view becomes valid. Removes any error message. // Should be overridden with custom functionality. - valid: function(view, attr, selector) { + valid: function(view, attr, selector, model) { view.$('[' + selector + '~="' + attr + '"]') .removeClass('invalid') .removeAttr('data-error'); @@ -438,7 +438,7 @@ Backbone.Validation = (function(_){ // Gets called when a field in the view becomes invalid. // Adds a error message. // Should be overridden with custom functionality. - invalid: function(view, attr, error, selector) { + invalid: function(view, attr, error, selector, model) { view.$('[' + selector + '~="' + attr + '"]') .addClass('invalid') .attr('data-error', error);