Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

backbone-validation

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone-validation - npm Package Compare versions

Comparing version 0.6.2 to 0.6.3

4

dist/backbone-validation-amd-min.js

@@ -1,2 +0,2 @@

// Backbone.Validation v0.6.2
// Backbone.Validation v0.6.3
//

@@ -8,2 +8,2 @@ // Copyright (c) 2011-2012 Thomas Pedersen

// http://thedersen.com/projects/backbone-validation
(function(a){typeof exports=="object"?module.exports=a(require("backbone"),require("underscore")):typeof define=="function"&&define.amd&&define(["backbone","underscore"],a)})(function(a,b){return a.Validation=function(a){"use strict";var b={forceUpdate:!1,selector:"name",labelFormatter:"sentenceCase",valid:Function.prototype,invalid:Function.prototype},c=function(){var c=function(b){return a.reduce(a.keys(b.validation||{}),function(a,b){return a[b]=void 0,a},{})},e=function(b,c){var d=b.validation?b.validation[c]||{}:{};if(a.isFunction(d)||a.isString(d))d={fn:d};return a.isArray(d)||(d=[d]),a.reduce(d,function(b,c){return a.each(a.without(a.keys(c),"msg"),function(a){b.push({fn:h[a],val:c[a],msg:c.msg})}),b},[])},f=function(b,c,d,f){return a.reduce(e(b,c),function(a,e){var g=e.fn.call(h,d,c,e.val,b,f);return g===!1||a===!1?!1:g&&!a?e.msg||g:a},"")},g=function(b,c){var d,e,g={},h=!0,i=a.clone(c);for(e in c)d=f(b,e,c[e],i),d&&(g[e]=d,h=!1);return{invalidAttrs:g,isValid:h}},i=function(b,d){return{preValidate:function(b,c){return f(this,b,c,a.extend({},this.attributes))},isValid:function(b){if(a.isString(b))return!f(this,b,this.get(b),a.extend({},this.attributes));if(a.isArray(b)){for(var c=0;c<b.length;c++)if(f(this,b[c],this.get(b[c]),a.extend({},this.attributes)))return!1;return!0}return b===!0&&this.validate(),this.validation?this._isValid:!0},validate:function(e,f){var h=this,i=!e,j=a.extend({},d,f),k=a.extend(c(h),h.attributes,e),l=e||k,m=g(h,k);h._isValid=m.isValid;for(var n in k){var o=m.invalidAttrs.hasOwnProperty(n),p=l.hasOwnProperty(n);o&&(p||i)&&j.invalid(b,n,m.invalidAttrs[n],j.selector),o||j.valid(b,n,j.selector)}a.defer(function(){h.trigger("validated",h._isValid,h,m.invalidAttrs),h.trigger("validated:"+(h._isValid?"valid":"invalid"),h,m.invalidAttrs)});if(!j.forceUpdate&&a.intersection(a.keys(m.invalidAttrs),a.keys(l)).length>0)return m.invalidAttrs}}},j=function(b,c,d){a.extend(c,i(b,d))},k=function(a){delete a.validate,delete a.preValidate,delete a.isValid},l=function(a){j(this.view,a,this.options)},m=function(a){k(a)};return{version:"0.6.2",configure:function(c){a.extend(b,c)},bind:function(c,e){var f=c.model,g=c.collection;e=a.extend({},b,d,e);if(typeof f=="undefined"&&typeof g=="undefined")throw"Before you execute the binding your view must have a model or a collection.\nSee http://thedersen.com/projects/backbone-validation/#using-form-model-validation for more information.";f&&j(c,f,e),g&&(g.each(function(a){j(c,a,e)}),g.bind("add",l,{view:c,options:e}),g.bind("remove",m))},unbind:function(a){var b=a.model,c=a.collection;b&&k(a.model),c&&(c.each(function(a){k(a)}),c.unbind("add",l),c.unbind("remove",m))},mixin:i(null,b)}}(),d=c.callbacks={valid:function(a,b,c){a.$("["+c+"~="+b+"]").removeClass("invalid").removeAttr("data-error")},invalid:function(a,b,c,d){a.$("["+d+"~="+b+"]").addClass("invalid").attr("data-error",c)}},e=c.patterns={digits:/^\d+$/,number:/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/,email:/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i,url:/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i},f=c.messages={required:"{0} is required",acceptance:"{0} must be accepted",min:"{0} must be greater than or equal to {1}",max:"{0} must be less than or equal to {1}",range:"{0} must be between {1} and {2}",length:"{0} must be {1} characters",minLength:"{0} must be at least {1} characters",maxLength:"{0} must be at most {1} characters",rangeLength:"{0} must be between {1} and {2} characters",oneOf:"{0} must be one of: {1}",equalTo:"{0} must be the same as {1}",pattern:"{0} must be a valid {1}"},g=c.labelFormatters={none:function(a){return a},sentenceCase:function(a){return a.replace(/(?:^\w|[A-Z]|\b\w)/g,function(a,b){return b===0?a.toUpperCase():" "+a.toLowerCase()}).replace("_"," ")},label:function(a,b){return b.labels[a]||g.sentenceCase(a,b)}},h=c.validators=function(){var c=String.prototype.trim?function(a){return a===null?"":String.prototype.trim.call(a)}:function(a){var b=/^\s+/,c=/\s+$/;return a===null?"":a.toString().replace(b,"").replace(c,"")},d=function(a,c){return g[b.labelFormatter](a,c)},h=function(){var a=Array.prototype.slice.call(arguments),b=a.shift();return b.replace(/\{(\d+)\}/g,function(b,c){return typeof a[c]!="undefined"?a[c]:b})},i=function(b){return a.isNumber(b)||a.isString(b)&&b.match(e.number)},j=function(b){return!(a.isNull(b)||a.isUndefined(b)||a.isString(b)&&c(b)==="")};return{fn:function(b,c,d,e,f){return a.isString(d)&&(d=e[d]),d.call(e,b,c,f)},required:function(b,c,e,g,i){var k=a.isFunction(e)?e.call(g,b,c,i):e;if(!k&&!j(b))return!1;if(k&&!j(b))return h(f.required,d(c,g))},acceptance:function(b,c,e,g){if(b!=="true"&&(!a.isBoolean(b)||b===!1))return h(f.acceptance,d(c,g))},min:function(a,b,c,e){if(!i(a)||a<c)return h(f.min,d(b,e),c)},max:function(a,b,c,e){if(!i(a)||a>c)return h(f.max,d(b,e),c)},range:function(a,b,c,e){if(!i(a)||a<c[0]||a>c[1])return h(f.range,d(b,e),c[0],c[1])},length:function(a,b,e,g){if(!j(a)||c(a).length!==e)return h(f.length,d(b,g),e)},minLength:function(a,b,e,g){if(!j(a)||c(a).length<e)return h(f.minLength,d(b,g),e)},maxLength:function(a,b,e,g){if(!j(a)||c(a).length>e)return h(f.maxLength,d(b,g),e)},rangeLength:function(a,b,e,g){if(!j(a)||c(a).length<e[0]||c(a).length>e[1])return h(f.rangeLength,d(b,g),e[0],e[1])},oneOf:function(b,c,e,g){if(!a.include(e,b))return h(f.oneOf,d(c,g),e.join(", "))},equalTo:function(a,b,c,e,g){if(a!==g[c])return h(f.equalTo,d(b,e),d(c,e))},pattern:function(a,b,c,g){if(!j(a)||!a.toString().match(e[c]||c))return h(f.pattern,d(b,g),c)}}}();return c}(b),a.Validation});
(function(e){typeof exports=="object"?module.exports=e(require("backbone"),require("underscore")):typeof define=="function"&&define.amd&&define(["backbone","underscore"],e)})(function(e,t){return e.Validation=function(e){"use strict";var t={forceUpdate:!1,selector:"name",labelFormatter:"sentenceCase",valid:Function.prototype,invalid:Function.prototype},n=function(){var n=function(t){return e.reduce(e.keys(t.validation||{}),function(e,t){return e[t]=void 0,e},{})},i=function(t,n){var r=t.validation?t.validation[n]||{}:{};if(e.isFunction(r)||e.isString(r))r={fn:r};return e.isArray(r)||(r=[r]),e.reduce(r,function(t,n){return e.each(e.without(e.keys(n),"msg"),function(e){t.push({fn:u[e],val:n[e],msg:n.msg})}),t},[])},s=function(t,n,r,s){return e.reduce(i(t,n),function(e,i){var o=i.fn.call(u,r,n,i.val,t,s);return o===!1||e===!1?!1:o&&!e?i.msg||o:e},"")},o=function(t,n){var r,i,o={},u=!0,a=e.clone(n);for(i in n)r=s(t,i,n[i],a),r&&(o[i]=r,u=!1);return{invalidAttrs:o,isValid:u}},a=function(t,r){return{preValidate:function(t,n){return s(this,t,n,e.extend({},this.attributes))},isValid:function(t){if(e.isString(t))return!s(this,t,this.get(t),e.extend({},this.attributes));if(e.isArray(t)){for(var n=0;n<t.length;n++)if(s(this,t[n],this.get(t[n]),e.extend({},this.attributes)))return!1;return!0}return t===!0&&this.validate(),this.validation?this._isValid:!0},validate:function(i,s){var u=this,a=!i,f=e.extend({},r,s),l=n(u),c=e.extend({},l,u.attributes,i),h=i||c,p=o(u,c);u._isValid=p.isValid,e.each(e.keys(l),function(e){var n=p.invalidAttrs.hasOwnProperty(e);n||f.valid(t,e,f.selector)}),e.each(e.keys(l),function(e){var n=p.invalidAttrs.hasOwnProperty(e),r=h.hasOwnProperty(e);n&&(r||a)&&f.invalid(t,e,p.invalidAttrs[e],f.selector)}),e.defer(function(){u.trigger("validated",u._isValid,u,p.invalidAttrs),u.trigger("validated:"+(u._isValid?"valid":"invalid"),u,p.invalidAttrs)});if(!f.forceUpdate&&e.intersection(e.keys(p.invalidAttrs),e.keys(h)).length>0)return p.invalidAttrs}}},f=function(t,n,r){e.extend(n,a(t,r))},l=function(e){delete e.validate,delete e.preValidate,delete e.isValid},c=function(e){f(this.view,e,this.options)},h=function(e){l(e)};return{version:"0.6.3",configure:function(n){e.extend(t,n)},bind:function(n,i){var s=n.model,o=n.collection;i=e.extend({},t,r,i);if(typeof s=="undefined"&&typeof o=="undefined")throw"Before you execute the binding your view must have a model or a collection.\nSee http://thedersen.com/projects/backbone-validation/#using-form-model-validation for more information.";s&&f(n,s,i),o&&(o.each(function(e){f(n,e,i)}),o.bind("add",c,{view:n,options:i}),o.bind("remove",h))},unbind:function(e){var t=e.model,n=e.collection;t&&l(e.model),n&&(n.each(function(e){l(e)}),n.unbind("add",c),n.unbind("remove",h))},mixin:a(null,t)}}(),r=n.callbacks={valid:function(e,t,n){e.$("["+n+"~="+t+"]").removeClass("invalid").removeAttr("data-error")},invalid:function(e,t,n,r){e.$("["+r+"~="+t+"]").addClass("invalid").attr("data-error",n)}},i=n.patterns={digits:/^\d+$/,number:/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/,email:/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i,url:/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i},s=n.messages={required:"{0} is required",acceptance:"{0} must be accepted",min:"{0} must be greater than or equal to {1}",max:"{0} must be less than or equal to {1}",range:"{0} must be between {1} and {2}",length:"{0} must be {1} characters",minLength:"{0} must be at least {1} characters",maxLength:"{0} must be at most {1} characters",rangeLength:"{0} must be between {1} and {2} characters",oneOf:"{0} must be one of: {1}",equalTo:"{0} must be the same as {1}",pattern:"{0} must be a valid {1}"},o=n.labelFormatters={none:function(e){return e},sentenceCase:function(e){return e.replace(/(?:^\w|[A-Z]|\b\w)/g,function(e,t){return t===0?e.toUpperCase():" "+e.toLowerCase()}).replace("_"," ")},label:function(e,t){return t.labels&&t.labels[e]||o.sentenceCase(e,t)}},u=n.validators=function(){var n=String.prototype.trim?function(e){return e===null?"":String.prototype.trim.call(e)}:function(e){var t=/^\s+/,n=/\s+$/;return e===null?"":e.toString().replace(t,"").replace(n,"")},r=function(e,n){return o[t.labelFormatter](e,n)},u=function(){var e=Array.prototype.slice.call(arguments),t=e.shift();return t.replace(/\{(\d+)\}/g,function(t,n){return typeof e[n]!="undefined"?e[n]:t})},a=function(t){return e.isNumber(t)||e.isString(t)&&t.match(i.number)},f=function(t){return!(e.isNull(t)||e.isUndefined(t)||e.isString(t)&&n(t)==="")};return{fn:function(t,n,r,i,s){return e.isString(r)&&(r=i[r]),r.call(i,t,n,s)},required:function(t,n,i,o,a){var l=e.isFunction(i)?i.call(o,t,n,a):i;if(!l&&!f(t))return!1;if(l&&!f(t))return u(s.required,r(n,o))},acceptance:function(t,n,i,o){if(t!=="true"&&(!e.isBoolean(t)||t===!1))return u(s.acceptance,r(n,o))},min:function(e,t,n,i){if(!a(e)||e<n)return u(s.min,r(t,i),n)},max:function(e,t,n,i){if(!a(e)||e>n)return u(s.max,r(t,i),n)},range:function(e,t,n,i){if(!a(e)||e<n[0]||e>n[1])return u(s.range,r(t,i),n[0],n[1])},length:function(e,t,i,o){if(!f(e)||n(e).length!==i)return u(s.length,r(t,o),i)},minLength:function(e,t,i,o){if(!f(e)||n(e).length<i)return u(s.minLength,r(t,o),i)},maxLength:function(e,t,i,o){if(!f(e)||n(e).length>i)return u(s.maxLength,r(t,o),i)},rangeLength:function(e,t,i,o){if(!f(e)||n(e).length<i[0]||n(e).length>i[1])return u(s.rangeLength,r(t,o),i[0],i[1])},oneOf:function(t,n,i,o){if(!e.include(i,t))return u(s.oneOf,r(n,o),i.join(", "))},equalTo:function(e,t,n,i,o){if(e!==o[n])return u(s.equalTo,r(t,i),r(n,i))},pattern:function(e,t,n,o){if(!f(e)||!e.toString().match(i[n]||n))return u(s.pattern,r(t,o),n)}}}();return n}(t),e.Validation});

@@ -1,2 +0,2 @@

// Backbone.Validation v0.6.2
// Backbone.Validation v0.6.3
//

@@ -161,3 +161,4 @@ // Copyright (c) 2011-2012 Thomas Pedersen

opt = _.extend({}, options, setOptions),
allAttrs = _.extend(getValidatedAttrs(model), model.attributes, attrs),
validatedAttrs = getValidatedAttrs(model),
allAttrs = _.extend({}, validatedAttrs, model.attributes, attrs),
changedAttrs = attrs || allAttrs,

@@ -169,13 +170,20 @@ result = validateModel(model, allAttrs);

// After validation is performed, loop through all changed attributes
// and call either the valid or invalid callback so the view is updated.
for(var attr in allAttrs) {
// and call the valid callbacks so the view is updated.
_.each(_.keys(validatedAttrs), function(attr){
var invalid = result.invalidAttrs.hasOwnProperty(attr);
if(!invalid){
opt.valid(view, attr, opt.selector);
}
});
// After validation is performed, loop through all changed attributes
// and call the invalid callback so the view is updated.
_.each(_.keys(validatedAttrs), function(attr){
var invalid = result.invalidAttrs.hasOwnProperty(attr),
changed = changedAttrs.hasOwnProperty(attr);
if(invalid && (changed || validateAll)){
opt.invalid(view, attr, result.invalidAttrs[attr], opt.selector);
}
if(!invalid){
opt.valid(view, attr, opt.selector);
}
}
});

@@ -228,3 +236,3 @@ // Trigger validated events.

// Current version of the library
version: '0.6.2',
version: '0.6.3',

@@ -387,3 +395,3 @@ // Called to configure the default options

label: function(attrName, model) {
return model.labels[attrName] || defaultLabelFormatters.sentenceCase(attrName, model);
return (model.labels && model.labels[attrName]) || defaultLabelFormatters.sentenceCase(attrName, model);
}

@@ -390,0 +398,0 @@ };

@@ -1,2 +0,2 @@

// Backbone.Validation v0.6.2
// Backbone.Validation v0.6.3
//

@@ -8,2 +8,2 @@ // Copyright (c) 2011-2012 Thomas Pedersen

// http://thedersen.com/projects/backbone-validation
Backbone.Validation=function(a){"use strict";var b={forceUpdate:!1,selector:"name",labelFormatter:"sentenceCase",valid:Function.prototype,invalid:Function.prototype},c=function(){var c=function(b){return a.reduce(a.keys(b.validation||{}),function(a,b){return a[b]=void 0,a},{})},e=function(b,c){var d=b.validation?b.validation[c]||{}:{};if(a.isFunction(d)||a.isString(d))d={fn:d};return a.isArray(d)||(d=[d]),a.reduce(d,function(b,c){return a.each(a.without(a.keys(c),"msg"),function(a){b.push({fn:h[a],val:c[a],msg:c.msg})}),b},[])},f=function(b,c,d,f){return a.reduce(e(b,c),function(a,e){var g=e.fn.call(h,d,c,e.val,b,f);return g===!1||a===!1?!1:g&&!a?e.msg||g:a},"")},g=function(b,c){var d,e,g={},h=!0,i=a.clone(c);for(e in c)d=f(b,e,c[e],i),d&&(g[e]=d,h=!1);return{invalidAttrs:g,isValid:h}},i=function(b,d){return{preValidate:function(b,c){return f(this,b,c,a.extend({},this.attributes))},isValid:function(b){if(a.isString(b))return!f(this,b,this.get(b),a.extend({},this.attributes));if(a.isArray(b)){for(var c=0;c<b.length;c++)if(f(this,b[c],this.get(b[c]),a.extend({},this.attributes)))return!1;return!0}return b===!0&&this.validate(),this.validation?this._isValid:!0},validate:function(e,f){var h=this,i=!e,j=a.extend({},d,f),k=a.extend(c(h),h.attributes,e),l=e||k,m=g(h,k);h._isValid=m.isValid;for(var n in k){var o=m.invalidAttrs.hasOwnProperty(n),p=l.hasOwnProperty(n);o&&(p||i)&&j.invalid(b,n,m.invalidAttrs[n],j.selector),o||j.valid(b,n,j.selector)}a.defer(function(){h.trigger("validated",h._isValid,h,m.invalidAttrs),h.trigger("validated:"+(h._isValid?"valid":"invalid"),h,m.invalidAttrs)});if(!j.forceUpdate&&a.intersection(a.keys(m.invalidAttrs),a.keys(l)).length>0)return m.invalidAttrs}}},j=function(b,c,d){a.extend(c,i(b,d))},k=function(a){delete a.validate,delete a.preValidate,delete a.isValid},l=function(a){j(this.view,a,this.options)},m=function(a){k(a)};return{version:"0.6.2",configure:function(c){a.extend(b,c)},bind:function(c,e){var f=c.model,g=c.collection;e=a.extend({},b,d,e);if(typeof f=="undefined"&&typeof g=="undefined")throw"Before you execute the binding your view must have a model or a collection.\nSee http://thedersen.com/projects/backbone-validation/#using-form-model-validation for more information.";f&&j(c,f,e),g&&(g.each(function(a){j(c,a,e)}),g.bind("add",l,{view:c,options:e}),g.bind("remove",m))},unbind:function(a){var b=a.model,c=a.collection;b&&k(a.model),c&&(c.each(function(a){k(a)}),c.unbind("add",l),c.unbind("remove",m))},mixin:i(null,b)}}(),d=c.callbacks={valid:function(a,b,c){a.$("["+c+"~="+b+"]").removeClass("invalid").removeAttr("data-error")},invalid:function(a,b,c,d){a.$("["+d+"~="+b+"]").addClass("invalid").attr("data-error",c)}},e=c.patterns={digits:/^\d+$/,number:/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/,email:/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i,url:/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i},f=c.messages={required:"{0} is required",acceptance:"{0} must be accepted",min:"{0} must be greater than or equal to {1}",max:"{0} must be less than or equal to {1}",range:"{0} must be between {1} and {2}",length:"{0} must be {1} characters",minLength:"{0} must be at least {1} characters",maxLength:"{0} must be at most {1} characters",rangeLength:"{0} must be between {1} and {2} characters",oneOf:"{0} must be one of: {1}",equalTo:"{0} must be the same as {1}",pattern:"{0} must be a valid {1}"},g=c.labelFormatters={none:function(a){return a},sentenceCase:function(a){return a.replace(/(?:^\w|[A-Z]|\b\w)/g,function(a,b){return b===0?a.toUpperCase():" "+a.toLowerCase()}).replace("_"," ")},label:function(a,b){return b.labels[a]||g.sentenceCase(a,b)}},h=c.validators=function(){var c=String.prototype.trim?function(a){return a===null?"":String.prototype.trim.call(a)}:function(a){var b=/^\s+/,c=/\s+$/;return a===null?"":a.toString().replace(b,"").replace(c,"")},d=function(a,c){return g[b.labelFormatter](a,c)},h=function(){var a=Array.prototype.slice.call(arguments),b=a.shift();return b.replace(/\{(\d+)\}/g,function(b,c){return typeof a[c]!="undefined"?a[c]:b})},i=function(b){return a.isNumber(b)||a.isString(b)&&b.match(e.number)},j=function(b){return!(a.isNull(b)||a.isUndefined(b)||a.isString(b)&&c(b)==="")};return{fn:function(b,c,d,e,f){return a.isString(d)&&(d=e[d]),d.call(e,b,c,f)},required:function(b,c,e,g,i){var k=a.isFunction(e)?e.call(g,b,c,i):e;if(!k&&!j(b))return!1;if(k&&!j(b))return h(f.required,d(c,g))},acceptance:function(b,c,e,g){if(b!=="true"&&(!a.isBoolean(b)||b===!1))return h(f.acceptance,d(c,g))},min:function(a,b,c,e){if(!i(a)||a<c)return h(f.min,d(b,e),c)},max:function(a,b,c,e){if(!i(a)||a>c)return h(f.max,d(b,e),c)},range:function(a,b,c,e){if(!i(a)||a<c[0]||a>c[1])return h(f.range,d(b,e),c[0],c[1])},length:function(a,b,e,g){if(!j(a)||c(a).length!==e)return h(f.length,d(b,g),e)},minLength:function(a,b,e,g){if(!j(a)||c(a).length<e)return h(f.minLength,d(b,g),e)},maxLength:function(a,b,e,g){if(!j(a)||c(a).length>e)return h(f.maxLength,d(b,g),e)},rangeLength:function(a,b,e,g){if(!j(a)||c(a).length<e[0]||c(a).length>e[1])return h(f.rangeLength,d(b,g),e[0],e[1])},oneOf:function(b,c,e,g){if(!a.include(e,b))return h(f.oneOf,d(c,g),e.join(", "))},equalTo:function(a,b,c,e,g){if(a!==g[c])return h(f.equalTo,d(b,e),d(c,e))},pattern:function(a,b,c,g){if(!j(a)||!a.toString().match(e[c]||c))return h(f.pattern,d(b,g),c)}}}();return c}(_);
Backbone.Validation=function(e){"use strict";var t={forceUpdate:!1,selector:"name",labelFormatter:"sentenceCase",valid:Function.prototype,invalid:Function.prototype},n=function(){var n=function(t){return e.reduce(e.keys(t.validation||{}),function(e,t){return e[t]=void 0,e},{})},i=function(t,n){var r=t.validation?t.validation[n]||{}:{};if(e.isFunction(r)||e.isString(r))r={fn:r};return e.isArray(r)||(r=[r]),e.reduce(r,function(t,n){return e.each(e.without(e.keys(n),"msg"),function(e){t.push({fn:u[e],val:n[e],msg:n.msg})}),t},[])},s=function(t,n,r,s){return e.reduce(i(t,n),function(e,i){var o=i.fn.call(u,r,n,i.val,t,s);return o===!1||e===!1?!1:o&&!e?i.msg||o:e},"")},o=function(t,n){var r,i,o={},u=!0,a=e.clone(n);for(i in n)r=s(t,i,n[i],a),r&&(o[i]=r,u=!1);return{invalidAttrs:o,isValid:u}},a=function(t,r){return{preValidate:function(t,n){return s(this,t,n,e.extend({},this.attributes))},isValid:function(t){if(e.isString(t))return!s(this,t,this.get(t),e.extend({},this.attributes));if(e.isArray(t)){for(var n=0;n<t.length;n++)if(s(this,t[n],this.get(t[n]),e.extend({},this.attributes)))return!1;return!0}return t===!0&&this.validate(),this.validation?this._isValid:!0},validate:function(i,s){var u=this,a=!i,f=e.extend({},r,s),l=n(u),c=e.extend({},l,u.attributes,i),h=i||c,p=o(u,c);u._isValid=p.isValid,e.each(e.keys(l),function(e){var n=p.invalidAttrs.hasOwnProperty(e);n||f.valid(t,e,f.selector)}),e.each(e.keys(l),function(e){var n=p.invalidAttrs.hasOwnProperty(e),r=h.hasOwnProperty(e);n&&(r||a)&&f.invalid(t,e,p.invalidAttrs[e],f.selector)}),e.defer(function(){u.trigger("validated",u._isValid,u,p.invalidAttrs),u.trigger("validated:"+(u._isValid?"valid":"invalid"),u,p.invalidAttrs)});if(!f.forceUpdate&&e.intersection(e.keys(p.invalidAttrs),e.keys(h)).length>0)return p.invalidAttrs}}},f=function(t,n,r){e.extend(n,a(t,r))},l=function(e){delete e.validate,delete e.preValidate,delete e.isValid},c=function(e){f(this.view,e,this.options)},h=function(e){l(e)};return{version:"0.6.3",configure:function(n){e.extend(t,n)},bind:function(n,i){var s=n.model,o=n.collection;i=e.extend({},t,r,i);if(typeof s=="undefined"&&typeof o=="undefined")throw"Before you execute the binding your view must have a model or a collection.\nSee http://thedersen.com/projects/backbone-validation/#using-form-model-validation for more information.";s&&f(n,s,i),o&&(o.each(function(e){f(n,e,i)}),o.bind("add",c,{view:n,options:i}),o.bind("remove",h))},unbind:function(e){var t=e.model,n=e.collection;t&&l(e.model),n&&(n.each(function(e){l(e)}),n.unbind("add",c),n.unbind("remove",h))},mixin:a(null,t)}}(),r=n.callbacks={valid:function(e,t,n){e.$("["+n+"~="+t+"]").removeClass("invalid").removeAttr("data-error")},invalid:function(e,t,n,r){e.$("["+r+"~="+t+"]").addClass("invalid").attr("data-error",n)}},i=n.patterns={digits:/^\d+$/,number:/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/,email:/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i,url:/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i},s=n.messages={required:"{0} is required",acceptance:"{0} must be accepted",min:"{0} must be greater than or equal to {1}",max:"{0} must be less than or equal to {1}",range:"{0} must be between {1} and {2}",length:"{0} must be {1} characters",minLength:"{0} must be at least {1} characters",maxLength:"{0} must be at most {1} characters",rangeLength:"{0} must be between {1} and {2} characters",oneOf:"{0} must be one of: {1}",equalTo:"{0} must be the same as {1}",pattern:"{0} must be a valid {1}"},o=n.labelFormatters={none:function(e){return e},sentenceCase:function(e){return e.replace(/(?:^\w|[A-Z]|\b\w)/g,function(e,t){return t===0?e.toUpperCase():" "+e.toLowerCase()}).replace("_"," ")},label:function(e,t){return t.labels&&t.labels[e]||o.sentenceCase(e,t)}},u=n.validators=function(){var n=String.prototype.trim?function(e){return e===null?"":String.prototype.trim.call(e)}:function(e){var t=/^\s+/,n=/\s+$/;return e===null?"":e.toString().replace(t,"").replace(n,"")},r=function(e,n){return o[t.labelFormatter](e,n)},u=function(){var e=Array.prototype.slice.call(arguments),t=e.shift();return t.replace(/\{(\d+)\}/g,function(t,n){return typeof e[n]!="undefined"?e[n]:t})},a=function(t){return e.isNumber(t)||e.isString(t)&&t.match(i.number)},f=function(t){return!(e.isNull(t)||e.isUndefined(t)||e.isString(t)&&n(t)==="")};return{fn:function(t,n,r,i,s){return e.isString(r)&&(r=i[r]),r.call(i,t,n,s)},required:function(t,n,i,o,a){var l=e.isFunction(i)?i.call(o,t,n,a):i;if(!l&&!f(t))return!1;if(l&&!f(t))return u(s.required,r(n,o))},acceptance:function(t,n,i,o){if(t!=="true"&&(!e.isBoolean(t)||t===!1))return u(s.acceptance,r(n,o))},min:function(e,t,n,i){if(!a(e)||e<n)return u(s.min,r(t,i),n)},max:function(e,t,n,i){if(!a(e)||e>n)return u(s.max,r(t,i),n)},range:function(e,t,n,i){if(!a(e)||e<n[0]||e>n[1])return u(s.range,r(t,i),n[0],n[1])},length:function(e,t,i,o){if(!f(e)||n(e).length!==i)return u(s.length,r(t,o),i)},minLength:function(e,t,i,o){if(!f(e)||n(e).length<i)return u(s.minLength,r(t,o),i)},maxLength:function(e,t,i,o){if(!f(e)||n(e).length>i)return u(s.maxLength,r(t,o),i)},rangeLength:function(e,t,i,o){if(!f(e)||n(e).length<i[0]||n(e).length>i[1])return u(s.rangeLength,r(t,o),i[0],i[1])},oneOf:function(t,n,i,o){if(!e.include(i,t))return u(s.oneOf,r(n,o),i.join(", "))},equalTo:function(e,t,n,i,o){if(e!==o[n])return u(s.equalTo,r(t,i),r(n,i))},pattern:function(e,t,n,o){if(!f(e)||!e.toString().match(i[n]||n))return u(s.pattern,r(t,o),n)}}}();return n}(_);

@@ -1,2 +0,2 @@

// Backbone.Validation v0.6.2
// Backbone.Validation v0.6.3
//

@@ -153,3 +153,4 @@ // Copyright (c) 2011-2012 Thomas Pedersen

opt = _.extend({}, options, setOptions),
allAttrs = _.extend(getValidatedAttrs(model), model.attributes, attrs),
validatedAttrs = getValidatedAttrs(model),
allAttrs = _.extend({}, validatedAttrs, model.attributes, attrs),
changedAttrs = attrs || allAttrs,

@@ -161,13 +162,20 @@ result = validateModel(model, allAttrs);

// After validation is performed, loop through all changed attributes
// and call either the valid or invalid callback so the view is updated.
for(var attr in allAttrs) {
// and call the valid callbacks so the view is updated.
_.each(_.keys(validatedAttrs), function(attr){
var invalid = result.invalidAttrs.hasOwnProperty(attr);
if(!invalid){
opt.valid(view, attr, opt.selector);
}
});
// After validation is performed, loop through all changed attributes
// and call the invalid callback so the view is updated.
_.each(_.keys(validatedAttrs), function(attr){
var invalid = result.invalidAttrs.hasOwnProperty(attr),
changed = changedAttrs.hasOwnProperty(attr);
if(invalid && (changed || validateAll)){
opt.invalid(view, attr, result.invalidAttrs[attr], opt.selector);
}
if(!invalid){
opt.valid(view, attr, opt.selector);
}
}
});

@@ -220,3 +228,3 @@ // Trigger validated events.

// Current version of the library
version: '0.6.2',
version: '0.6.3',

@@ -379,3 +387,3 @@ // Called to configure the default options

label: function(attrName, model) {
return model.labels[attrName] || defaultLabelFormatters.sentenceCase(attrName, model);
return (model.labels && model.labels[attrName]) || defaultLabelFormatters.sentenceCase(attrName, model);
}

@@ -382,0 +390,0 @@ };

{
"name": "backbone-validation",
"title": "Backbone.Validation",
"version": "0.6.2",
"version": "0.6.3",
"author": {

@@ -6,0 +6,0 @@ "name": "Thomas Pedersen",

@@ -1,8 +0,5 @@

# Backbone.Validation v0.6.2
# Backbone.Validation v0.6.3
A validation plugin for [Backbone.js](http://documentcloud.github.com/backbone) that validates both your model as well as form input.
<iframe class="github-btn" src="http://markdotto.github.com/github-buttons/github-btn.html?user=thedersen&repo=backbone.validation&type=watch&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="112px" height="20px"></iframe>
<iframe class="github-btn" src="http://markdotto.github.com/github-buttons/github-btn.html?user=thedersen&repo=backbone.validation&type=fork&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="112px" height="20px"></iframe>
## Introduction

@@ -24,3 +21,3 @@

* Development: [backbone-validation.js](https://raw.github.com/thedersen/backbone.validation/master/dist/backbone-validation.js) *21.1kb*
* Development: [backbone-validation.js](https://raw.github.com/thedersen/backbone.validation/master/dist/backbone-validation.js) *21.5kb*
* Production: [backbone-validation-min.js](https://raw.github.com/thedersen/backbone.validation/master/dist/backbone-validation-min.js) *2.5kb gzipped*

@@ -30,3 +27,3 @@

* Development: [backbone-validation-amd.js](https://raw.github.com/thedersen/backbone.validation/master/dist/backbone-validation-amd.js) *21.4kb*
* Development: [backbone-validation-amd.js](https://raw.github.com/thedersen/backbone.validation/master/dist/backbone-validation-amd.js) *21.8kb*
* Production: [backbone-validation-amd-min.js](https://raw.github.com/thedersen/backbone.validation/master/dist/backbone-validation-amd-min.js) *2.6kb gzipped*

@@ -115,3 +112,3 @@

Note that Backbone.Validation does not provide any automatic/two-way binding between your model and the view, that's up you to implement (you can for instance use [Backbone.ModelBinder](https://github.com/theironcook/Backbone.ModelBinder) or [Rivets.js](http://rivetsjs.com/)).
Note that Backbone.Validation does not provide any automatic/two-way binding between your model and the view, that's up you to implement (you can for instance use [Backbone.stickit](http://nytimes.github.com/backbone.stickit/).

@@ -646,3 +643,3 @@ Before you can start using form validation, you need to bind your view.

* email - Matches a valid email address (e.g. mail@example.com)
* url - Mathes any valid url (e.g. http://www.xample.com)
* url - Matches any valid url (e.g. http://www.example.com)
* digits - Matches any digit(s) (i.e. 0-9)

@@ -729,2 +726,6 @@

## Examples
Some examples can be found [here](http://thedersen.com/projects/backbone-validation/examples/). This is by far not complete, but I hope you get the idea. View source to see how it's made.
## FAQ

@@ -775,2 +776,9 @@

#### v0.6.3
* Labelformatter set to 'label' no longer crashes when no `labels` attribute is present on the model
* Does not invoke callbacks for attributes that are not validated
* Valid callbacks are always called before invalid callbacks (Thanks to [Justin Etheredge](https://github.com/jetheredge))
* Fixed typo in the readme
#### v0.6.2

@@ -777,0 +785,0 @@

@@ -145,3 +145,4 @@ Backbone.Validation = (function(_){

opt = _.extend({}, options, setOptions),
allAttrs = _.extend(getValidatedAttrs(model), model.attributes, attrs),
validatedAttrs = getValidatedAttrs(model),
allAttrs = _.extend({}, validatedAttrs, model.attributes, attrs),
changedAttrs = attrs || allAttrs,

@@ -153,13 +154,20 @@ result = validateModel(model, allAttrs);

// After validation is performed, loop through all changed attributes
// and call either the valid or invalid callback so the view is updated.
for(var attr in allAttrs) {
// and call the valid callbacks so the view is updated.
_.each(_.keys(validatedAttrs), function(attr){
var invalid = result.invalidAttrs.hasOwnProperty(attr);
if(!invalid){
opt.valid(view, attr, opt.selector);
}
});
// After validation is performed, loop through all changed attributes
// and call the invalid callback so the view is updated.
_.each(_.keys(validatedAttrs), function(attr){
var invalid = result.invalidAttrs.hasOwnProperty(attr),
changed = changedAttrs.hasOwnProperty(attr);
if(invalid && (changed || validateAll)){
opt.invalid(view, attr, result.invalidAttrs[attr], opt.selector);
}
if(!invalid){
opt.valid(view, attr, opt.selector);
}
}
});

@@ -212,3 +220,3 @@ // Trigger validated events.

// Current version of the library
version: '0.6.2',
version: '0.6.3',

@@ -371,3 +379,3 @@ // Called to configure the default options

label: function(attrName, model) {
return model.labels[attrName] || defaultLabelFormatters.sentenceCase(attrName, model);
return (model.labels && model.labels[attrName]) || defaultLabelFormatters.sentenceCase(attrName, model);
}

@@ -374,0 +382,0 @@ };

@@ -354,2 +354,13 @@ buster.testCase("Backbone.Validation", {

assert.calledWith(this.valid, this.view, 'name');
},
"callbacks are not called for unvalidated attributes": function(){
this.model.set({age: 1, name: 'name', someProp: 'some value'}, {silent:true});
this.model.validate();
assert.calledWith(this.valid, this.view, 'age');
assert.calledWith(this.valid, this.view, 'name');
refute.calledWith(this.valid, this.view, 'someProp');
}

@@ -356,0 +367,0 @@ }

@@ -55,2 +55,17 @@ buster.testCase('Label formatters', {

assert.equals('Some attribute is required', this.model.preValidate('some_attribute', ''));
},
"returns sentence cased name when label attribute is not defined": function(){
var Model = Backbone.Model.extend({
validation: {
someAttribute: {
required: true
}
}
});
var model = new Model();
_.extend(model, Backbone.Validation.mixin);
assert.equals('Some attribute is required', model.preValidate('someAttribute', ''));
}

@@ -57,0 +72,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc