Comparing version 2.0.7 to 2.1.2
{ | ||
"name": "parsleyjs", | ||
"version": "2.0.7", | ||
"ignore": [ | ||
@@ -16,4 +15,6 @@ "**/.*", | ||
], | ||
"dependencies": { | ||
"jquery": ">1.8" | ||
}, | ||
"devDependencies": { | ||
"jquery": "~1.10.0", | ||
"validator.js": "~1.0.0", | ||
@@ -39,2 +40,2 @@ "requirejs": "~2.1.0", | ||
"main": "dist/parsley.js" | ||
} | ||
} |
# Parsley 2.x changelog | ||
## master | ||
## 2.1.2 | ||
- fix custom triggers after a `reset()` (#926) | ||
- fix documentation and generated dist files | ||
## 2.1.1 | ||
- Bug fix for reentrant validations | ||
## 2.1.0 | ||
- Event remodel | ||
- New API `on` and `off` to register for events | ||
- Global listeners added with `Parsley.on` | ||
- Using the new API, event names no longer have their ".parsley" ending | ||
- Compatibility with previous API is maintained, but `$.emit`, `$.listen`, | ||
etc. are now deprecated (#899) | ||
- New features | ||
- New event 'form:submit' fired before a form is submitted. | ||
- The `value` option can now be a function | ||
- Parsley.version is now the best way to get the current version | ||
- Additional translations | ||
- Changes | ||
- Error containers are created only the first time they are needed. | ||
- [BC Break] `isValid()` field method now returns just a boolean, `[]` is no | ||
more returned when field is optional and empty. `needsValidation()` appears | ||
now to indicate if a valid field needed a validation. | ||
- Bug fixes | ||
- Speed optimization (#855) | ||
- Eemote cache now cleared after form submission (#813) | ||
- Event 'field:reset' now fired if a field is no longer validated (because it | ||
is excluded, or removed) (#841) | ||
- Support for validators with compound names by restoring full case | ||
sensitivity to error messages. (#805) | ||
- Fix conflict between different forms on the same page (#888) | ||
- Handles checkbox names containing spaces (#881) | ||
- Detects name conflicts between validators and regular options | ||
- Compatible with jQuery.noConflict() (#859) | ||
## 2.0.7 | ||
@@ -4,0 +48,0 @@ |
@@ -7,2 +7,16 @@ # Contributing | ||
First thing: make sure you are using the **latest official release**. | ||
## Questions? | ||
Please ask questions on [StackOverflow](http://stackoverflow.com/questions/ask) and be sure to include the `parsley.js` tag. Please **provide an example**, starting for example from [this jsfiddle](http://jsfiddle.net/marcandre/58vnaqur/) | ||
## Issues? | ||
If you believe you have found a bug in `parsley`, please **provide an example**, starting for example from [this jsfiddle](http://jsfiddle.net/marcandre/58vnaqur/). | ||
This makes it possible for you to be sure you have isolated the issue to a minimal case. It also makes it much easier for us to understand your issue. Sometimes the issue is [completely different than what you would expect](https://github.com/guillaumepotier/Parsley.js/issues/711) and only an actual example can lead to a solution. | ||
## Pull requests? | ||
Here are a few simple rules you'll have to follow in order to ease code reviews, | ||
@@ -9,0 +23,0 @@ discussions and PR merging. |
/*! | ||
* Parsleyjs | ||
* Guillaume Potier - <guillaume@wisembly.com> | ||
* Version 2.0.6 - built Sat Jan 24 2015 14:44:37 | ||
* Version 2.1.2 - built Tue Jun 16 2015 10:32:01 | ||
* MIT Licensed | ||
* | ||
*/ | ||
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){"undefined"==typeof a&&"undefined"!=typeof window.jQuery&&(a=window.jQuery);var b={attr:function(a,b,c){var d,e={},f=this.msieversion(),g=new RegExp("^"+b,"i");if("undefined"==typeof a||"undefined"==typeof a[0])return{};for(var h in a[0].attributes)if(d=a[0].attributes[h],"undefined"!=typeof d&&null!==d&&(!f||f>=8||d.specified)&&g.test(d.name)){if("undefined"!=typeof c&&new RegExp(c+"$","i").test(d.name))return!0;e[this.camelize(d.name.replace(b,""))]=this.deserializeValue(d.value)}return"undefined"==typeof c?e:!1},setAttr:function(a,b,c,d){a[0].setAttribute(this.dasherize(b+c),String(d))},get:function(a,b){for(var c=0,d=(b||"").split(".");this.isObject(a)||this.isArray(a);)if(a=a[d[c++]],c===d.length)return a;return void 0},hash:function(a){return String(Math.random()).substring(2,a?a+2:9)},isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)},isObject:function(a){return a===Object(a)},deserializeValue:function(b){var c;try{return b?"true"==b||("false"==b?!1:"null"==b?null:isNaN(c=Number(b))?/^[\[\{]/.test(b)?a.parseJSON(b):b:c):b}catch(d){return b}},camelize:function(a){return a.replace(/-+(.)?/g,function(a,b){return b?b.toUpperCase():""})},dasherize:function(a){return a.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()},msieversion:function(){var a=window.navigator.userAgent,b=a.indexOf("MSIE ");return b>0||navigator.userAgent.match(/Trident.*rv\:11\./)?parseInt(a.substring(b+5,a.indexOf(".",b)),10):0}},c={namespace:"data-parsley-",inputs:"input, textarea, select",excluded:"input[type=button], input[type=submit], input[type=reset], input[type=hidden]",priorityEnabled:!0,uiEnabled:!0,validationThreshold:3,focus:"first",trigger:!1,errorClass:"parsley-error",successClass:"parsley-success",classHandler:function(){},errorsContainer:function(){},errorsWrapper:'<ul class="parsley-errors-list"></ul>',errorTemplate:"<li></li>"},d=function(){};d.prototype={asyncSupport:!1,actualizeOptions:function(){return this.options=this.OptionsFactory.get(this),this},validateThroughValidator:function(a,b,c){return window.ParsleyValidator.validate(a,b,c)},subscribe:function(b,c){return a.listenTo(this,b.toLowerCase(),c),this},unsubscribe:function(b){return a.unsubscribeTo(this,b.toLowerCase()),this},reset:function(){if("ParsleyForm"!==this.__class__)return a.emit("parsley:field:reset",this);for(var b=0;b<this.fields.length;b++)a.emit("parsley:field:reset",this.fields[b]);a.emit("parsley:form:reset",this)},destroy:function(){if("ParsleyForm"!==this.__class__)return this.$element.removeData("Parsley"),this.$element.removeData("ParsleyFieldMultiple"),void a.emit("parsley:field:destroy",this);for(var b=0;b<this.fields.length;b++)this.fields[b].destroy();this.$element.removeData("Parsley"),a.emit("parsley:form:destroy",this)}};var e=function(){var a={},b=function(a){this.__class__="Validator",this.__version__="1.0.1",this.options=a||{},this.bindingKey=this.options.bindingKey||"_validatorjsConstraint"};b.prototype={constructor:b,validate:function(a,b,c){if("string"!=typeof a&&"object"!=typeof a)throw new Error("You must validate an object or a string");return"string"==typeof a||g(a)?this._validateString(a,b,c):this.isBinded(a)?this._validateBindedObject(a,b):this._validateObject(a,b,c)},bind:function(a,b){if("object"!=typeof a)throw new Error("Must bind a Constraint to an object");return a[this.bindingKey]=new c(b),this},unbind:function(a){return"undefined"==typeof a._validatorjsConstraint?this:(delete a[this.bindingKey],this)},isBinded:function(a){return"undefined"!=typeof a[this.bindingKey]},getBinded:function(a){return this.isBinded(a)?a[this.bindingKey]:null},_validateString:function(a,b,c){var f,h=[];g(b)||(b=[b]);for(var i=0;i<b.length;i++){if(!(b[i]instanceof e))throw new Error("You must give an Assert or an Asserts array to validate a string");f=b[i].check(a,c),f instanceof d&&h.push(f)}return h.length?h:!0},_validateObject:function(a,b,d){if("object"!=typeof b)throw new Error("You must give a constraint to validate an object");return b instanceof c?b.check(a,d):new c(b).check(a,d)},_validateBindedObject:function(a,b){return a[this.bindingKey].check(a,b)}},b.errorCode={must_be_a_string:"must_be_a_string",must_be_an_array:"must_be_an_array",must_be_a_number:"must_be_a_number",must_be_a_string_or_array:"must_be_a_string_or_array"};var c=function(a,b){if(this.__class__="Constraint",this.options=b||{},this.nodes={},a)try{this._bootstrap(a)}catch(c){throw new Error("Should give a valid mapping object to Constraint",c,a)}};c.prototype={constructor:c,check:function(a,b){var c,d={};for(var h in this.nodes){for(var i=!1,j=this.get(h),k=g(j)?j:[j],l=k.length-1;l>=0;l--)"Required"!==k[l].__class__||(i=k[l].requiresValidation(b));if(this.has(h,a)||this.options.strict||i)try{this.has(h,this.options.strict||i?a:void 0)||(new e).HaveProperty(h).validate(a),c=this._check(h,a[h],b),(g(c)&&c.length>0||!g(c)&&!f(c))&&(d[h]=c)}catch(m){d[h]=m}}return f(d)?!0:d},add:function(a,b){if(b instanceof e||g(b)&&b[0]instanceof e)return this.nodes[a]=b,this;if("object"==typeof b&&!g(b))return this.nodes[a]=b instanceof c?b:new c(b),this;throw new Error("Should give an Assert, an Asserts array, a Constraint",b)},has:function(a,b){return b="undefined"!=typeof b?b:this.nodes,"undefined"!=typeof b[a]},get:function(a,b){return this.has(a)?this.nodes[a]:b||null},remove:function(a){var b=[];for(var c in this.nodes)c!==a&&(b[c]=this.nodes[c]);return this.nodes=b,this},_bootstrap:function(a){if(a instanceof c)return this.nodes=a.nodes;for(var b in a)this.add(b,a[b])},_check:function(a,b,d){if(this.nodes[a]instanceof e)return this._checkAsserts(b,[this.nodes[a]],d);if(g(this.nodes[a]))return this._checkAsserts(b,this.nodes[a],d);if(this.nodes[a]instanceof c)return this.nodes[a].check(b,d);throw new Error("Invalid node",this.nodes[a])},_checkAsserts:function(a,b,c){for(var d,e=[],f=0;f<b.length;f++)d=b[f].check(a,c),"undefined"!=typeof d&&!0!==d&&e.push(d);return e}};var d=function(a,b,c){if(this.__class__="Violation",!(a instanceof e))throw new Error("Should give an assertion implementing the Assert interface");this.assert=a,this.value=b,"undefined"!=typeof c&&(this.violation=c)};d.prototype={show:function(){var a={assert:this.assert.__class__,value:this.value};return this.violation&&(a.violation=this.violation),a},__toString:function(){return"undefined"!=typeof this.violation&&(this.violation='", '+this.getViolation().constraint+" expected was "+this.getViolation().expected),this.assert.__class__+' assert failed for "'+this.value+this.violation||""},getViolation:function(){var a,b;for(a in this.violation)b=this.violation[a];return{constraint:a,expected:b}}};var e=function(a){this.__class__="Assert",this.__parentClass__=this.__class__,this.groups=[],"undefined"!=typeof a&&this.addGroup(a)};e.prototype={construct:e,requiresValidation:function(a){return a&&!this.hasGroup(a)?!1:!a&&this.hasGroups()?!1:!0},check:function(a,b){if(this.requiresValidation(b))try{return this.validate(a,b)}catch(c){return c}},hasGroup:function(a){return g(a)?this.hasOneOf(a):"Any"===a?!0:this.hasGroups()?-1!==this.groups.indexOf(a):"Default"===a},hasOneOf:function(a){for(var b=0;b<a.length;b++)if(this.hasGroup(a[b]))return!0;return!1},hasGroups:function(){return this.groups.length>0},addGroup:function(a){return g(a)?this.addGroups(a):(this.hasGroup(a)||this.groups.push(a),this)},removeGroup:function(a){for(var b=[],c=0;c<this.groups.length;c++)a!==this.groups[c]&&b.push(this.groups[c]);return this.groups=b,this},addGroups:function(a){for(var b=0;b<a.length;b++)this.addGroup(a[b]);return this},HaveProperty:function(a){return this.__class__="HaveProperty",this.node=a,this.validate=function(a){if("undefined"==typeof a[this.node])throw new d(this,a,{value:this.node});return!0},this},Blank:function(){return this.__class__="Blank",this.validate=function(a){if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(""!==a.replace(/^\s+/g,"").replace(/\s+$/g,""))throw new d(this,a);return!0},this},Callback:function(a){if(this.__class__="Callback",this.arguments=Array.prototype.slice.call(arguments),1===this.arguments.length?this.arguments=[]:this.arguments.splice(0,1),"function"!=typeof a)throw new Error("Callback must be instanciated with a function");return this.fn=a,this.validate=function(a){var b=this.fn.apply(this,[a].concat(this.arguments));if(!0!==b)throw new d(this,a,{result:b});return!0},this},Choice:function(a){if(this.__class__="Choice",!g(a)&&"function"!=typeof a)throw new Error("Choice must be instanciated with an array or a function");return this.list=a,this.validate=function(a){for(var b="function"==typeof this.list?this.list():this.list,c=0;c<b.length;c++)if(a===b[c])return!0;throw new d(this,a,{choices:b})},this},Collection:function(a){return this.__class__="Collection",this.constraint="undefined"!=typeof a?a instanceof e?a:new c(a):!1,this.validate=function(a,c){var e,h=new b,i=0,j={},k=this.groups.length?this.groups:c;if(!g(a))throw new d(this,a,{value:b.errorCode.must_be_an_array});for(var l=0;l<a.length;l++)e=this.constraint?h.validate(a[l],this.constraint,k):h.validate(a[l],k),f(e)||(j[i]=e),i++;return f(j)?!0:j},this},Count:function(a){return this.__class__="Count",this.count=a,this.validate=function(a){if(!g(a))throw new d(this,a,{value:b.errorCode.must_be_an_array});var c="function"==typeof this.count?this.count(a):this.count;if(isNaN(Number(c)))throw new Error("Count must be a valid interger",c);if(c!==a.length)throw new d(this,a,{count:c});return!0},this},Email:function(){return this.__class__="Email",this.validate=function(a){var c=/^((([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;if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(!c.test(a))throw new d(this,a);return!0},this},EqualTo:function(a){if(this.__class__="EqualTo","undefined"==typeof a)throw new Error("EqualTo must be instanciated with a value or a function");return this.reference=a,this.validate=function(a){var b="function"==typeof this.reference?this.reference(a):this.reference;if(b!==a)throw new d(this,a,{value:b});return!0},this},GreaterThan:function(a){if(this.__class__="GreaterThan","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold>=a)throw new d(this,a,{threshold:this.threshold});return!0},this},GreaterThanOrEqual:function(a){if(this.__class__="GreaterThanOrEqual","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold>a)throw new d(this,a,{threshold:this.threshold});return!0},this},InstanceOf:function(a){if(this.__class__="InstanceOf","undefined"==typeof a)throw new Error("InstanceOf must be instanciated with a value");return this.classRef=a,this.validate=function(a){if(!0!=a instanceof this.classRef)throw new d(this,a,{classRef:this.classRef});return!0},this},Length:function(a){if(this.__class__="Length",!a.min&&!a.max)throw new Error("Lenth assert must be instanciated with a { min: x, max: y } object");return this.min=a.min,this.max=a.max,this.validate=function(a){if("string"!=typeof a&&!g(a))throw new d(this,a,{value:b.errorCode.must_be_a_string_or_array});if("undefined"!=typeof this.min&&this.min===this.max&&a.length!==this.min)throw new d(this,a,{min:this.min,max:this.max});if("undefined"!=typeof this.max&&a.length>this.max)throw new d(this,a,{max:this.max});if("undefined"!=typeof this.min&&a.length<this.min)throw new d(this,a,{min:this.min});return!0},this},LessThan:function(a){if(this.__class__="LessThan","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold<=a)throw new d(this,a,{threshold:this.threshold});return!0},this},LessThanOrEqual:function(a){if(this.__class__="LessThanOrEqual","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold<a)throw new d(this,a,{threshold:this.threshold});return!0},this},NotNull:function(){return this.__class__="NotNull",this.validate=function(a){if(null===a||"undefined"==typeof a)throw new d(this,a);return!0},this},NotBlank:function(){return this.__class__="NotBlank",this.validate=function(a){if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(""===a.replace(/^\s+/g,"").replace(/\s+$/g,""))throw new d(this,a);return!0},this},Null:function(){return this.__class__="Null",this.validate=function(a){if(null!==a)throw new d(this,a);return!0},this},Range:function(a,b){if(this.__class__="Range","undefined"==typeof a||"undefined"==typeof b)throw new Error("Range assert expects min and max values");return this.min=a,this.max=b,this.validate=function(a){try{return"string"==typeof a&&isNaN(Number(a))||g(a)?(new e).Length({min:this.min,max:this.max}).validate(a):(new e).GreaterThanOrEqual(this.min).validate(a)&&(new e).LessThanOrEqual(this.max).validate(a),!0}catch(b){throw new d(this,a,b.violation)}return!0},this},Regexp:function(a,c){if(this.__class__="Regexp","undefined"==typeof a)throw new Error("You must give a regexp");return this.regexp=a,this.flag=c||"",this.validate=function(a){if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(!new RegExp(this.regexp,this.flag).test(a))throw new d(this,a,{regexp:this.regexp,flag:this.flag});return!0},this},Required:function(){return this.__class__="Required",this.validate=function(a){if("undefined"==typeof a)throw new d(this,a);try{"string"==typeof a?(new e).NotNull().validate(a)&&(new e).NotBlank().validate(a):!0===g(a)&&(new e).Length({min:1}).validate(a)}catch(b){throw new d(this,a)}return!0},this},Unique:function(a){return this.__class__="Unique","object"==typeof a&&(this.key=a.key),this.validate=function(a){var c,e=[];if(!g(a))throw new d(this,a,{value:b.errorCode.must_be_an_array});for(var f=0;f<a.length;f++)if(c="object"==typeof a[f]?a[f][this.key]:a[f],"undefined"!=typeof c){if(-1!==e.indexOf(c))throw new d(this,a,{value:c});e.push(c)}return!0},this}},a.Assert=e,a.Validator=b,a.Violation=d,a.Constraint=c,Array.prototype.indexOf||(Array.prototype.indexOf=function(a){if(null===this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!==d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1});var f=function(a){for(var b in a)return!1;return!0},g=function(a){return"[object Array]"===Object.prototype.toString.call(a)};return"function"==typeof define&&define.amd?define("vendors/validator.js/dist/validator",[],function(){return a}):"undefined"!=typeof module&&module.exports?module.exports=a:window["undefined"!=typeof validatorjs_ns?validatorjs_ns:"Validator"]=a,a}();e="undefined"!=typeof e?e:"undefined"!=typeof module?module.exports:null;var f=function(a,b){this.__class__="ParsleyValidator",this.Validator=e,this.locale="en",this.init(a||{},b||{})};f.prototype={init:function(b,c){this.catalog=c;for(var d in b)this.addValidator(d,b[d].fn,b[d].priority,b[d].requirementsTransformer);a.emit("parsley:validator:init")},setLocale:function(a){if("undefined"==typeof this.catalog[a])throw new Error(a+" is not available in the catalog");return this.locale=a,this},addCatalog:function(a,b,c){return"object"==typeof b&&(this.catalog[a]=b),!0===c?this.setLocale(a):this},addMessage:function(a,b,c){return"undefined"==typeof this.catalog[a]&&(this.catalog[a]={}),this.catalog[a][b.toLowerCase()]=c,this},validate:function(){return(new this.Validator.Validator).validate.apply(new e.Validator,arguments)},addValidator:function(b,c,d,f){return this.validators[b.toLowerCase()]=function(b){return a.extend((new e.Assert).Callback(c,b),{priority:d,requirementsTransformer:f})},this},updateValidator:function(a,b,c,d){return this.addValidator(a,b,c,d)},removeValidator:function(a){return delete this.validators[a],this},getErrorMessage:function(a){var b;return b="type"===a.name?this.catalog[this.locale][a.name][a.requirements]:this.formatMessage(this.catalog[this.locale][a.name],a.requirements),""!==b?b:this.catalog[this.locale].defaultMessage},formatMessage:function(a,b){if("object"==typeof b){for(var c in b)a=this.formatMessage(a,b[c]);return a}return"string"==typeof a?a.replace(new RegExp("%s","i"),b):""},validators:{notblank:function(){return a.extend((new e.Assert).NotBlank(),{priority:2})},required:function(){return a.extend((new e.Assert).Required(),{priority:512})},type:function(b){var c;switch(b){case"email":c=(new e.Assert).Email();break;case"range":case"number":c=(new e.Assert).Regexp("^-?(?:\\d+|\\d{1,3}(?:,\\d{3})+)?(?:\\.\\d+)?$");break;case"integer":c=(new e.Assert).Regexp("^-?\\d+$");break;case"digits":c=(new e.Assert).Regexp("^\\d+$");break;case"alphanum":c=(new e.Assert).Regexp("^\\w+$","i");break;case"url":c=(new e.Assert).Regexp("(https?:\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,24}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)","i");break;default:throw new Error("validator type `"+b+"` is not supported")}return a.extend(c,{priority:256})},pattern:function(b){var c="";return/^\/.*\/(?:[gimy]*)$/.test(b)&&(c=b.replace(/.*\/([gimy]*)$/,"$1"),b=b.replace(new RegExp("^/(.*?)/"+c+"$"),"$1")),a.extend((new e.Assert).Regexp(b,c),{priority:64})},minlength:function(b){return a.extend((new e.Assert).Length({min:b}),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},maxlength:function(b){return a.extend((new e.Assert).Length({max:b}),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},length:function(b){return a.extend((new e.Assert).Length({min:b[0],max:b[1]}),{priority:32})},mincheck:function(a){return this.minlength(a)},maxcheck:function(a){return this.maxlength(a)},check:function(a){return this.length(a)},min:function(b){return a.extend((new e.Assert).GreaterThanOrEqual(b),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},max:function(b){return a.extend((new e.Assert).LessThanOrEqual(b),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},range:function(b){return a.extend((new e.Assert).Range(b[0],b[1]),{priority:32,requirementsTransformer:function(){for(var a=0;a<b.length;a++)b[a]="string"!=typeof b[a]||isNaN(b[a])?b[a]:parseInt(b[a],10);return b}})},equalto:function(b){return a.extend((new e.Assert).EqualTo(b),{priority:256,requirementsTransformer:function(){return a(b).length?a(b).val():b}})}}};var g=function(){this.__class__="ParsleyUI"};g.prototype={listen:function(){return a.listen("parsley:form:init",this,this.setupForm),a.listen("parsley:field:init",this,this.setupField),a.listen("parsley:field:validated",this,this.reflow),a.listen("parsley:form:validated",this,this.focus),a.listen("parsley:field:reset",this,this.reset),a.listen("parsley:form:destroy",this,this.destroy),a.listen("parsley:field:destroy",this,this.destroy),this},reflow:function(a){if("undefined"!=typeof a._ui&&!1!==a._ui.active){var b=this._diff(a.validationResult,a._ui.lastValidationResult);a._ui.lastValidationResult=a.validationResult,a._ui.validatedOnce=!0,this.manageStatusClass(a),this.manageErrorsMessages(a,b),this.actualizeTriggers(a),(b.kept.length||b.added.length)&&"undefined"==typeof a._ui.failedOnce&&this.manageFailingFieldTrigger(a)}},getErrorsMessages:function(a){if(!0===a.validationResult)return[];for(var b=[],c=0;c<a.validationResult.length;c++)b.push(this._getErrorMessage(a,a.validationResult[c].assert));return b},manageStatusClass:function(a){!0===a.validationResult?this._successClass(a):a.validationResult.length>0?this._errorClass(a):this._resetClass(a)},manageErrorsMessages:function(b,c){if("undefined"==typeof b.options.errorsMessagesDisabled){if("undefined"!=typeof b.options.errorMessage)return c.added.length||c.kept.length?(0===b._ui.$errorsWrapper.find(".parsley-custom-error-message").length&&b._ui.$errorsWrapper.append(a(b.options.errorTemplate).addClass("parsley-custom-error-message")),b._ui.$errorsWrapper.addClass("filled").find(".parsley-custom-error-message").html(b.options.errorMessage)):b._ui.$errorsWrapper.removeClass("filled").find(".parsley-custom-error-message").remove();for(var d=0;d<c.removed.length;d++)this.removeError(b,c.removed[d].assert.name,!0);for(d=0;d<c.added.length;d++)this.addError(b,c.added[d].assert.name,void 0,c.added[d].assert,!0);for(d=0;d<c.kept.length;d++)this.updateError(b,c.kept[d].assert.name,void 0,c.kept[d].assert,!0)}},addError:function(b,c,d,e,f){b._ui.$errorsWrapper.addClass("filled").append(a(b.options.errorTemplate).addClass("parsley-"+c).html(d||this._getErrorMessage(b,e))),!0!==f&&this._errorClass(b)},updateError:function(a,b,c,d,e){a._ui.$errorsWrapper.addClass("filled").find(".parsley-"+b).html(c||this._getErrorMessage(a,d)),!0!==e&&this._errorClass(a)},removeError:function(a,b,c){a._ui.$errorsWrapper.removeClass("filled").find(".parsley-"+b).remove(),!0!==c&&this.manageStatusClass(a)},focus:function(a){if(!0===a.validationResult||"none"===a.options.focus)return a._focusedField=null;a._focusedField=null;for(var b=0;b<a.fields.length;b++)if(!0!==a.fields[b].validationResult&&a.fields[b].validationResult.length>0&&"undefined"==typeof a.fields[b].options.noFocus){if("first"===a.options.focus)return a._focusedField=a.fields[b].$element,a._focusedField.focus();a._focusedField=a.fields[b].$element}return null===a._focusedField?null:a._focusedField.focus()},_getErrorMessage:function(a,b){var c=b.name+"Message";return"undefined"!=typeof a.options[c]?window.ParsleyValidator.formatMessage(a.options[c],b.requirements):window.ParsleyValidator.getErrorMessage(b)},_diff:function(a,b,c){for(var d=[],e=[],f=0;f<a.length;f++){for(var g=!1,h=0;h<b.length;h++)if(a[f].assert.name===b[h].assert.name){g=!0;break}g?e.push(a[f]):d.push(a[f])}return{kept:e,added:d,removed:c?[]:this._diff(b,a,!0).added}},setupForm:function(b){b.$element.on("submit.Parsley",!1,a.proxy(b.onSubmitValidate,b)),!1!==b.options.uiEnabled&&b.$element.attr("novalidate","")},setupField:function(b){var c={active:!1};!1!==b.options.uiEnabled&&(c.active=!0,b.$element.attr(b.options.namespace+"id",b.__id__),c.$errorClassHandler=this._manageClassHandler(b),c.errorsWrapperId="parsley-id-"+("undefined"!=typeof b.options.multiple?"multiple-"+b.options.multiple:b.__id__),c.$errorsWrapper=a(b.options.errorsWrapper).attr("id",c.errorsWrapperId),c.lastValidationResult=[],c.validatedOnce=!1,c.validationInformationVisible=!1,b._ui=c,b.$element.is(b.options.excluded)||this._insertErrorWrapper(b),this.actualizeTriggers(b))},_manageClassHandler:function(b){if("string"==typeof b.options.classHandler&&a(b.options.classHandler).length)return a(b.options.classHandler);var c=b.options.classHandler(b);return"undefined"!=typeof c&&c.length?c:"undefined"==typeof b.options.multiple||b.$element.is("select")?b.$element:b.$element.parent()},_insertErrorWrapper:function(b){var c;if("string"==typeof b.options.errorsContainer){if(a(b.options.errorsContainer).length)return a(b.options.errorsContainer).append(b._ui.$errorsWrapper);window.console&&window.console.warn&&window.console.warn("The errors container `"+b.options.errorsContainer+"` does not exist in DOM")}else"function"==typeof b.options.errorsContainer&&(c=b.options.errorsContainer(b));return"undefined"!=typeof c&&c.length?c.append(b._ui.$errorsWrapper):"undefined"==typeof b.options.multiple?b.$element.after(b._ui.$errorsWrapper):b.$element.parent().after(b._ui.$errorsWrapper)},actualizeTriggers:function(b){var c=b.$element;if(b.options.multiple&&(c=a("["+b.options.namespace+'multiple="'+b.options.multiple+'"]')),c.off(".Parsley"),!1!==b.options.trigger){var d=b.options.trigger.replace(/^\s+/g,"").replace(/\s+$/g,"");""!==d&&c.on(d.split(" ").join(".Parsley ")+".Parsley",a.proxy("function"==typeof b.eventValidate?b.eventValidate:this.eventValidate,b))}},eventValidate:function(a){new RegExp("key").test(a.type)&&!this._ui.validationInformationVisible&&this.getValue().length<=this.options.validationThreshold||(this._ui.validatedOnce=!0,this.validate())},manageFailingFieldTrigger:function(b){return b._ui.failedOnce=!0,b.options.multiple&&a("["+b.options.namespace+'multiple="'+b.options.multiple+'"]').each(function(){return new RegExp("change","i").test(a(this).parsley().options.trigger||"")?void 0:a(this).on("change.ParsleyFailedOnce",!1,a.proxy(b.validate,b))}),b.$element.is("select")&&!new RegExp("change","i").test(b.options.trigger||"")?b.$element.on("change.ParsleyFailedOnce",!1,a.proxy(b.validate,b)):new RegExp("keyup","i").test(b.options.trigger||"")?void 0:b.$element.on("keyup.ParsleyFailedOnce",!1,a.proxy(b.validate,b))},reset:function(a){a.$element.off(".Parsley"),a.$element.off(".ParsleyFailedOnce"),"undefined"!=typeof a._ui&&"ParsleyForm"!==a.__class__&&(a._ui.$errorsWrapper.removeClass("filled").children().remove(),this._resetClass(a),a._ui.validatedOnce=!1,a._ui.lastValidationResult=[],a._ui.validationInformationVisible=!1)},destroy:function(a){this.reset(a),"ParsleyForm"!==a.__class__&&("undefined"!=typeof a._ui&&a._ui.$errorsWrapper.remove(),delete a._ui)},_successClass:function(a){a._ui.validationInformationVisible=!0,a._ui.$errorClassHandler.removeClass(a.options.errorClass).addClass(a.options.successClass)},_errorClass:function(a){a._ui.validationInformationVisible=!0,a._ui.$errorClassHandler.removeClass(a.options.successClass).addClass(a.options.errorClass)},_resetClass:function(a){a._ui.$errorClassHandler.removeClass(a.options.successClass).removeClass(a.options.errorClass)}};var h=function(c,d,e,f){this.__class__="OptionsFactory",this.__id__=b.hash(4),this.formOptions=null,this.fieldOptions=null,this.staticOptions=a.extend(!0,{},c,d,e,{namespace:f})};h.prototype={get:function(a){if("undefined"==typeof a.__class__)throw new Error("Parsley Instance expected");switch(a.__class__){case"Parsley":return this.staticOptions;case"ParsleyForm":return this.getFormOptions(a);case"ParsleyField":case"ParsleyFieldMultiple":return this.getFieldOptions(a);default:throw new Error("Instance "+a.__class__+" is not supported")}},getFormOptions:function(c){return this.formOptions=b.attr(c.$element,this.staticOptions.namespace),a.extend({},this.staticOptions,this.formOptions)},getFieldOptions:function(c){return this.fieldOptions=b.attr(c.$element,this.staticOptions.namespace),null===this.formOptions&&"undefined"!=typeof c.parent&&(this.formOptions=this.getFormOptions(c.parent)),a.extend({},this.staticOptions,this.formOptions,this.fieldOptions)}};var i=function(c,d){if(this.__class__="ParsleyForm",this.__id__=b.hash(4),"OptionsFactory"!==b.get(d,"__class__"))throw new Error("You must give an OptionsFactory instance");this.OptionsFactory=d,this.$element=a(c),this.validationResult=null,this.options=this.OptionsFactory.get(this)};i.prototype={onSubmitValidate:function(b){return this.validate(void 0,void 0,b),!1===this.validationResult&&b instanceof a.Event&&(b.stopImmediatePropagation(),b.preventDefault()),this},validate:function(b,c,d){this.submitEvent=d,this.validationResult=!0;var e=[];a.emit("parsley:form:validate",this),this._refreshFields();for(var f=0;f<this.fields.length;f++)(!b||this._isFieldInGroup(this.fields[f],b))&&(e=this.fields[f].validate(c),!0!==e&&e.length>0&&this.validationResult&&(this.validationResult=!1));return a.emit("parsley:form:"+(this.validationResult?"success":"error"),this),a.emit("parsley:form:validated",this),this.validationResult},isValid:function(a,b){this._refreshFields();for(var c=0;c<this.fields.length;c++)if((!a||this._isFieldInGroup(this.fields[c],a))&&!1===this.fields[c].isValid(b))return!1;return!0},_isFieldInGroup:function(c,d){return b.isArray(c.options.group)?-1!==a.inArray(d,c.options.group):c.options.group===d},_refreshFields:function(){return this.actualizeOptions()._bindFields()},_bindFields:function(){var a=this;return this.fields=[],this.fieldsMappedById={},this.$element.find(this.options.inputs).each(function(){var b=new window.Parsley(this,{},a);"ParsleyField"!==b.__class__&&"ParsleyFieldMultiple"!==b.__class__||b.$element.is(b.options.excluded)||"undefined"==typeof a.fieldsMappedById[b.__class__+"-"+b.__id__]&&(a.fieldsMappedById[b.__class__+"-"+b.__id__]=b,a.fields.push(b))}),this}};var j=function(c,d,e,f,g){var h={};if(!new RegExp("ParsleyField").test(b.get(c,"__class__")))throw new Error("ParsleyField or ParsleyFieldMultiple instance expected");if("function"==typeof window.ParsleyValidator.validators[d]&&(h=window.ParsleyValidator.validators[d](e)),"Assert"!==h.__parentClass__)throw new Error("Valid validator expected");var i=function(){return"undefined"!=typeof c.options[d+"Priority"]?c.options[d+"Priority"]:b.get(h,"priority")||2};return f=f||i(),"function"==typeof h.requirementsTransformer&&(e=h.requirementsTransformer(),h=window.ParsleyValidator.validators[d](e)),a.extend(h,{name:d,requirements:e,priority:f,groups:[f],isDomConstraint:g||b.attr(c.$element,c.options.namespace,d)})},k=function(c,d,e){this.__class__="ParsleyField",this.__id__=b.hash(4),this.$element=a(c),"undefined"!=typeof e?(this.parent=e,this.OptionsFactory=this.parent.OptionsFactory,this.options=this.OptionsFactory.get(this)):(this.OptionsFactory=d,this.options=this.OptionsFactory.get(this)),this.constraints=[],this.constraintsByName={},this.validationResult=[],this._bindConstraints()};k.prototype={validate:function(b){return this.value=this.getValue(),a.emit("parsley:field:validate",this),a.emit("parsley:field:"+(this.isValid(b,this.value)?"success":"error"),this),a.emit("parsley:field:validated",this),this.validationResult},isValid:function(a,b){this.refreshConstraints();var c=this._getConstraintsSortedPriorities();if(0===c.length)return this.validationResult=[];if(("undefined"==typeof b||null===b)&&(b=this.getValue()),!b.length&&!this._isRequired()&&"undefined"==typeof this.options.validateIfEmpty&&!0!==a)return this.validationResult=[];if(!1===this.options.priorityEnabled)return!0===(this.validationResult=this.validateThroughValidator(b,this.constraints,"Any"));for(var d=0;d<c.length;d++)if(!0!==(this.validationResult=this.validateThroughValidator(b,this.constraints,c[d])))return!1;return!0},getValue:function(){var a;return a="undefined"!=typeof this.options.value?this.options.value:this.$element.val(),"undefined"==typeof a||null===a?"":!0===this.options.trimValue?a.replace(/^\s+|\s+$/g,""):a},refreshConstraints:function(){return this.actualizeOptions()._bindConstraints()},addConstraint:function(a,b,c,d){if(a=a.toLowerCase(),"function"==typeof window.ParsleyValidator.validators[a]){var e=new j(this,a,b,c,d); | ||
"undefined"!==this.constraintsByName[e.name]&&this.removeConstraint(e.name),this.constraints.push(e),this.constraintsByName[e.name]=e}return this},removeConstraint:function(a){for(var b=0;b<this.constraints.length;b++)if(a===this.constraints[b].name){this.constraints.splice(b,1);break}return delete this.constraintsByName[a],this},updateConstraint:function(a,b,c){return this.removeConstraint(a).addConstraint(a,b,c)},_bindConstraints:function(){for(var a=[],b={},c=0;c<this.constraints.length;c++)!1===this.constraints[c].isDomConstraint&&(a.push(this.constraints[c]),b[this.constraints[c].name]=this.constraints[c]);this.constraints=a,this.constraintsByName=b;for(var d in this.options)this.addConstraint(d,this.options[d]);return this._bindHtml5Constraints()},_bindHtml5Constraints:function(){(this.$element.hasClass("required")||this.$element.attr("required"))&&this.addConstraint("required",!0,void 0,!0),"string"==typeof this.$element.attr("pattern")&&this.addConstraint("pattern",this.$element.attr("pattern"),void 0,!0),"undefined"!=typeof this.$element.attr("min")&&"undefined"!=typeof this.$element.attr("max")?this.addConstraint("range",[this.$element.attr("min"),this.$element.attr("max")],void 0,!0):"undefined"!=typeof this.$element.attr("min")?this.addConstraint("min",this.$element.attr("min"),void 0,!0):"undefined"!=typeof this.$element.attr("max")&&this.addConstraint("max",this.$element.attr("max"),void 0,!0),"undefined"!=typeof this.$element.attr("minlength")&&"undefined"!=typeof this.$element.attr("maxlength")?this.addConstraint("length",[this.$element.attr("minlength"),this.$element.attr("maxlength")],void 0,!0):"undefined"!=typeof this.$element.attr("minlength")?this.addConstraint("minlength",this.$element.attr("minlength"),void 0,!0):"undefined"!=typeof this.$element.attr("maxlength")&&this.addConstraint("maxlength",this.$element.attr("maxlength"),void 0,!0);var a=this.$element.attr("type");return"undefined"==typeof a?this:"number"===a?"undefined"==typeof this.$element.attr("step")||0===parseFloat(this.$element.attr("step"))%1?this.addConstraint("type","integer",void 0,!0):this.addConstraint("type","number",void 0,!0):new RegExp(a,"i").test("email url range")?this.addConstraint("type",a,void 0,!0):this},_isRequired:function(){return"undefined"==typeof this.constraintsByName.required?!1:!1!==this.constraintsByName.required.requirements},_getConstraintsSortedPriorities:function(){for(var a=[],b=0;b<this.constraints.length;b++)-1===a.indexOf(this.constraints[b].priority)&&a.push(this.constraints[b].priority);return a.sort(function(a,b){return b-a}),a}};var l=function(){this.__class__="ParsleyFieldMultiple"};l.prototype={addElement:function(a){return this.$elements.push(a),this},refreshConstraints:function(){var b;if(this.constraints=[],this.$element.is("select"))return this.actualizeOptions()._bindConstraints(),this;for(var c=0;c<this.$elements.length;c++)if(a("html").has(this.$elements[c]).length){b=this.$elements[c].data("ParsleyFieldMultiple").refreshConstraints().constraints;for(var d=0;d<b.length;d++)this.addConstraint(b[d].name,b[d].requirements,b[d].priority,b[d].isDomConstraint)}else this.$elements.splice(c,1);return this},getValue:function(){if("undefined"!=typeof this.options.value)return this.options.value;if(this.$element.is("input[type=radio]"))return a("["+this.options.namespace+'multiple="'+this.options.multiple+'"]:checked').val()||"";if(this.$element.is("input[type=checkbox]")){var b=[];return a("["+this.options.namespace+'multiple="'+this.options.multiple+'"]:checked').each(function(){b.push(a(this).val())}),b.length?b:[]}return this.$element.is("select")&&null===this.$element.val()?[]:this.$element.val()},_init:function(a){return this.$elements=[this.$element],this.options.multiple=a,this}};var m=a({}),n={};a.listen=function(a){if("undefined"==typeof n[a]&&(n[a]=[]),"function"==typeof arguments[1])return n[a].push({fn:arguments[1]});if("object"==typeof arguments[1]&&"function"==typeof arguments[2])return n[a].push({fn:arguments[2],ctxt:arguments[1]});throw new Error("Wrong parameters")},a.listenTo=function(a,b,c){if("undefined"==typeof n[b]&&(n[b]=[]),!(a instanceof k||a instanceof i))throw new Error("Must give Parsley instance");if("string"!=typeof b||"function"!=typeof c)throw new Error("Wrong parameters");n[b].push({instance:a,fn:c})},a.unsubscribe=function(a,b){if("undefined"!=typeof n[a]){if("string"!=typeof a||"function"!=typeof b)throw new Error("Wrong arguments");for(var c=0;c<n[a].length;c++)if(n[a][c].fn===b)return n[a].splice(c,1)}},a.unsubscribeTo=function(a,b){if("undefined"!=typeof n[b]){if(!(a instanceof k||a instanceof i))throw new Error("Must give Parsley instance");for(var c=0;c<n[b].length;c++)if("undefined"!=typeof n[b][c].instance&&n[b][c].instance.__id__===a.__id__)return n[b].splice(c,1)}},a.unsubscribeAll=function(a){"undefined"!=typeof n[a]&&delete n[a]},a.emit=function(a,b){if("undefined"!=typeof n[a])for(var c=0;c<n[a].length;c++)if("undefined"!=typeof n[a][c].instance){if(b instanceof k||b instanceof i)if(n[a][c].instance.__id__!==b.__id__){if(n[a][c].instance instanceof i&&b instanceof k)for(var d=0;d<n[a][c].instance.fields.length;d++)if(n[a][c].instance.fields[d].__id__===b.__id__){n[a][c].fn.apply(m,Array.prototype.slice.call(arguments,1));continue}}else n[a][c].fn.apply(m,Array.prototype.slice.call(arguments,1))}else n[a][c].fn.apply("undefined"!=typeof n[a][c].ctxt?n[a][c].ctxt:m,Array.prototype.slice.call(arguments,1))},a.subscribed=function(){return n},window.ParsleyConfig=window.ParsleyConfig||{},window.ParsleyConfig.i18n=window.ParsleyConfig.i18n||{},window.ParsleyConfig.i18n.en=a.extend(window.ParsleyConfig.i18n.en||{},{defaultMessage:"This value seems to be invalid.",type:{email:"This value should be a valid email.",url:"This value should be a valid url.",number:"This value should be a valid number.",integer:"This value should be a valid integer.",digits:"This value should be digits.",alphanum:"This value should be alphanumeric."},notblank:"This value should not be blank.",required:"This value is required.",pattern:"This value seems to be invalid.",min:"This value should be greater than or equal to %s.",max:"This value should be lower than or equal to %s.",range:"This value should be between %s and %s.",minlength:"This value is too short. It should have %s characters or more.",maxlength:"This value is too long. It should have %s characters or fewer.",length:"This value length is invalid. It should be between %s and %s characters long.",mincheck:"You must select at least %s choices.",maxcheck:"You must select %s choices or fewer.",check:"You must select between %s and %s choices.",equalto:"This value should be the same."}),"undefined"!=typeof window.ParsleyValidator&&window.ParsleyValidator.addCatalog("en",window.ParsleyConfig.i18n.en,!0);var o=function(c,d,e){if(this.__class__="Parsley",this.__version__="2.0.6",this.__id__=b.hash(4),"undefined"==typeof c)throw new Error("You must give an element");if("undefined"!=typeof e&&"ParsleyForm"!==e.__class__)throw new Error("Parent instance must be a ParsleyForm instance");return this.init(a(c),d,e)};o.prototype={init:function(a,d,e){if(!a.length)throw new Error("You must bind Parsley on an existing element.");if(this.$element=a,this.$element.data("Parsley")){var f=this.$element.data("Parsley");return"undefined"!=typeof e&&(f.parent=e),f}return this.OptionsFactory=new h(c,b.get(window,"ParsleyConfig")||{},d,this.getNamespace(d)),this.options=this.OptionsFactory.get(this),this.$element.is("form")||b.attr(this.$element,this.options.namespace,"validate")&&!this.$element.is(this.options.inputs)?this.bind("parsleyForm"):this.$element.is(this.options.inputs)&&!this.$element.is(this.options.excluded)?this.isMultiple()?this.handleMultiple(e):this.bind("parsleyField",e):this},isMultiple:function(){return this.$element.is("input[type=radio], input[type=checkbox]")&&"undefined"==typeof this.options.multiple||this.$element.is("select")&&"undefined"!=typeof this.$element.attr("multiple")},handleMultiple:function(c){var d,e,f,g=this;if(this.options=a.extend(this.options,c?c.OptionsFactory.get(c):{},b.attr(this.$element,this.options.namespace)),this.options.multiple?e=this.options.multiple:"undefined"!=typeof this.$element.attr("name")&&this.$element.attr("name").length?e=d=this.$element.attr("name"):"undefined"!=typeof this.$element.attr("id")&&this.$element.attr("id").length&&(e=this.$element.attr("id")),this.$element.is("select")&&"undefined"!=typeof this.$element.attr("multiple"))return this.bind("parsleyFieldMultiple",c,e||this.__id__);if("undefined"==typeof e)return window.console&&window.console.warn&&window.console.warn("To be binded by Parsley, a radio, a checkbox and a multiple select input must have either a name or a multiple option.",this.$element),this;if(e=e.replace(/(:|\.|\[|\]|\{|\}|\$)/g,""),"undefined"!=typeof d&&a('input[name="'+d+'"]').each(function(){a(this).is("input[type=radio], input[type=checkbox]")&&a(this).attr(g.options.namespace+"multiple",e)}),a("["+this.options.namespace+"multiple="+e+"]").length)for(var h=0;h<a("["+this.options.namespace+"multiple="+e+"]").length;h++)if("undefined"!=typeof a(a("["+this.options.namespace+"multiple="+e+"]").get(h)).data("Parsley")){f=a(a("["+this.options.namespace+"multiple="+e+"]").get(h)).data("Parsley"),this.$element.data("ParsleyFieldMultiple")||(f.addElement(this.$element),this.$element.attr(this.options.namespace+"id",f.__id__));break}return this.bind("parsleyField",c,e,!0),f||this.bind("parsleyFieldMultiple",c,e)},getNamespace:function(a){return"undefined"!=typeof this.$element.data("parsleyNamespace")?this.$element.data("parsleyNamespace"):"undefined"!=typeof b.get(a,"namespace")?a.namespace:"undefined"!=typeof b.get(window,"ParsleyConfig.namespace")?window.ParsleyConfig.namespace:c.namespace},bind:function(c,e,f,g){var h;switch(c){case"parsleyForm":h=a.extend(new i(this.$element,this.OptionsFactory),new d,window.ParsleyExtend)._bindFields();break;case"parsleyField":h=a.extend(new k(this.$element,this.OptionsFactory,e),new d,window.ParsleyExtend);break;case"parsleyFieldMultiple":h=a.extend(new k(this.$element,this.OptionsFactory,e),new d,new l,window.ParsleyExtend)._init(f);break;default:throw new Error(c+"is not a supported Parsley type")}return"undefined"!=typeof f&&b.setAttr(this.$element,this.options.namespace,"multiple",f),"undefined"!=typeof g?(this.$element.data("ParsleyFieldMultiple",h),h):(new RegExp("ParsleyF","i").test(h.__class__)&&(this.$element.data("Parsley",h),a.emit("parsley:"+("parsleyForm"===c?"form":"field")+":init",h)),h)}},a.fn.parsley=a.fn.psly=function(b){if(this.length>1){var c=[];return this.each(function(){c.push(a(this).parsley(b))}),c}return a(this).length?new o(this,b):void(window.console&&window.console.warn&&window.console.warn("You must bind Parsley on an existing element."))},window.ParsleyUI="function"==typeof b.get(window,"ParsleyConfig.ParsleyUI")?(new window.ParsleyConfig.ParsleyUI).listen():(new g).listen(),"undefined"==typeof window.ParsleyExtend&&(window.ParsleyExtend={}),"undefined"==typeof window.ParsleyConfig&&(window.ParsleyConfig={}),window.Parsley=window.psly=o,window.ParsleyUtils=b,window.ParsleyValidator=new f(window.ParsleyConfig.validators,window.ParsleyConfig.i18n),!1!==b.get(window,"ParsleyConfig.autoBind")&&a(function(){a("[data-parsley-validate]").length&&a("[data-parsley-validate]").parsley()})}); | ||
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){function b(a,b){return a.parsleyAdaptedCallback||(a.parsleyAdaptedCallback=function(){var c=Array.prototype.slice.call(arguments,0);c.unshift(this),a.apply(b||q,c)}),a.parsleyAdaptedCallback}function c(a){return 0===a.lastIndexOf(s,0)?a.substr(s.length):a}"undefined"==typeof a&&"undefined"!=typeof window.jQuery&&(a=window.jQuery);var d=1,e={},f={attr:function(a,b,c){var d,e,f=new RegExp("^"+b,"i");if("undefined"==typeof c)c={};else for(var g in c)c.hasOwnProperty(g)&&delete c[g];if("undefined"==typeof a||"undefined"==typeof a[0])return c;e=a[0].attributes;for(var g=e.length;g--;)d=e[g],d&&d.specified&&f.test(d.name)&&(c[this.camelize(d.name.slice(b.length))]=this.deserializeValue(d.value));return c},checkAttr:function(a,b,c){return a.is("["+b+c+"]")},setAttr:function(a,b,c,d){a[0].setAttribute(this.dasherize(b+c),String(d))},generateID:function(){return""+d++},deserializeValue:function(b){var c;try{return b?"true"==b||("false"==b?!1:"null"==b?null:isNaN(c=Number(b))?/^[\[\{]/.test(b)?a.parseJSON(b):b:c):b}catch(d){return b}},camelize:function(a){return a.replace(/-+(.)?/g,function(a,b){return b?b.toUpperCase():""})},dasherize:function(a){return a.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()},warn:function(){window.console&&window.console.warn&&window.console.warn.apply(window.console,arguments)},warnOnce:function(a){e[a]||(e[a]=!0,this.warn.apply(this,arguments))},_resetWarnings:function(){e={}},objectCreate:Object.create||function(){var a=function(){};return function(b){if(arguments.length>1)throw Error("Second argument not supported");if("object"!=typeof b)throw TypeError("Argument must be an object");a.prototype=b;var c=new a;return a.prototype=null,c}}()},g={namespace:"data-parsley-",inputs:"input, textarea, select",excluded:"input[type=button], input[type=submit], input[type=reset], input[type=hidden]",priorityEnabled:!0,multiple:null,group:null,uiEnabled:!0,validationThreshold:3,focus:"first",trigger:!1,errorClass:"parsley-error",successClass:"parsley-success",classHandler:function(){},errorsContainer:function(){},errorsWrapper:'<ul class="parsley-errors-list"></ul>',errorTemplate:"<li></li>"},h=function(){};h.prototype={asyncSupport:!1,actualizeOptions:function(){return f.attr(this.$element,this.options.namespace,this.domOptions),this.parent&&this.parent.actualizeOptions&&this.parent.actualizeOptions(),this},_resetOptions:function(a){this.domOptions=f.objectCreate(this.parent.options),this.options=f.objectCreate(this.domOptions);for(var b in a)a.hasOwnProperty(b)&&(this.options[b]=a[b]);this.actualizeOptions()},validateThroughValidator:function(a,b,c){return window.ParsleyValidator.validate(a,b,c)},_listeners:null,on:function(a,b){this._listeners=this._listeners||{};var c=this._listeners[a]=this._listeners[a]||[];return c.push(b),this},subscribe:function(b,c){a.listenTo(this,b.toLowerCase(),c)},off:function(a,b){var c=this._listeners&&this._listeners[a];if(c)if(b)for(var d=c.length;d--;)c[d]===b&&c.splice(d,1);else delete this._listeners[a];return this},unsubscribe:function(b){a.unsubscribeTo(this,b.toLowerCase())},trigger:function(a,b){b=b||this;var c,d=this._listeners&&this._listeners[a];if(d)for(var e=d.length;e--;)if(c=d[e].call(b,b),c===!1)return c;return this.parent?this.parent.trigger(a,b):!0},reset:function(){if("ParsleyForm"!==this.__class__)return this._trigger("reset");for(var a=0;a<this.fields.length;a++)this.fields[a]._trigger("reset");this._trigger("reset")},destroy:function(){if("ParsleyForm"!==this.__class__)return this.$element.removeData("Parsley"),this.$element.removeData("ParsleyFieldMultiple"),void this._trigger("destroy");for(var a=0;a<this.fields.length;a++)this.fields[a].destroy();this.$element.removeData("Parsley"),this._trigger("destroy")},_findRelatedMultiple:function(){return this.parent.$element.find("["+this.options.namespace+'multiple="'+this.options.multiple+'"]')}};var i=function(){var a={},b=function(a){this.__class__="Validator",this.__version__="1.0.1",this.options=a||{},this.bindingKey=this.options.bindingKey||"_validatorjsConstraint"};b.prototype={constructor:b,validate:function(a,b,c){if("string"!=typeof a&&"object"!=typeof a)throw new Error("You must validate an object or a string");return"string"==typeof a||g(a)?this._validateString(a,b,c):this.isBinded(a)?this._validateBindedObject(a,b):this._validateObject(a,b,c)},bind:function(a,b){if("object"!=typeof a)throw new Error("Must bind a Constraint to an object");return a[this.bindingKey]=new c(b),this},unbind:function(a){return"undefined"==typeof a._validatorjsConstraint?this:(delete a[this.bindingKey],this)},isBinded:function(a){return"undefined"!=typeof a[this.bindingKey]},getBinded:function(a){return this.isBinded(a)?a[this.bindingKey]:null},_validateString:function(a,b,c){var f,h=[];g(b)||(b=[b]);for(var i=0;i<b.length;i++){if(!(b[i]instanceof e))throw new Error("You must give an Assert or an Asserts array to validate a string");f=b[i].check(a,c),f instanceof d&&h.push(f)}return h.length?h:!0},_validateObject:function(a,b,d){if("object"!=typeof b)throw new Error("You must give a constraint to validate an object");return b instanceof c?b.check(a,d):new c(b).check(a,d)},_validateBindedObject:function(a,b){return a[this.bindingKey].check(a,b)}},b.errorCode={must_be_a_string:"must_be_a_string",must_be_an_array:"must_be_an_array",must_be_a_number:"must_be_a_number",must_be_a_string_or_array:"must_be_a_string_or_array"};var c=function(a,b){if(this.__class__="Constraint",this.options=b||{},this.nodes={},a)try{this._bootstrap(a)}catch(c){throw new Error("Should give a valid mapping object to Constraint",c,a)}};c.prototype={constructor:c,check:function(a,b){var c,d={};for(var h in this.nodes){for(var i=!1,j=this.get(h),k=g(j)?j:[j],l=k.length-1;l>=0;l--)"Required"!==k[l].__class__||(i=k[l].requiresValidation(b));if(this.has(h,a)||this.options.strict||i)try{this.has(h,this.options.strict||i?a:void 0)||(new e).HaveProperty(h).validate(a),c=this._check(h,a[h],b),(g(c)&&c.length>0||!g(c)&&!f(c))&&(d[h]=c)}catch(m){d[h]=m}}return f(d)?!0:d},add:function(a,b){if(b instanceof e||g(b)&&b[0]instanceof e)return this.nodes[a]=b,this;if("object"==typeof b&&!g(b))return this.nodes[a]=b instanceof c?b:new c(b),this;throw new Error("Should give an Assert, an Asserts array, a Constraint",b)},has:function(a,b){return b="undefined"!=typeof b?b:this.nodes,"undefined"!=typeof b[a]},get:function(a,b){return this.has(a)?this.nodes[a]:b||null},remove:function(a){var b=[];for(var c in this.nodes)c!==a&&(b[c]=this.nodes[c]);return this.nodes=b,this},_bootstrap:function(a){if(a instanceof c)return this.nodes=a.nodes;for(var b in a)this.add(b,a[b])},_check:function(a,b,d){if(this.nodes[a]instanceof e)return this._checkAsserts(b,[this.nodes[a]],d);if(g(this.nodes[a]))return this._checkAsserts(b,this.nodes[a],d);if(this.nodes[a]instanceof c)return this.nodes[a].check(b,d);throw new Error("Invalid node",this.nodes[a])},_checkAsserts:function(a,b,c){for(var d,e=[],f=0;f<b.length;f++)d=b[f].check(a,c),"undefined"!=typeof d&&!0!==d&&e.push(d);return e}};var d=function(a,b,c){if(this.__class__="Violation",!(a instanceof e))throw new Error("Should give an assertion implementing the Assert interface");this.assert=a,this.value=b,"undefined"!=typeof c&&(this.violation=c)};d.prototype={show:function(){var a={assert:this.assert.__class__,value:this.value};return this.violation&&(a.violation=this.violation),a},__toString:function(){return"undefined"!=typeof this.violation&&(this.violation='", '+this.getViolation().constraint+" expected was "+this.getViolation().expected),this.assert.__class__+' assert failed for "'+this.value+this.violation||""},getViolation:function(){var a,b;for(a in this.violation)b=this.violation[a];return{constraint:a,expected:b}}};var e=function(a){this.__class__="Assert",this.__parentClass__=this.__class__,this.groups=[],"undefined"!=typeof a&&this.addGroup(a)};e.prototype={construct:e,requiresValidation:function(a){return a&&!this.hasGroup(a)?!1:!a&&this.hasGroups()?!1:!0},check:function(a,b){if(this.requiresValidation(b))try{return this.validate(a,b)}catch(c){return c}},hasGroup:function(a){return g(a)?this.hasOneOf(a):"Any"===a?!0:this.hasGroups()?-1!==this.groups.indexOf(a):"Default"===a},hasOneOf:function(a){for(var b=0;b<a.length;b++)if(this.hasGroup(a[b]))return!0;return!1},hasGroups:function(){return this.groups.length>0},addGroup:function(a){return g(a)?this.addGroups(a):(this.hasGroup(a)||this.groups.push(a),this)},removeGroup:function(a){for(var b=[],c=0;c<this.groups.length;c++)a!==this.groups[c]&&b.push(this.groups[c]);return this.groups=b,this},addGroups:function(a){for(var b=0;b<a.length;b++)this.addGroup(a[b]);return this},HaveProperty:function(a){return this.__class__="HaveProperty",this.node=a,this.validate=function(a){if("undefined"==typeof a[this.node])throw new d(this,a,{value:this.node});return!0},this},Blank:function(){return this.__class__="Blank",this.validate=function(a){if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(""!==a.replace(/^\s+/g,"").replace(/\s+$/g,""))throw new d(this,a);return!0},this},Callback:function(a){if(this.__class__="Callback",this.arguments=Array.prototype.slice.call(arguments),1===this.arguments.length?this.arguments=[]:this.arguments.splice(0,1),"function"!=typeof a)throw new Error("Callback must be instanciated with a function");return this.fn=a,this.validate=function(a){var b=this.fn.apply(this,[a].concat(this.arguments));if(!0!==b)throw new d(this,a,{result:b});return!0},this},Choice:function(a){if(this.__class__="Choice",!g(a)&&"function"!=typeof a)throw new Error("Choice must be instanciated with an array or a function");return this.list=a,this.validate=function(a){for(var b="function"==typeof this.list?this.list():this.list,c=0;c<b.length;c++)if(a===b[c])return!0;throw new d(this,a,{choices:b})},this},Collection:function(a){return this.__class__="Collection",this.constraint="undefined"!=typeof a?a instanceof e?a:new c(a):!1,this.validate=function(a,c){var e,h=new b,i=0,j={},k=this.groups.length?this.groups:c;if(!g(a))throw new d(this,a,{value:b.errorCode.must_be_an_array});for(var l=0;l<a.length;l++)e=this.constraint?h.validate(a[l],this.constraint,k):h.validate(a[l],k),f(e)||(j[i]=e),i++;return f(j)?!0:j},this},Count:function(a){return this.__class__="Count",this.count=a,this.validate=function(a){if(!g(a))throw new d(this,a,{value:b.errorCode.must_be_an_array});var c="function"==typeof this.count?this.count(a):this.count;if(isNaN(Number(c)))throw new Error("Count must be a valid interger",c);if(c!==a.length)throw new d(this,a,{count:c});return!0},this},Email:function(){return this.__class__="Email",this.validate=function(a){var c=/^((([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;if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(!c.test(a))throw new d(this,a);return!0},this},EqualTo:function(a){if(this.__class__="EqualTo","undefined"==typeof a)throw new Error("EqualTo must be instanciated with a value or a function");return this.reference=a,this.validate=function(a){var b="function"==typeof this.reference?this.reference(a):this.reference;if(b!==a)throw new d(this,a,{value:b});return!0},this},GreaterThan:function(a){if(this.__class__="GreaterThan","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold>=a)throw new d(this,a,{threshold:this.threshold});return!0},this},GreaterThanOrEqual:function(a){if(this.__class__="GreaterThanOrEqual","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold>a)throw new d(this,a,{threshold:this.threshold});return!0},this},InstanceOf:function(a){if(this.__class__="InstanceOf","undefined"==typeof a)throw new Error("InstanceOf must be instanciated with a value");return this.classRef=a,this.validate=function(a){if(!0!=a instanceof this.classRef)throw new d(this,a,{classRef:this.classRef});return!0},this},Length:function(a){if(this.__class__="Length",!a.min&&!a.max)throw new Error("Lenth assert must be instanciated with a { min: x, max: y } object");return this.min=a.min,this.max=a.max,this.validate=function(a){if("string"!=typeof a&&!g(a))throw new d(this,a,{value:b.errorCode.must_be_a_string_or_array});if("undefined"!=typeof this.min&&this.min===this.max&&a.length!==this.min)throw new d(this,a,{min:this.min,max:this.max});if("undefined"!=typeof this.max&&a.length>this.max)throw new d(this,a,{max:this.max});if("undefined"!=typeof this.min&&a.length<this.min)throw new d(this,a,{min:this.min});return!0},this},LessThan:function(a){if(this.__class__="LessThan","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold<=a)throw new d(this,a,{threshold:this.threshold});return!0},this},LessThanOrEqual:function(a){if(this.__class__="LessThanOrEqual","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold<a)throw new d(this,a,{threshold:this.threshold});return!0},this},NotNull:function(){return this.__class__="NotNull",this.validate=function(a){if(null===a||"undefined"==typeof a)throw new d(this,a);return!0},this},NotBlank:function(){return this.__class__="NotBlank",this.validate=function(a){if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(""===a.replace(/^\s+/g,"").replace(/\s+$/g,""))throw new d(this,a);return!0},this},Null:function(){return this.__class__="Null",this.validate=function(a){if(null!==a)throw new d(this,a);return!0},this},Range:function(a,b){if(this.__class__="Range","undefined"==typeof a||"undefined"==typeof b)throw new Error("Range assert expects min and max values");return this.min=a,this.max=b,this.validate=function(a){try{return"string"==typeof a&&isNaN(Number(a))||g(a)?(new e).Length({min:this.min,max:this.max}).validate(a):(new e).GreaterThanOrEqual(this.min).validate(a)&&(new e).LessThanOrEqual(this.max).validate(a),!0}catch(b){throw new d(this,a,b.violation)}return!0},this},Regexp:function(a,c){if(this.__class__="Regexp","undefined"==typeof a)throw new Error("You must give a regexp");return this.regexp=a,this.flag=c||"",this.validate=function(a){if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(!new RegExp(this.regexp,this.flag).test(a))throw new d(this,a,{regexp:this.regexp,flag:this.flag});return!0},this},Required:function(){return this.__class__="Required",this.validate=function(a){if("undefined"==typeof a)throw new d(this,a);try{"string"==typeof a?(new e).NotNull().validate(a)&&(new e).NotBlank().validate(a):!0===g(a)&&(new e).Length({min:1}).validate(a)}catch(b){throw new d(this,a)}return!0},this},Unique:function(a){return this.__class__="Unique","object"==typeof a&&(this.key=a.key),this.validate=function(a){var c,e=[];if(!g(a))throw new d(this,a,{value:b.errorCode.must_be_an_array});for(var f=0;f<a.length;f++)if(c="object"==typeof a[f]?a[f][this.key]:a[f],"undefined"!=typeof c){if(-1!==e.indexOf(c))throw new d(this,a,{value:c});e.push(c)}return!0},this}},a.Assert=e,a.Validator=b,a.Violation=d,a.Constraint=c,Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null===this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!==d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1});var f=function(a){for(var b in a)return!1;return!0},g=function(a){return"[object Array]"===Object.prototype.toString.call(a)};return"function"==typeof define&&define.amd?define("vendors/validator.js/dist/validator",[],function(){return a}):"undefined"!=typeof module&&module.exports?module.exports=a:window["undefined"!=typeof validatorjs_ns?validatorjs_ns:"Validator"]=a,a}();i="undefined"!=typeof i?i:"undefined"!=typeof module?module.exports:null;var j=function(a,b){this.__class__="ParsleyValidator",this.Validator=i,this.locale="en",this.init(a||{},b||{})};j.prototype={init:function(b,c){this.catalog=c,this.validators=a.extend({},this.validators);for(var d in b)this.addValidator(d,b[d].fn,b[d].priority,b[d].requirementsTransformer);window.Parsley.trigger("parsley:validator:init")},setLocale:function(a){if("undefined"==typeof this.catalog[a])throw new Error(a+" is not available in the catalog");return this.locale=a,this},addCatalog:function(a,b,c){return"object"==typeof b&&(this.catalog[a]=b),!0===c?this.setLocale(a):this},addMessage:function(a,b,c){return"undefined"==typeof this.catalog[a]&&(this.catalog[a]={}),this.catalog[a][b.toLowerCase()]=c,this},validate:function(){return(new this.Validator.Validator).validate.apply(new i.Validator,arguments)},addValidator:function(a,b,c,d){if(this.validators[a])f.warn('Validator "'+a+'" is already defined.');else if(g.hasOwnProperty(a))return void f.warn('"'+a+'" is a restricted keyword and is not a valid validator name.');return this._setValidator(a,b,c,d)},updateValidator:function(a,b,c,d){return this.validators[a]?this._setValidator(a,b,c,d):(f.warn('Validator "'+a+'" is not already defined.'),this.addValidator(a,b,c,d))},removeValidator:function(a){return this.validators[a]||f.warn('Validator "'+a+'" is not defined.'),delete this.validators[a],this},_setValidator:function(b,c,d,e){return this.validators[b]=function(b){return a.extend((new i.Assert).Callback(c,b),{priority:d,requirementsTransformer:e})},this},getErrorMessage:function(a){var b;if("type"===a.name){var c=this.catalog[this.locale][a.name]||{};b=c[a.requirements]}else b=this.formatMessage(this.catalog[this.locale][a.name],a.requirements);return b||this.catalog[this.locale].defaultMessage||this.catalog.en.defaultMessage},formatMessage:function(a,b){if("object"==typeof b){for(var c in b)a=this.formatMessage(a,b[c]);return a}return"string"==typeof a?a.replace(new RegExp("%s","i"),b):""},validators:{notblank:function(){return a.extend((new i.Assert).NotBlank(),{priority:2})},required:function(){return a.extend((new i.Assert).Required(),{priority:512})},type:function(b){var c;switch(b){case"email":c=(new i.Assert).Email();break;case"range":case"number":c=(new i.Assert).Regexp("^-?(?:\\d+|\\d{1,3}(?:,\\d{3})+)?(?:\\.\\d+)?$");break;case"integer":c=(new i.Assert).Regexp("^-?\\d+$");break;case"digits":c=(new i.Assert).Regexp("^\\d+$");break;case"alphanum":c=(new i.Assert).Regexp("^\\w+$","i");break;case"url":c=(new i.Assert).Regexp("^(?:(?:https?|ftp)://)?(?:\\S+(?::\\S*)?@)?(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:/\\S*)?$","i");break;default:throw new Error("validator type `"+b+"` is not supported")}return a.extend(c,{priority:256})},pattern:function(b){var c="";return/^\/.*\/(?:[gimy]*)$/.test(b)&&(c=b.replace(/.*\/([gimy]*)$/,"$1"),b=b.replace(new RegExp("^/(.*?)/"+c+"$"),"$1")),a.extend((new i.Assert).Regexp(b,c),{priority:64})},minlength:function(b){return a.extend((new i.Assert).Length({min:b}),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},maxlength:function(b){return a.extend((new i.Assert).Length({max:b}),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},length:function(b){return a.extend((new i.Assert).Length({min:b[0],max:b[1]}),{priority:32})},mincheck:function(a){return this.minlength(a)},maxcheck:function(a){return this.maxlength(a)},check:function(a){return this.length(a)},min:function(b){return a.extend((new i.Assert).GreaterThanOrEqual(b),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},max:function(b){return a.extend((new i.Assert).LessThanOrEqual(b),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},range:function(b){return a.extend((new i.Assert).Range(b[0],b[1]),{priority:32,requirementsTransformer:function(){for(var a=0;a<b.length;a++)b[a]="string"!=typeof b[a]||isNaN(b[a])?b[a]:parseInt(b[a],10);return b}})},equalto:function(b){return a.extend((new i.Assert).EqualTo(b),{priority:256,requirementsTransformer:function(){return a(b).length?a(b).val():b}})}}};var k=function(){this.__class__="ParsleyUI"};k.prototype={listen:function(){var a=this;return window.Parsley.on("form:init",function(){a.setupForm(this)}).on("field:init",function(){a.setupField(this)}).on("field:validated",function(){a.reflow(this)}).on("form:validated",function(){a.focus(this)}).on("field:reset",function(){a.reset(this)}).on("form:destroy",function(){a.destroy(this)}).on("field:destroy",function(){a.destroy(this)}),this},reflow:function(a){if("undefined"!=typeof a._ui&&!1!==a._ui.active){var b=this._diff(a.validationResult,a._ui.lastValidationResult);a._ui.lastValidationResult=a.validationResult,a._ui.validatedOnce=!0,this.manageStatusClass(a),this.manageErrorsMessages(a,b),this.actualizeTriggers(a),(b.kept.length||b.added.length)&&!0!==a._ui.failedOnce&&this.manageFailingFieldTrigger(a)}},getErrorsMessages:function(a){if(!0===a.validationResult)return[];for(var b=[],c=0;c<a.validationResult.length;c++)b.push(this._getErrorMessage(a,a.validationResult[c].assert));return b},manageStatusClass:function(a){a.hasConstraints()&&a.needsValidation()&&!0===a.validationResult?this._successClass(a):a.validationResult.length>0?this._errorClass(a):this._resetClass(a)},manageErrorsMessages:function(b,c){if("undefined"==typeof b.options.errorsMessagesDisabled){if("undefined"!=typeof b.options.errorMessage)return c.added.length||c.kept.length?(this._insertErrorWrapper(b),0===b._ui.$errorsWrapper.find(".parsley-custom-error-message").length&&b._ui.$errorsWrapper.append(a(b.options.errorTemplate).addClass("parsley-custom-error-message")),b._ui.$errorsWrapper.addClass("filled").find(".parsley-custom-error-message").html(b.options.errorMessage)):b._ui.$errorsWrapper.removeClass("filled").find(".parsley-custom-error-message").remove();for(var d=0;d<c.removed.length;d++)this.removeError(b,c.removed[d].assert.name,!0);for(d=0;d<c.added.length;d++)this.addError(b,c.added[d].assert.name,void 0,c.added[d].assert,!0);for(d=0;d<c.kept.length;d++)this.updateError(b,c.kept[d].assert.name,void 0,c.kept[d].assert,!0)}},addError:function(b,c,d,e,f){this._insertErrorWrapper(b),b._ui.$errorsWrapper.addClass("filled").append(a(b.options.errorTemplate).addClass("parsley-"+c).html(d||this._getErrorMessage(b,e))),!0!==f&&this._errorClass(b)},updateError:function(a,b,c,d,e){a._ui.$errorsWrapper.addClass("filled").find(".parsley-"+b).html(c||this._getErrorMessage(a,d)),!0!==e&&this._errorClass(a)},removeError:function(a,b,c){a._ui.$errorsWrapper.removeClass("filled").find(".parsley-"+b).remove(),!0!==c&&this.manageStatusClass(a)},focus:function(a){if(a._focusedField=null,!0===a.validationResult||"none"===a.options.focus)return null;for(var b=0;b<a.fields.length;b++){var c=a.fields[b];if(!0!==c.validationResult&&c.validationResult.length>0&&"undefined"==typeof c.options.noFocus&&(a._focusedField=c.$element,"first"===a.options.focus))break}return null===a._focusedField?null:a._focusedField.focus()},_getErrorMessage:function(a,b){var c=b.name+"Message";return"undefined"!=typeof a.options[c]?window.ParsleyValidator.formatMessage(a.options[c],b.requirements):window.ParsleyValidator.getErrorMessage(b)},_diff:function(a,b,c){for(var d=[],e=[],f=0;f<a.length;f++){for(var g=!1,h=0;h<b.length;h++)if(a[f].assert.name===b[h].assert.name){g=!0;break}g?e.push(a[f]):d.push(a[f])}return{kept:e,added:d,removed:c?[]:this._diff(b,a,!0).added}},setupForm:function(b){b.$element.on("submit.Parsley",!1,a.proxy(b.onSubmitValidate,b)),!1!==b.options.uiEnabled&&b.$element.attr("novalidate","")},setupField:function(b){var c={active:!1};!1!==b.options.uiEnabled&&(c.active=!0,b.$element.attr(b.options.namespace+"id",b.__id__),c.$errorClassHandler=this._manageClassHandler(b),c.errorsWrapperId="parsley-id-"+(b.options.multiple?"multiple-"+b.options.multiple:b.__id__),c.$errorsWrapper=a(b.options.errorsWrapper).attr("id",c.errorsWrapperId),c.lastValidationResult=[],c.validatedOnce=!1,c.validationInformationVisible=!1,b._ui=c,this.actualizeTriggers(b))},_manageClassHandler:function(b){if("string"==typeof b.options.classHandler&&a(b.options.classHandler).length)return a(b.options.classHandler);var c=b.options.classHandler(b);return"undefined"!=typeof c&&c.length?c:!b.options.multiple||b.$element.is("select")?b.$element:b.$element.parent()},_insertErrorWrapper:function(b){var c;if(0!==b._ui.$errorsWrapper.parent().length)return b._ui.$errorsWrapper.parent();if("string"==typeof b.options.errorsContainer){if(a(b.options.errorsContainer).length)return a(b.options.errorsContainer).append(b._ui.$errorsWrapper);f.warn("The errors container `"+b.options.errorsContainer+"` does not exist in DOM")}else"function"==typeof b.options.errorsContainer&&(c=b.options.errorsContainer(b));if("undefined"!=typeof c&&c.length)return c.append(b._ui.$errorsWrapper);var d=b.$element;return b.options.multiple&&(d=d.parent()),d.after(b._ui.$errorsWrapper)},actualizeTriggers:function(b){var c=b.$element;if(b.options.multiple&&(c=a("["+b.options.namespace+'multiple="'+b.options.multiple+'"]')),c.off(".Parsley"),!1!==b.options.trigger){var d=b.options.trigger.replace(/^\s+/g,"").replace(/\s+$/g,"");""!==d&&c.on(d.split(" ").join(".Parsley ")+".Parsley",a.proxy("function"==typeof b.eventValidate?b.eventValidate:this.eventValidate,b))}},eventValidate:function(a){new RegExp("key").test(a.type)&&!this._ui.validationInformationVisible&&this.getValue().length<=this.options.validationThreshold||(this._ui.validatedOnce=!0,this.validate())},manageFailingFieldTrigger:function(b){return b._ui.failedOnce=!0,b.options.multiple&&a("["+b.options.namespace+'multiple="'+b.options.multiple+'"]').each(function(){return new RegExp("change","i").test(a(this).parsley().options.trigger||"")?void 0:a(this).on("change.ParsleyFailedOnce",!1,a.proxy(b.validate,b))}),b.$element.is("select")&&!new RegExp("change","i").test(b.options.trigger||"")?b.$element.on("change.ParsleyFailedOnce",!1,a.proxy(b.validate,b)):new RegExp("keyup","i").test(b.options.trigger||"")?void 0:b.$element.on("keyup.ParsleyFailedOnce",!1,a.proxy(b.validate,b))},reset:function(a){this.actualizeTriggers(a),a.$element.off(".ParsleyFailedOnce"),"undefined"!=typeof a._ui&&"ParsleyForm"!==a.__class__&&(a._ui.$errorsWrapper.removeClass("filled").children().remove(),this._resetClass(a),a._ui.validatedOnce=!1,a._ui.lastValidationResult=[],a._ui.validationInformationVisible=!1,a._ui.failedOnce=!1)},destroy:function(a){this.reset(a),"ParsleyForm"!==a.__class__&&("undefined"!=typeof a._ui&&a._ui.$errorsWrapper.remove(),delete a._ui)},_successClass:function(a){a._ui.validationInformationVisible=!0,a._ui.$errorClassHandler.removeClass(a.options.errorClass).addClass(a.options.successClass)},_errorClass:function(a){a._ui.validationInformationVisible=!0,a._ui.$errorClassHandler.removeClass(a.options.successClass).addClass(a.options.errorClass)},_resetClass:function(a){a._ui.$errorClassHandler.removeClass(a.options.successClass).removeClass(a.options.errorClass)}};var l=function(b,c,d){this.__class__="ParsleyForm",this.__id__=f.generateID(),this.$element=a(b),this.domOptions=c,this.options=d,this.parent=window.Parsley,this.fields=[],this.validationResult=null};l.prototype={onSubmitValidate:function(b){return this.validate(void 0,void 0,b),(!1===this.validationResult||!this._trigger("submit"))&&b instanceof a.Event&&(b.stopImmediatePropagation(),b.preventDefault()),this},validate:function(a,b,c){this.submitEvent=c,this.validationResult=!0;var d=[];return this._trigger("validate"),this._refreshFields(),this._withoutReactualizingFormOptions(function(){for(var c=0;c<this.fields.length;c++)(!a||this._isFieldInGroup(this.fields[c],a))&&(d=this.fields[c].validate(b),!0!==d&&d.length>0&&this.validationResult&&(this.validationResult=!1))}),this._trigger(this.validationResult?"success":"error"),this._trigger("validated"),this.validationResult},isValid:function(a,b){return this._refreshFields(),this._withoutReactualizingFormOptions(function(){for(var c=0;c<this.fields.length;c++)if((!a||this._isFieldInGroup(this.fields[c],a))&&!1===this.fields[c].isValid(b))return!1;return!0})},_isFieldInGroup:function(b,c){return a.isArray(b.options.group)?-1!==a.inArray(c,b.options.group):b.options.group===c},_refreshFields:function(){return this.actualizeOptions()._bindFields()},_bindFields:function(){var b=this,c=this.fields;return this.fields=[],this.fieldsMappedById={},this._withoutReactualizingFormOptions(function(){this.$element.find(this.options.inputs).not(this.options.excluded).each(function(){var a=new t.Factory(this,{},b);"ParsleyField"!==a.__class__&&"ParsleyFieldMultiple"!==a.__class__||!0===a.options.excluded||"undefined"==typeof b.fieldsMappedById[a.__class__+"-"+a.__id__]&&(b.fieldsMappedById[a.__class__+"-"+a.__id__]=a,b.fields.push(a))}),a(c).not(b.fields).each(function(){this._trigger("reset")})}),this},_withoutReactualizingFormOptions:function(a){var b=this.actualizeOptions;this.actualizeOptions=function(){return this};var c=a.call(this);return this.actualizeOptions=b,c},_trigger:function(a){return a="form:"+a,this.trigger.apply(this,arguments)}};var m=function(b,c,d,e,g){var h={};if(!new RegExp("ParsleyField").test(b.__class__))throw new Error("ParsleyField or ParsleyFieldMultiple instance expected");if("function"==typeof window.ParsleyValidator.validators[c]&&(h=window.ParsleyValidator.validators[c](d)),"Assert"!==h.__parentClass__)throw new Error("Valid validator expected");var i=function(){return"undefined"!=typeof b.options[c+"Priority"]?b.options[c+"Priority"]:h.priority||2};return e=e||i(),"function"==typeof h.requirementsTransformer&&(d=h.requirementsTransformer(),h=window.ParsleyValidator.validators[c](d)),a.extend(h,{name:c,requirements:d,priority:e,groups:[e],isDomConstraint:g||f.checkAttr(b.$element,b.options.namespace,c)})},n=function(b,c,d,e){this.__class__="ParsleyField",this.__id__=f.generateID(),this.$element=a(b),"undefined"!=typeof e&&(this.parent=e),this.options=d,this.domOptions=c,this.constraints=[],this.constraintsByName={},this.validationResult=[],this._bindConstraints(); | ||
};n.prototype={validate:function(a){return this.value=this.getValue(),this._trigger("validate"),this._trigger(this.isValid(a,this.value)?"success":"error"),this._trigger("validated"),this.validationResult},hasConstraints:function(){return 0!==this.constraints.length},needsValidation:function(a){return"undefined"==typeof a&&(a=this.getValue()),a.length||this._isRequired()||"undefined"!=typeof this.options.validateIfEmpty?!0:!1},isValid:function(a,b){if(this.refreshConstraints(),this.validationResult=!0,!this.hasConstraints())return!0;if(("undefined"==typeof b||null===b)&&(b=this.getValue()),!this.needsValidation(b)&&!0!==a)return!0;var c=["Any"];!1!==this.options.priorityEnabled&&(c=this._getConstraintsSortedPriorities());for(var d=0;d<c.length;d++)if(!0!==(this.validationResult=this.validateThroughValidator(b,this.constraints,c[d])))return!1;return!0},getValue:function(){var a;return a="function"==typeof this.options.value?this.options.value(this):"undefined"!=typeof this.options.value?this.options.value:this.$element.val(),"undefined"==typeof a||null===a?"":!0===this.options.trimValue?a.replace(/^\s+|\s+$/g,""):a},refreshConstraints:function(){return this.actualizeOptions()._bindConstraints()},addConstraint:function(a,b,c,d){if("function"==typeof window.ParsleyValidator.validators[a]){var e=new m(this,a,b,c,d);"undefined"!==this.constraintsByName[e.name]&&this.removeConstraint(e.name),this.constraints.push(e),this.constraintsByName[e.name]=e}return this},removeConstraint:function(a){for(var b=0;b<this.constraints.length;b++)if(a===this.constraints[b].name){this.constraints.splice(b,1);break}return delete this.constraintsByName[a],this},updateConstraint:function(a,b,c){return this.removeConstraint(a).addConstraint(a,b,c)},_bindConstraints:function(){for(var a=[],b={},c=0;c<this.constraints.length;c++)!1===this.constraints[c].isDomConstraint&&(a.push(this.constraints[c]),b[this.constraints[c].name]=this.constraints[c]);this.constraints=a,this.constraintsByName=b;for(var d in this.options)this.addConstraint(d,this.options[d]);return this._bindHtml5Constraints()},_bindHtml5Constraints:function(){(this.$element.hasClass("required")||this.$element.attr("required"))&&this.addConstraint("required",!0,void 0,!0),"string"==typeof this.$element.attr("pattern")&&this.addConstraint("pattern",this.$element.attr("pattern"),void 0,!0),"undefined"!=typeof this.$element.attr("min")&&"undefined"!=typeof this.$element.attr("max")?this.addConstraint("range",[this.$element.attr("min"),this.$element.attr("max")],void 0,!0):"undefined"!=typeof this.$element.attr("min")?this.addConstraint("min",this.$element.attr("min"),void 0,!0):"undefined"!=typeof this.$element.attr("max")&&this.addConstraint("max",this.$element.attr("max"),void 0,!0),"undefined"!=typeof this.$element.attr("minlength")&&"undefined"!=typeof this.$element.attr("maxlength")?this.addConstraint("length",[this.$element.attr("minlength"),this.$element.attr("maxlength")],void 0,!0):"undefined"!=typeof this.$element.attr("minlength")?this.addConstraint("minlength",this.$element.attr("minlength"),void 0,!0):"undefined"!=typeof this.$element.attr("maxlength")&&this.addConstraint("maxlength",this.$element.attr("maxlength"),void 0,!0);var a=this.$element.attr("type");return"undefined"==typeof a?this:"number"===a?"undefined"==typeof this.$element.attr("step")||0===parseFloat(this.$element.attr("step"))%1?this.addConstraint("type","integer",void 0,!0):this.addConstraint("type","number",void 0,!0):/^(email|url|range)$/i.test(a)?this.addConstraint("type",a,void 0,!0):this},_isRequired:function(){return"undefined"==typeof this.constraintsByName.required?!1:!1!==this.constraintsByName.required.requirements},_trigger:function(a){return a="field:"+a,this.trigger.apply(this,arguments)},_getConstraintsSortedPriorities:function(){for(var a=[],b=0;b<this.constraints.length;b++)-1===a.indexOf(this.constraints[b].priority)&&a.push(this.constraints[b].priority);return a.sort(function(a,b){return b-a}),a}};var o=function(){this.__class__="ParsleyFieldMultiple"};o.prototype={addElement:function(a){return this.$elements.push(a),this},refreshConstraints:function(){var b;if(this.constraints=[],this.$element.is("select"))return this.actualizeOptions()._bindConstraints(),this;for(var c=0;c<this.$elements.length;c++)if(a("html").has(this.$elements[c]).length){b=this.$elements[c].data("ParsleyFieldMultiple").refreshConstraints().constraints;for(var d=0;d<b.length;d++)this.addConstraint(b[d].name,b[d].requirements,b[d].priority,b[d].isDomConstraint)}else this.$elements.splice(c,1);return this},getValue:function(){if("undefined"!=typeof this.options.value)return this.options.value;if(this.$element.is("input[type=radio]"))return this._findRelatedMultiple().filter(":checked").val()||"";if(this.$element.is("input[type=checkbox]")){var b=[];return this._findRelatedMultiple().filter(":checked").each(function(){b.push(a(this).val())}),b}return this.$element.is("select")&&null===this.$element.val()?[]:this.$element.val()},_init:function(){return this.$elements=[this.$element],this}};var p=function(b,c,d){this.$element=a(b);var e=this.$element.data("Parsley");if(e)return"undefined"!=typeof d&&e.parent===window.Parsley&&(e.parent=d,e._resetOptions(e.options)),e;if(!this.$element.length)throw new Error("You must bind Parsley on an existing element.");if("undefined"!=typeof d&&"ParsleyForm"!==d.__class__)throw new Error("Parent instance must be a ParsleyForm instance");return this.parent=d||window.Parsley,this.init(c)};p.prototype={init:function(a){return this.__class__="Parsley",this.__version__="2.1.2",this.__id__=f.generateID(),this._resetOptions(a),this.$element.is("form")||f.checkAttr(this.$element,this.options.namespace,"validate")&&!this.$element.is(this.options.inputs)?this.bind("parsleyForm"):this.isMultiple()?this.handleMultiple():this.bind("parsleyField")},isMultiple:function(){return this.$element.is("input[type=radio], input[type=checkbox]")||this.$element.is("select")&&"undefined"!=typeof this.$element.attr("multiple")},handleMultiple:function(){var b,c,d=this;if(this.options.multiple||("undefined"!=typeof this.$element.attr("name")&&this.$element.attr("name").length?this.options.multiple=b=this.$element.attr("name"):"undefined"!=typeof this.$element.attr("id")&&this.$element.attr("id").length&&(this.options.multiple=this.$element.attr("id"))),this.$element.is("select")&&"undefined"!=typeof this.$element.attr("multiple"))return this.options.multiple=this.options.multiple||this.__id__,this.bind("parsleyFieldMultiple");if(!this.options.multiple)return f.warn("To be bound by Parsley, a radio, a checkbox and a multiple select input must have either a name or a multiple option.",this.$element),this;this.options.multiple=this.options.multiple.replace(/(:|\.|\[|\]|\{|\}|\$)/g,""),"undefined"!=typeof b&&a('input[name="'+b+'"]').each(function(){a(this).is("input[type=radio], input[type=checkbox]")&&a(this).attr(d.options.namespace+"multiple",d.options.multiple)});for(var e=this._findRelatedMultiple(),g=0;g<e.length;g++)if(c=a(e.get(g)).data("Parsley"),"undefined"!=typeof c){this.$element.data("ParsleyFieldMultiple")||c.addElement(this.$element);break}return this.bind("parsleyField",!0),c||this.bind("parsleyFieldMultiple")},bind:function(b,c){var d;switch(b){case"parsleyForm":d=a.extend(new l(this.$element,this.domOptions,this.options),window.ParsleyExtend)._bindFields();break;case"parsleyField":d=a.extend(new n(this.$element,this.domOptions,this.options,this.parent),window.ParsleyExtend);break;case"parsleyFieldMultiple":d=a.extend(new n(this.$element,this.domOptions,this.options,this.parent),new o,window.ParsleyExtend)._init();break;default:throw new Error(b+"is not a supported Parsley type")}return this.options.multiple&&f.setAttr(this.$element,this.options.namespace,"multiple",this.options.multiple),"undefined"!=typeof c?(this.$element.data("ParsleyFieldMultiple",d),d):(this.$element.data("Parsley",d),d._trigger("init"),d)}};var q=a({}),r=function(){f.warnOnce("Parsley's pubsub module is deprecated; use the corresponding jQuery event method instead")},s="parsley:";a.listen=function(a,d){var e;if(r(),"object"==typeof arguments[1]&&"function"==typeof arguments[2]&&(e=arguments[1],d=arguments[2]),"function"!=typeof arguments[1])throw new Error("Wrong parameters");window.Parsley.on(c(a),b(d,e))},a.listenTo=function(a,d,e){if(r(),!(a instanceof n||a instanceof l))throw new Error("Must give Parsley instance");if("string"!=typeof d||"function"!=typeof e)throw new Error("Wrong parameters");a.on(c(d),b(e))},a.unsubscribe=function(a,b){if(r(),"string"!=typeof a||"function"!=typeof b)throw new Error("Wrong arguments");window.Parsley.off(c(a),b.parsleyAdaptedCallback)},a.unsubscribeTo=function(a,b){if(r(),!(a instanceof n||a instanceof l))throw new Error("Must give Parsley instance");a.off(c(b))},a.unsubscribeAll=function(b){r(),window.Parsley.off(c(b)),a("form,input,textarea,select").each(function(){var d=a(this).data("Parsley");d&&d.off(c(b))})},a.emit=function(a,b){r();var d=b instanceof n||b instanceof l,e=Array.prototype.slice.call(arguments,d?2:1);e.unshift(c(a)),d||(b=window.Parsley),b.trigger.apply(b,e)},window.ParsleyConfig=window.ParsleyConfig||{},window.ParsleyConfig.i18n=window.ParsleyConfig.i18n||{},window.ParsleyConfig.i18n.en=jQuery.extend(window.ParsleyConfig.i18n.en||{},{defaultMessage:"This value seems to be invalid.",type:{email:"This value should be a valid email.",url:"This value should be a valid url.",number:"This value should be a valid number.",integer:"This value should be a valid integer.",digits:"This value should be digits.",alphanum:"This value should be alphanumeric."},notblank:"This value should not be blank.",required:"This value is required.",pattern:"This value seems to be invalid.",min:"This value should be greater than or equal to %s.",max:"This value should be lower than or equal to %s.",range:"This value should be between %s and %s.",minlength:"This value is too short. It should have %s characters or more.",maxlength:"This value is too long. It should have %s characters or fewer.",length:"This value length is invalid. It should be between %s and %s characters long.",mincheck:"You must select at least %s choices.",maxcheck:"You must select %s choices or fewer.",check:"You must select between %s and %s choices.",equalto:"This value should be the same."}),"undefined"!=typeof window.ParsleyValidator&&window.ParsleyValidator.addCatalog("en",window.ParsleyConfig.i18n.en,!0);var t=a.extend(new h,{$element:a(document),actualizeOptions:null,_resetOptions:null,Factory:p,version:"2.1.2"});a.extend(n.prototype,h.prototype),a.extend(l.prototype,h.prototype),a.extend(p.prototype,h.prototype),a.fn.parsley=a.fn.psly=function(b){if(this.length>1){var c=[];return this.each(function(){c.push(a(this).parsley(b))}),c}return a(this).length?new p(this,b):void f.warn("You must bind Parsley on an existing element.")},"undefined"==typeof window.ParsleyExtend&&(window.ParsleyExtend={}),t.options=a.extend(f.objectCreate(g),window.ParsleyConfig),window.ParsleyConfig=t.options,window.Parsley=window.psly=t,window.ParsleyUtils=f,window.ParsleyValidator=new j(window.ParsleyConfig.validators,window.ParsleyConfig.i18n),window.ParsleyUI="function"==typeof window.ParsleyConfig.ParsleyUI?(new window.ParsleyConfig.ParsleyUI).listen():(new k).listen(),!1!==window.ParsleyConfig.autoBind&&a(function(){a("[data-parsley-validate]").length&&a("[data-parsley-validate]").parsley()})}); |
@@ -1,9 +0,10 @@ | ||
window.ParsleyExtend=window.ParsleyExtend||{},window.ParsleyExtend=$.extend(window.ParsleyExtend,{asyncSupport:!0,asyncValidators:$.extend({"default":{fn:function(a){return"resolved"===a.state()},url:!1},reverse:{fn:function(a){return"rejected"===a.state()},url:!1}},window.ParsleyExtend.asyncValidators),addAsyncValidator:function(a,b,c,d){return this.asyncValidators[a.toLowerCase()]={fn:b,url:c||!1,options:d||{}},this},asyncValidate:function(){return"ParsleyForm"===this.__class__?this._asyncValidateForm.apply(this,arguments):this._asyncValidateField.apply(this,arguments)},asyncIsValid:function(){return"ParsleyField"===this.__class__?this._asyncIsValidField.apply(this,arguments):this._asyncIsValidForm.apply(this,arguments)},onSubmitValidate:function(a){var b=this;if(!0!==a.parsley)return this.submitEvent=$.extend(!0,{},a),a instanceof $.Event&&(a.stopImmediatePropagation(),a.preventDefault()),this._asyncValidateForm(void 0,a).done(function(){b.submitEvent.isDefaultPrevented()||b.$element.trigger($.extend($.Event("submit"),{parsley:!0}))})},eventValidate:function(a){new RegExp("key").test(a.type)&&!this._ui.validationInformationVisible&&this.getValue().length<=this.options.validationThreshold||(this._ui.validatedOnce=!0,this.asyncValidate())},_asyncValidateForm:function(a){var b=this,c=[];this._refreshFields(),$.emit("parsley:form:validate",this);for(var d=0;d<this.fields.length;d++)a&&a!==this.fields[d].options.group||c.push(this.fields[d]._asyncValidateField());return $.when.apply($,c).done(function(){$.emit("parsley:form:success",b)}).fail(function(){$.emit("parsley:form:error",b)}).always(function(){$.emit("parsley:form:validated",b)})},_asyncIsValidForm:function(a,b){var c=[];this._refreshFields();for(var d=0;d<this.fields.length;d++)a&&a!==this.fields[d].options.group||c.push(this.fields[d]._asyncIsValidField(b));return $.when.apply($,c)},_asyncValidateField:function(a){var b=this;return $.emit("parsley:field:validate",this),this._asyncIsValidField(a).done(function(){$.emit("parsley:field:success",b)}).fail(function(){$.emit("parsley:field:error",b)}).always(function(){$.emit("parsley:field:validated",b)})},_asyncIsValidField:function(a,b){var c=$.Deferred();return!1===this.isValid(a,b)?c.rejectWith(this):"undefined"!=typeof this.constraintsByName.remote?this._remote(c):c.resolveWith(this),c.promise()},_remote:function(a){var b,c,d=this,e={},f=this.options.remoteValidator||(!0===this.options.remoteReverse?"reverse":"default");if(f=f.toLowerCase(),"undefined"==typeof this.asyncValidators[f])throw new Error("Calling an undefined async validator: `"+f+"`");e[this.$element.attr("name")||this.$element.attr("id")]=this.getValue(),this.options.remoteOptions=$.extend(!0,this.options.remoteOptions||{},this.asyncValidators[f].options),b=$.extend(!0,{},{url:this.asyncValidators[f].url||this.options.remote,data:e,type:"GET"},this.options.remoteOptions||{}),c=$.param(b),"undefined"==typeof this._remoteCache&&(this._remoteCache={}),this._remoteCache[c]||(this._xhr&&"pending"===this._xhr.state()&&this._xhr.abort(),this._xhr=$.ajax(b),this._remoteCache[c]=this._xhr),this._remoteCache[c].done(function(b,c,e){d._handleRemoteResult(f,e,a)}).fail(function(b,c){"abort"!==c&&d._handleRemoteResult(f,b,a)})},_handleRemoteResult:function(a,b,c){return"function"==typeof this.asyncValidators[a].fn&&this.asyncValidators[a].fn.call(this,b)?void c.resolveWith(this):(this.validationResult=[new window.ParsleyValidator.Validator.Violation(this.constraintsByName.remote,this.getValue(),null)],void c.rejectWith(this))}}),window.ParsleyConfig=window.ParsleyConfig||{},window.ParsleyConfig.validators=window.ParsleyConfig.validators||{},window.ParsleyConfig.validators.remote={fn:function(){return!0},priority:-1},/*! | ||
!function(a){window.ParsleyExtend=window.ParsleyExtend||{},window.ParsleyExtend=a.extend(!0,window.ParsleyExtend,{asyncSupport:!0,asyncValidators:{"default":{fn:function(a){return"resolved"===a.state()},url:!1},reverse:{fn:function(a){return"rejected"===a.state()},url:!1}},addAsyncValidator:function(a,b,c,d){return this.asyncValidators[a.toLowerCase()]={fn:b,url:c||!1,options:d||{}},this},asyncValidate:function(){return"ParsleyForm"===this.__class__?this._asyncValidateForm.apply(this,arguments):this._asyncValidateField.apply(this,arguments)},asyncIsValid:function(){return"ParsleyField"===this.__class__?this._asyncIsValidField.apply(this,arguments):this._asyncIsValidForm.apply(this,arguments)},onSubmitValidate:function(b){var c=this;if(!0!==b.parsley)return this.submitEvent=a.extend(!0,{},b),b instanceof a.Event&&(b.stopImmediatePropagation(),b.preventDefault()),this._asyncValidateForm(void 0,b).done(function(){c._trigger("submit")&&!c.submitEvent.isDefaultPrevented()&&c.$element.trigger(a.extend(a.Event("submit"),{parsley:!0}))})},eventValidate:function(a){new RegExp("key").test(a.type)&&!this._ui.validationInformationVisible&&this.getValue().length<=this.options.validationThreshold||(this._ui.validatedOnce=!0,this.asyncValidate())},_asyncValidateForm:function(b){var c=this,d=[];this._refreshFields(),this._trigger("validate");for(var e=0;e<this.fields.length;e++)b&&b!==this.fields[e].options.group||d.push(this.fields[e]._asyncValidateField());return a.when.apply(a,d).done(function(){c._trigger("success")}).fail(function(){c._trigger("error")}).always(function(){c._trigger("validated")})},_asyncIsValidForm:function(b,c){var d=[];this._refreshFields();for(var e=0;e<this.fields.length;e++)b&&b!==this.fields[e].options.group||d.push(this.fields[e]._asyncIsValidField(c));return a.when.apply(a,d)},_asyncValidateField:function(a){var b=this;return this._trigger("validate"),this._asyncIsValidField(a).done(function(){b._trigger("success")}).fail(function(){b._trigger("error")}).always(function(){b._trigger("validated")})},_asyncIsValidField:function(b,c){var d=a.Deferred();return!1===this.isValid(b,c)?d.rejectWith(this):"undefined"!=typeof this.constraintsByName.remote?this._remote(d):d.resolveWith(this),d.promise()},_remote:function(b){var c,d,e=this,f={},g=this.options.remoteValidator||(!0===this.options.remoteReverse?"reverse":"default");if(g=g.toLowerCase(),"undefined"==typeof this.asyncValidators[g])throw new Error("Calling an undefined async validator: `"+g+"`");f[this.$element.attr("name")||this.$element.attr("id")]=this.getValue(),this.options.remoteOptions=a.extend(!0,this.options.remoteOptions||{},this.asyncValidators[g].options),c=a.extend(!0,{},{url:this.asyncValidators[g].url||this.options.remote,data:f,type:"GET"},this.options.remoteOptions||{}),d=a.param(c),"undefined"==typeof this._remoteCache&&(this._remoteCache={}),this._remoteCache[d]||(this._xhr&&"pending"===this._xhr.state()&&this._xhr.abort(),this._xhr=a.ajax(c),this._remoteCache[d]=this._xhr),this._remoteCache[d].done(function(a,c,d){e._handleRemoteResult(g,d,b)}).fail(function(a,c){"abort"!==c&&e._handleRemoteResult(g,a,b)})},_handleRemoteResult:function(a,b,c){return"function"==typeof this.asyncValidators[a].fn&&this.asyncValidators[a].fn.call(this,b)?void c.resolveWith(this):(this.validationResult=[new window.ParsleyValidator.Validator.Violation(this.constraintsByName.remote,this.getValue(),null)],void c.rejectWith(this))}}),window.ParsleyConfig=window.ParsleyConfig||{},window.ParsleyConfig.validators=window.ParsleyConfig.validators||{},window.ParsleyConfig.validators.remote={fn:function(){return!0},priority:-1},window.Parsley.on("form:submit",function(){this._remoteCache={}})}(jQuery),/*! | ||
* Parsleyjs | ||
* Guillaume Potier - <guillaume@wisembly.com> | ||
* Version 2.0.6 - built Sat Jan 24 2015 14:44:37 | ||
* Version 2.1.2 - built Tue Jun 16 2015 10:32:01 | ||
* MIT Licensed | ||
* | ||
*/ | ||
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){"undefined"==typeof a&&"undefined"!=typeof window.jQuery&&(a=window.jQuery);var b={attr:function(a,b,c){var d,e={},f=this.msieversion(),g=new RegExp("^"+b,"i");if("undefined"==typeof a||"undefined"==typeof a[0])return{};for(var h in a[0].attributes)if(d=a[0].attributes[h],"undefined"!=typeof d&&null!==d&&(!f||f>=8||d.specified)&&g.test(d.name)){if("undefined"!=typeof c&&new RegExp(c+"$","i").test(d.name))return!0;e[this.camelize(d.name.replace(b,""))]=this.deserializeValue(d.value)}return"undefined"==typeof c?e:!1},setAttr:function(a,b,c,d){a[0].setAttribute(this.dasherize(b+c),String(d))},get:function(a,b){for(var c=0,d=(b||"").split(".");this.isObject(a)||this.isArray(a);)if(a=a[d[c++]],c===d.length)return a;return void 0},hash:function(a){return String(Math.random()).substring(2,a?a+2:9)},isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)},isObject:function(a){return a===Object(a)},deserializeValue:function(b){var c;try{return b?"true"==b||("false"==b?!1:"null"==b?null:isNaN(c=Number(b))?/^[\[\{]/.test(b)?a.parseJSON(b):b:c):b}catch(d){return b}},camelize:function(a){return a.replace(/-+(.)?/g,function(a,b){return b?b.toUpperCase():""})},dasherize:function(a){return a.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()},msieversion:function(){var a=window.navigator.userAgent,b=a.indexOf("MSIE ");return b>0||navigator.userAgent.match(/Trident.*rv\:11\./)?parseInt(a.substring(b+5,a.indexOf(".",b)),10):0}},c={namespace:"data-parsley-",inputs:"input, textarea, select",excluded:"input[type=button], input[type=submit], input[type=reset], input[type=hidden]",priorityEnabled:!0,uiEnabled:!0,validationThreshold:3,focus:"first",trigger:!1,errorClass:"parsley-error",successClass:"parsley-success",classHandler:function(){},errorsContainer:function(){},errorsWrapper:'<ul class="parsley-errors-list"></ul>',errorTemplate:"<li></li>"},d=function(){};d.prototype={asyncSupport:!1,actualizeOptions:function(){return this.options=this.OptionsFactory.get(this),this},validateThroughValidator:function(a,b,c){return window.ParsleyValidator.validate(a,b,c)},subscribe:function(b,c){return a.listenTo(this,b.toLowerCase(),c),this},unsubscribe:function(b){return a.unsubscribeTo(this,b.toLowerCase()),this},reset:function(){if("ParsleyForm"!==this.__class__)return a.emit("parsley:field:reset",this);for(var b=0;b<this.fields.length;b++)a.emit("parsley:field:reset",this.fields[b]);a.emit("parsley:form:reset",this)},destroy:function(){if("ParsleyForm"!==this.__class__)return this.$element.removeData("Parsley"),this.$element.removeData("ParsleyFieldMultiple"),void a.emit("parsley:field:destroy",this);for(var b=0;b<this.fields.length;b++)this.fields[b].destroy();this.$element.removeData("Parsley"),a.emit("parsley:form:destroy",this)}};var e=function(){var a={},b=function(a){this.__class__="Validator",this.__version__="1.0.1",this.options=a||{},this.bindingKey=this.options.bindingKey||"_validatorjsConstraint"};b.prototype={constructor:b,validate:function(a,b,c){if("string"!=typeof a&&"object"!=typeof a)throw new Error("You must validate an object or a string");return"string"==typeof a||g(a)?this._validateString(a,b,c):this.isBinded(a)?this._validateBindedObject(a,b):this._validateObject(a,b,c)},bind:function(a,b){if("object"!=typeof a)throw new Error("Must bind a Constraint to an object");return a[this.bindingKey]=new c(b),this},unbind:function(a){return"undefined"==typeof a._validatorjsConstraint?this:(delete a[this.bindingKey],this)},isBinded:function(a){return"undefined"!=typeof a[this.bindingKey]},getBinded:function(a){return this.isBinded(a)?a[this.bindingKey]:null},_validateString:function(a,b,c){var f,h=[];g(b)||(b=[b]);for(var i=0;i<b.length;i++){if(!(b[i]instanceof e))throw new Error("You must give an Assert or an Asserts array to validate a string");f=b[i].check(a,c),f instanceof d&&h.push(f)}return h.length?h:!0},_validateObject:function(a,b,d){if("object"!=typeof b)throw new Error("You must give a constraint to validate an object");return b instanceof c?b.check(a,d):new c(b).check(a,d)},_validateBindedObject:function(a,b){return a[this.bindingKey].check(a,b)}},b.errorCode={must_be_a_string:"must_be_a_string",must_be_an_array:"must_be_an_array",must_be_a_number:"must_be_a_number",must_be_a_string_or_array:"must_be_a_string_or_array"};var c=function(a,b){if(this.__class__="Constraint",this.options=b||{},this.nodes={},a)try{this._bootstrap(a)}catch(c){throw new Error("Should give a valid mapping object to Constraint",c,a)}};c.prototype={constructor:c,check:function(a,b){var c,d={};for(var h in this.nodes){for(var i=!1,j=this.get(h),k=g(j)?j:[j],l=k.length-1;l>=0;l--)"Required"!==k[l].__class__||(i=k[l].requiresValidation(b));if(this.has(h,a)||this.options.strict||i)try{this.has(h,this.options.strict||i?a:void 0)||(new e).HaveProperty(h).validate(a),c=this._check(h,a[h],b),(g(c)&&c.length>0||!g(c)&&!f(c))&&(d[h]=c)}catch(m){d[h]=m}}return f(d)?!0:d},add:function(a,b){if(b instanceof e||g(b)&&b[0]instanceof e)return this.nodes[a]=b,this;if("object"==typeof b&&!g(b))return this.nodes[a]=b instanceof c?b:new c(b),this;throw new Error("Should give an Assert, an Asserts array, a Constraint",b)},has:function(a,b){return b="undefined"!=typeof b?b:this.nodes,"undefined"!=typeof b[a]},get:function(a,b){return this.has(a)?this.nodes[a]:b||null},remove:function(a){var b=[];for(var c in this.nodes)c!==a&&(b[c]=this.nodes[c]);return this.nodes=b,this},_bootstrap:function(a){if(a instanceof c)return this.nodes=a.nodes;for(var b in a)this.add(b,a[b])},_check:function(a,b,d){if(this.nodes[a]instanceof e)return this._checkAsserts(b,[this.nodes[a]],d);if(g(this.nodes[a]))return this._checkAsserts(b,this.nodes[a],d);if(this.nodes[a]instanceof c)return this.nodes[a].check(b,d);throw new Error("Invalid node",this.nodes[a])},_checkAsserts:function(a,b,c){for(var d,e=[],f=0;f<b.length;f++)d=b[f].check(a,c),"undefined"!=typeof d&&!0!==d&&e.push(d);return e}};var d=function(a,b,c){if(this.__class__="Violation",!(a instanceof e))throw new Error("Should give an assertion implementing the Assert interface");this.assert=a,this.value=b,"undefined"!=typeof c&&(this.violation=c)};d.prototype={show:function(){var a={assert:this.assert.__class__,value:this.value};return this.violation&&(a.violation=this.violation),a},__toString:function(){return"undefined"!=typeof this.violation&&(this.violation='", '+this.getViolation().constraint+" expected was "+this.getViolation().expected),this.assert.__class__+' assert failed for "'+this.value+this.violation||""},getViolation:function(){var a,b;for(a in this.violation)b=this.violation[a];return{constraint:a,expected:b}}};var e=function(a){this.__class__="Assert",this.__parentClass__=this.__class__,this.groups=[],"undefined"!=typeof a&&this.addGroup(a)};e.prototype={construct:e,requiresValidation:function(a){return a&&!this.hasGroup(a)?!1:!a&&this.hasGroups()?!1:!0},check:function(a,b){if(this.requiresValidation(b))try{return this.validate(a,b)}catch(c){return c}},hasGroup:function(a){return g(a)?this.hasOneOf(a):"Any"===a?!0:this.hasGroups()?-1!==this.groups.indexOf(a):"Default"===a},hasOneOf:function(a){for(var b=0;b<a.length;b++)if(this.hasGroup(a[b]))return!0;return!1},hasGroups:function(){return this.groups.length>0},addGroup:function(a){return g(a)?this.addGroups(a):(this.hasGroup(a)||this.groups.push(a),this)},removeGroup:function(a){for(var b=[],c=0;c<this.groups.length;c++)a!==this.groups[c]&&b.push(this.groups[c]);return this.groups=b,this},addGroups:function(a){for(var b=0;b<a.length;b++)this.addGroup(a[b]);return this},HaveProperty:function(a){return this.__class__="HaveProperty",this.node=a,this.validate=function(a){if("undefined"==typeof a[this.node])throw new d(this,a,{value:this.node});return!0},this},Blank:function(){return this.__class__="Blank",this.validate=function(a){if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(""!==a.replace(/^\s+/g,"").replace(/\s+$/g,""))throw new d(this,a);return!0},this},Callback:function(a){if(this.__class__="Callback",this.arguments=Array.prototype.slice.call(arguments),1===this.arguments.length?this.arguments=[]:this.arguments.splice(0,1),"function"!=typeof a)throw new Error("Callback must be instanciated with a function");return this.fn=a,this.validate=function(a){var b=this.fn.apply(this,[a].concat(this.arguments));if(!0!==b)throw new d(this,a,{result:b});return!0},this},Choice:function(a){if(this.__class__="Choice",!g(a)&&"function"!=typeof a)throw new Error("Choice must be instanciated with an array or a function");return this.list=a,this.validate=function(a){for(var b="function"==typeof this.list?this.list():this.list,c=0;c<b.length;c++)if(a===b[c])return!0;throw new d(this,a,{choices:b})},this},Collection:function(a){return this.__class__="Collection",this.constraint="undefined"!=typeof a?a instanceof e?a:new c(a):!1,this.validate=function(a,c){var e,h=new b,i=0,j={},k=this.groups.length?this.groups:c;if(!g(a))throw new d(this,a,{value:b.errorCode.must_be_an_array});for(var l=0;l<a.length;l++)e=this.constraint?h.validate(a[l],this.constraint,k):h.validate(a[l],k),f(e)||(j[i]=e),i++;return f(j)?!0:j},this},Count:function(a){return this.__class__="Count",this.count=a,this.validate=function(a){if(!g(a))throw new d(this,a,{value:b.errorCode.must_be_an_array});var c="function"==typeof this.count?this.count(a):this.count;if(isNaN(Number(c)))throw new Error("Count must be a valid interger",c);if(c!==a.length)throw new d(this,a,{count:c});return!0},this},Email:function(){return this.__class__="Email",this.validate=function(a){var c=/^((([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;if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(!c.test(a))throw new d(this,a);return!0},this},EqualTo:function(a){if(this.__class__="EqualTo","undefined"==typeof a)throw new Error("EqualTo must be instanciated with a value or a function");return this.reference=a,this.validate=function(a){var b="function"==typeof this.reference?this.reference(a):this.reference;if(b!==a)throw new d(this,a,{value:b});return!0},this},GreaterThan:function(a){if(this.__class__="GreaterThan","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold>=a)throw new d(this,a,{threshold:this.threshold});return!0},this},GreaterThanOrEqual:function(a){if(this.__class__="GreaterThanOrEqual","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold>a)throw new d(this,a,{threshold:this.threshold});return!0},this},InstanceOf:function(a){if(this.__class__="InstanceOf","undefined"==typeof a)throw new Error("InstanceOf must be instanciated with a value");return this.classRef=a,this.validate=function(a){if(!0!=a instanceof this.classRef)throw new d(this,a,{classRef:this.classRef});return!0},this},Length:function(a){if(this.__class__="Length",!a.min&&!a.max)throw new Error("Lenth assert must be instanciated with a { min: x, max: y } object");return this.min=a.min,this.max=a.max,this.validate=function(a){if("string"!=typeof a&&!g(a))throw new d(this,a,{value:b.errorCode.must_be_a_string_or_array});if("undefined"!=typeof this.min&&this.min===this.max&&a.length!==this.min)throw new d(this,a,{min:this.min,max:this.max});if("undefined"!=typeof this.max&&a.length>this.max)throw new d(this,a,{max:this.max});if("undefined"!=typeof this.min&&a.length<this.min)throw new d(this,a,{min:this.min});return!0},this},LessThan:function(a){if(this.__class__="LessThan","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold<=a)throw new d(this,a,{threshold:this.threshold});return!0},this},LessThanOrEqual:function(a){if(this.__class__="LessThanOrEqual","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold<a)throw new d(this,a,{threshold:this.threshold});return!0},this},NotNull:function(){return this.__class__="NotNull",this.validate=function(a){if(null===a||"undefined"==typeof a)throw new d(this,a);return!0},this},NotBlank:function(){return this.__class__="NotBlank",this.validate=function(a){if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(""===a.replace(/^\s+/g,"").replace(/\s+$/g,""))throw new d(this,a);return!0},this},Null:function(){return this.__class__="Null",this.validate=function(a){if(null!==a)throw new d(this,a);return!0},this},Range:function(a,b){if(this.__class__="Range","undefined"==typeof a||"undefined"==typeof b)throw new Error("Range assert expects min and max values");return this.min=a,this.max=b,this.validate=function(a){try{return"string"==typeof a&&isNaN(Number(a))||g(a)?(new e).Length({min:this.min,max:this.max}).validate(a):(new e).GreaterThanOrEqual(this.min).validate(a)&&(new e).LessThanOrEqual(this.max).validate(a),!0}catch(b){throw new d(this,a,b.violation)}return!0},this},Regexp:function(a,c){if(this.__class__="Regexp","undefined"==typeof a)throw new Error("You must give a regexp");return this.regexp=a,this.flag=c||"",this.validate=function(a){if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(!new RegExp(this.regexp,this.flag).test(a))throw new d(this,a,{regexp:this.regexp,flag:this.flag});return!0},this},Required:function(){return this.__class__="Required",this.validate=function(a){if("undefined"==typeof a)throw new d(this,a);try{"string"==typeof a?(new e).NotNull().validate(a)&&(new e).NotBlank().validate(a):!0===g(a)&&(new e).Length({min:1}).validate(a)}catch(b){throw new d(this,a)}return!0},this},Unique:function(a){return this.__class__="Unique","object"==typeof a&&(this.key=a.key),this.validate=function(a){var c,e=[];if(!g(a))throw new d(this,a,{value:b.errorCode.must_be_an_array});for(var f=0;f<a.length;f++)if(c="object"==typeof a[f]?a[f][this.key]:a[f],"undefined"!=typeof c){if(-1!==e.indexOf(c))throw new d(this,a,{value:c});e.push(c)}return!0},this}},a.Assert=e,a.Validator=b,a.Violation=d,a.Constraint=c,Array.prototype.indexOf||(Array.prototype.indexOf=function(a){if(null===this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!==d&&1/0!=d&&d!=-1/0&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1});var f=function(a){for(var b in a)return!1;return!0},g=function(a){return"[object Array]"===Object.prototype.toString.call(a)};return"function"==typeof define&&define.amd?define("vendors/validator.js/dist/validator",[],function(){return a}):"undefined"!=typeof module&&module.exports?module.exports=a:window["undefined"!=typeof validatorjs_ns?validatorjs_ns:"Validator"]=a,a}();e="undefined"!=typeof e?e:"undefined"!=typeof module?module.exports:null;var f=function(a,b){this.__class__="ParsleyValidator",this.Validator=e,this.locale="en",this.init(a||{},b||{})};f.prototype={init:function(b,c){this.catalog=c;for(var d in b)this.addValidator(d,b[d].fn,b[d].priority,b[d].requirementsTransformer);a.emit("parsley:validator:init")},setLocale:function(a){if("undefined"==typeof this.catalog[a])throw new Error(a+" is not available in the catalog");return this.locale=a,this},addCatalog:function(a,b,c){return"object"==typeof b&&(this.catalog[a]=b),!0===c?this.setLocale(a):this},addMessage:function(a,b,c){return"undefined"==typeof this.catalog[a]&&(this.catalog[a]={}),this.catalog[a][b.toLowerCase()]=c,this},validate:function(){return(new this.Validator.Validator).validate.apply(new e.Validator,arguments)},addValidator:function(b,c,d,f){return this.validators[b.toLowerCase()]=function(b){return a.extend((new e.Assert).Callback(c,b),{priority:d,requirementsTransformer:f})},this},updateValidator:function(a,b,c,d){return this.addValidator(a,b,c,d)},removeValidator:function(a){return delete this.validators[a],this},getErrorMessage:function(a){var b;return b="type"===a.name?this.catalog[this.locale][a.name][a.requirements]:this.formatMessage(this.catalog[this.locale][a.name],a.requirements),""!==b?b:this.catalog[this.locale].defaultMessage},formatMessage:function(a,b){if("object"==typeof b){for(var c in b)a=this.formatMessage(a,b[c]);return a}return"string"==typeof a?a.replace(new RegExp("%s","i"),b):""},validators:{notblank:function(){return a.extend((new e.Assert).NotBlank(),{priority:2})},required:function(){return a.extend((new e.Assert).Required(),{priority:512})},type:function(b){var c;switch(b){case"email":c=(new e.Assert).Email();break;case"range":case"number":c=(new e.Assert).Regexp("^-?(?:\\d+|\\d{1,3}(?:,\\d{3})+)?(?:\\.\\d+)?$");break;case"integer":c=(new e.Assert).Regexp("^-?\\d+$");break;case"digits":c=(new e.Assert).Regexp("^\\d+$");break;case"alphanum":c=(new e.Assert).Regexp("^\\w+$","i");break;case"url":c=(new e.Assert).Regexp("(https?:\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,24}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)","i");break;default:throw new Error("validator type `"+b+"` is not supported")}return a.extend(c,{priority:256})},pattern:function(b){var c="";return/^\/.*\/(?:[gimy]*)$/.test(b)&&(c=b.replace(/.*\/([gimy]*)$/,"$1"),b=b.replace(new RegExp("^/(.*?)/"+c+"$"),"$1")),a.extend((new e.Assert).Regexp(b,c),{priority:64})},minlength:function(b){return a.extend((new e.Assert).Length({min:b}),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},maxlength:function(b){return a.extend((new e.Assert).Length({max:b}),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},length:function(b){return a.extend((new e.Assert).Length({min:b[0],max:b[1]}),{priority:32})},mincheck:function(a){return this.minlength(a)},maxcheck:function(a){return this.maxlength(a)},check:function(a){return this.length(a)},min:function(b){return a.extend((new e.Assert).GreaterThanOrEqual(b),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},max:function(b){return a.extend((new e.Assert).LessThanOrEqual(b),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},range:function(b){return a.extend((new e.Assert).Range(b[0],b[1]),{priority:32,requirementsTransformer:function(){for(var a=0;a<b.length;a++)b[a]="string"!=typeof b[a]||isNaN(b[a])?b[a]:parseInt(b[a],10);return b}})},equalto:function(b){return a.extend((new e.Assert).EqualTo(b),{priority:256,requirementsTransformer:function(){return a(b).length?a(b).val():b}})}}};var g=function(){this.__class__="ParsleyUI"};g.prototype={listen:function(){return a.listen("parsley:form:init",this,this.setupForm),a.listen("parsley:field:init",this,this.setupField),a.listen("parsley:field:validated",this,this.reflow),a.listen("parsley:form:validated",this,this.focus),a.listen("parsley:field:reset",this,this.reset),a.listen("parsley:form:destroy",this,this.destroy),a.listen("parsley:field:destroy",this,this.destroy),this},reflow:function(a){if("undefined"!=typeof a._ui&&!1!==a._ui.active){var b=this._diff(a.validationResult,a._ui.lastValidationResult);a._ui.lastValidationResult=a.validationResult,a._ui.validatedOnce=!0,this.manageStatusClass(a),this.manageErrorsMessages(a,b),this.actualizeTriggers(a),(b.kept.length||b.added.length)&&"undefined"==typeof a._ui.failedOnce&&this.manageFailingFieldTrigger(a)}},getErrorsMessages:function(a){if(!0===a.validationResult)return[];for(var b=[],c=0;c<a.validationResult.length;c++)b.push(this._getErrorMessage(a,a.validationResult[c].assert));return b},manageStatusClass:function(a){!0===a.validationResult?this._successClass(a):a.validationResult.length>0?this._errorClass(a):this._resetClass(a)},manageErrorsMessages:function(b,c){if("undefined"==typeof b.options.errorsMessagesDisabled){if("undefined"!=typeof b.options.errorMessage)return c.added.length||c.kept.length?(0===b._ui.$errorsWrapper.find(".parsley-custom-error-message").length&&b._ui.$errorsWrapper.append(a(b.options.errorTemplate).addClass("parsley-custom-error-message")),b._ui.$errorsWrapper.addClass("filled").find(".parsley-custom-error-message").html(b.options.errorMessage)):b._ui.$errorsWrapper.removeClass("filled").find(".parsley-custom-error-message").remove();for(var d=0;d<c.removed.length;d++)this.removeError(b,c.removed[d].assert.name,!0);for(d=0;d<c.added.length;d++)this.addError(b,c.added[d].assert.name,void 0,c.added[d].assert,!0);for(d=0;d<c.kept.length;d++)this.updateError(b,c.kept[d].assert.name,void 0,c.kept[d].assert,!0)}},addError:function(b,c,d,e,f){b._ui.$errorsWrapper.addClass("filled").append(a(b.options.errorTemplate).addClass("parsley-"+c).html(d||this._getErrorMessage(b,e))),!0!==f&&this._errorClass(b)},updateError:function(a,b,c,d,e){a._ui.$errorsWrapper.addClass("filled").find(".parsley-"+b).html(c||this._getErrorMessage(a,d)),!0!==e&&this._errorClass(a)},removeError:function(a,b,c){a._ui.$errorsWrapper.removeClass("filled").find(".parsley-"+b).remove(),!0!==c&&this.manageStatusClass(a)},focus:function(a){if(!0===a.validationResult||"none"===a.options.focus)return a._focusedField=null;a._focusedField=null;for(var b=0;b<a.fields.length;b++)if(!0!==a.fields[b].validationResult&&a.fields[b].validationResult.length>0&&"undefined"==typeof a.fields[b].options.noFocus){if("first"===a.options.focus)return a._focusedField=a.fields[b].$element,a._focusedField.focus();a._focusedField=a.fields[b].$element}return null===a._focusedField?null:a._focusedField.focus()},_getErrorMessage:function(a,b){var c=b.name+"Message";return"undefined"!=typeof a.options[c]?window.ParsleyValidator.formatMessage(a.options[c],b.requirements):window.ParsleyValidator.getErrorMessage(b)},_diff:function(a,b,c){for(var d=[],e=[],f=0;f<a.length;f++){for(var g=!1,h=0;h<b.length;h++)if(a[f].assert.name===b[h].assert.name){g=!0;break}g?e.push(a[f]):d.push(a[f])}return{kept:e,added:d,removed:c?[]:this._diff(b,a,!0).added}},setupForm:function(b){b.$element.on("submit.Parsley",!1,a.proxy(b.onSubmitValidate,b)),!1!==b.options.uiEnabled&&b.$element.attr("novalidate","")},setupField:function(b){var c={active:!1};!1!==b.options.uiEnabled&&(c.active=!0,b.$element.attr(b.options.namespace+"id",b.__id__),c.$errorClassHandler=this._manageClassHandler(b),c.errorsWrapperId="parsley-id-"+("undefined"!=typeof b.options.multiple?"multiple-"+b.options.multiple:b.__id__),c.$errorsWrapper=a(b.options.errorsWrapper).attr("id",c.errorsWrapperId),c.lastValidationResult=[],c.validatedOnce=!1,c.validationInformationVisible=!1,b._ui=c,b.$element.is(b.options.excluded)||this._insertErrorWrapper(b),this.actualizeTriggers(b))},_manageClassHandler:function(b){if("string"==typeof b.options.classHandler&&a(b.options.classHandler).length)return a(b.options.classHandler);var c=b.options.classHandler(b);return"undefined"!=typeof c&&c.length?c:"undefined"==typeof b.options.multiple||b.$element.is("select")?b.$element:b.$element.parent()},_insertErrorWrapper:function(b){var c;if("string"==typeof b.options.errorsContainer){if(a(b.options.errorsContainer).length)return a(b.options.errorsContainer).append(b._ui.$errorsWrapper);window.console&&window.console.warn&&window.console.warn("The errors container `"+b.options.errorsContainer+"` does not exist in DOM")}else"function"==typeof b.options.errorsContainer&&(c=b.options.errorsContainer(b));return"undefined"!=typeof c&&c.length?c.append(b._ui.$errorsWrapper):"undefined"==typeof b.options.multiple?b.$element.after(b._ui.$errorsWrapper):b.$element.parent().after(b._ui.$errorsWrapper)},actualizeTriggers:function(b){var c=b.$element;if(b.options.multiple&&(c=a("["+b.options.namespace+'multiple="'+b.options.multiple+'"]')),c.off(".Parsley"),!1!==b.options.trigger){var d=b.options.trigger.replace(/^\s+/g,"").replace(/\s+$/g,"");""!==d&&c.on(d.split(" ").join(".Parsley ")+".Parsley",a.proxy("function"==typeof b.eventValidate?b.eventValidate:this.eventValidate,b))}},eventValidate:function(a){new RegExp("key").test(a.type)&&!this._ui.validationInformationVisible&&this.getValue().length<=this.options.validationThreshold||(this._ui.validatedOnce=!0,this.validate())},manageFailingFieldTrigger:function(b){return b._ui.failedOnce=!0,b.options.multiple&&a("["+b.options.namespace+'multiple="'+b.options.multiple+'"]').each(function(){return new RegExp("change","i").test(a(this).parsley().options.trigger||"")?void 0:a(this).on("change.ParsleyFailedOnce",!1,a.proxy(b.validate,b))}),b.$element.is("select")&&!new RegExp("change","i").test(b.options.trigger||"")?b.$element.on("change.ParsleyFailedOnce",!1,a.proxy(b.validate,b)):new RegExp("keyup","i").test(b.options.trigger||"")?void 0:b.$element.on("keyup.ParsleyFailedOnce",!1,a.proxy(b.validate,b))},reset:function(a){a.$element.off(".Parsley"),a.$element.off(".ParsleyFailedOnce"),"undefined"!=typeof a._ui&&"ParsleyForm"!==a.__class__&&(a._ui.$errorsWrapper.removeClass("filled").children().remove(),this._resetClass(a),a._ui.validatedOnce=!1,a._ui.lastValidationResult=[],a._ui.validationInformationVisible=!1)},destroy:function(a){this.reset(a),"ParsleyForm"!==a.__class__&&("undefined"!=typeof a._ui&&a._ui.$errorsWrapper.remove(),delete a._ui)},_successClass:function(a){a._ui.validationInformationVisible=!0,a._ui.$errorClassHandler.removeClass(a.options.errorClass).addClass(a.options.successClass)},_errorClass:function(a){a._ui.validationInformationVisible=!0,a._ui.$errorClassHandler.removeClass(a.options.successClass).addClass(a.options.errorClass)},_resetClass:function(a){a._ui.$errorClassHandler.removeClass(a.options.successClass).removeClass(a.options.errorClass)}};var h=function(c,d,e,f){this.__class__="OptionsFactory",this.__id__=b.hash(4),this.formOptions=null,this.fieldOptions=null,this.staticOptions=a.extend(!0,{},c,d,e,{namespace:f})};h.prototype={get:function(a){if("undefined"==typeof a.__class__)throw new Error("Parsley Instance expected");switch(a.__class__){case"Parsley":return this.staticOptions;case"ParsleyForm":return this.getFormOptions(a);case"ParsleyField":case"ParsleyFieldMultiple":return this.getFieldOptions(a);default:throw new Error("Instance "+a.__class__+" is not supported")}},getFormOptions:function(c){return this.formOptions=b.attr(c.$element,this.staticOptions.namespace),a.extend({},this.staticOptions,this.formOptions)},getFieldOptions:function(c){return this.fieldOptions=b.attr(c.$element,this.staticOptions.namespace),null===this.formOptions&&"undefined"!=typeof c.parent&&(this.formOptions=this.getFormOptions(c.parent)),a.extend({},this.staticOptions,this.formOptions,this.fieldOptions)}};var i=function(c,d){if(this.__class__="ParsleyForm",this.__id__=b.hash(4),"OptionsFactory"!==b.get(d,"__class__"))throw new Error("You must give an OptionsFactory instance");this.OptionsFactory=d,this.$element=a(c),this.validationResult=null,this.options=this.OptionsFactory.get(this)};i.prototype={onSubmitValidate:function(b){return this.validate(void 0,void 0,b),!1===this.validationResult&&b instanceof a.Event&&(b.stopImmediatePropagation(),b.preventDefault()),this},validate:function(b,c,d){this.submitEvent=d,this.validationResult=!0;var e=[];a.emit("parsley:form:validate",this),this._refreshFields();for(var f=0;f<this.fields.length;f++)(!b||this._isFieldInGroup(this.fields[f],b))&&(e=this.fields[f].validate(c),!0!==e&&e.length>0&&this.validationResult&&(this.validationResult=!1));return a.emit("parsley:form:"+(this.validationResult?"success":"error"),this),a.emit("parsley:form:validated",this),this.validationResult},isValid:function(a,b){this._refreshFields();for(var c=0;c<this.fields.length;c++)if((!a||this._isFieldInGroup(this.fields[c],a))&&!1===this.fields[c].isValid(b))return!1;return!0},_isFieldInGroup:function(c,d){return b.isArray(c.options.group)?-1!==a.inArray(d,c.options.group):c.options.group===d},_refreshFields:function(){return this.actualizeOptions()._bindFields()},_bindFields:function(){var a=this;return this.fields=[],this.fieldsMappedById={},this.$element.find(this.options.inputs).each(function(){var b=new window.Parsley(this,{},a);"ParsleyField"!==b.__class__&&"ParsleyFieldMultiple"!==b.__class__||b.$element.is(b.options.excluded)||"undefined"==typeof a.fieldsMappedById[b.__class__+"-"+b.__id__]&&(a.fieldsMappedById[b.__class__+"-"+b.__id__]=b,a.fields.push(b))}),this}};var j=function(c,d,e,f,g){var h={};if(!new RegExp("ParsleyField").test(b.get(c,"__class__")))throw new Error("ParsleyField or ParsleyFieldMultiple instance expected");if("function"==typeof window.ParsleyValidator.validators[d]&&(h=window.ParsleyValidator.validators[d](e)),"Assert"!==h.__parentClass__)throw new Error("Valid validator expected");var i=function(){return"undefined"!=typeof c.options[d+"Priority"]?c.options[d+"Priority"]:b.get(h,"priority")||2};return f=f||i(),"function"==typeof h.requirementsTransformer&&(e=h.requirementsTransformer(),h=window.ParsleyValidator.validators[d](e)),a.extend(h,{name:d,requirements:e,priority:f,groups:[f],isDomConstraint:g||b.attr(c.$element,c.options.namespace,d)})},k=function(c,d,e){this.__class__="ParsleyField",this.__id__=b.hash(4),this.$element=a(c),"undefined"!=typeof e?(this.parent=e,this.OptionsFactory=this.parent.OptionsFactory,this.options=this.OptionsFactory.get(this)):(this.OptionsFactory=d,this.options=this.OptionsFactory.get(this)),this.constraints=[],this.constraintsByName={},this.validationResult=[],this._bindConstraints()};k.prototype={validate:function(b){return this.value=this.getValue(),a.emit("parsley:field:validate",this),a.emit("parsley:field:"+(this.isValid(b,this.value)?"success":"error"),this),a.emit("parsley:field:validated",this),this.validationResult},isValid:function(a,b){this.refreshConstraints();var c=this._getConstraintsSortedPriorities();if(0===c.length)return this.validationResult=[];if(("undefined"==typeof b||null===b)&&(b=this.getValue()),!b.length&&!this._isRequired()&&"undefined"==typeof this.options.validateIfEmpty&&!0!==a)return this.validationResult=[];if(!1===this.options.priorityEnabled)return!0===(this.validationResult=this.validateThroughValidator(b,this.constraints,"Any"));for(var d=0;d<c.length;d++)if(!0!==(this.validationResult=this.validateThroughValidator(b,this.constraints,c[d])))return!1;return!0},getValue:function(){var a;return a="undefined"!=typeof this.options.value?this.options.value:this.$element.val(),"undefined"==typeof a||null===a?"":!0===this.options.trimValue?a.replace(/^\s+|\s+$/g,""):a},refreshConstraints:function(){return this.actualizeOptions()._bindConstraints()},addConstraint:function(a,b,c,d){if(a=a.toLowerCase(),"function"==typeof window.ParsleyValidator.validators[a]){var e=new j(this,a,b,c,d); | ||
"undefined"!==this.constraintsByName[e.name]&&this.removeConstraint(e.name),this.constraints.push(e),this.constraintsByName[e.name]=e}return this},removeConstraint:function(a){for(var b=0;b<this.constraints.length;b++)if(a===this.constraints[b].name){this.constraints.splice(b,1);break}return delete this.constraintsByName[a],this},updateConstraint:function(a,b,c){return this.removeConstraint(a).addConstraint(a,b,c)},_bindConstraints:function(){for(var a=[],b={},c=0;c<this.constraints.length;c++)!1===this.constraints[c].isDomConstraint&&(a.push(this.constraints[c]),b[this.constraints[c].name]=this.constraints[c]);this.constraints=a,this.constraintsByName=b;for(var d in this.options)this.addConstraint(d,this.options[d]);return this._bindHtml5Constraints()},_bindHtml5Constraints:function(){(this.$element.hasClass("required")||this.$element.attr("required"))&&this.addConstraint("required",!0,void 0,!0),"string"==typeof this.$element.attr("pattern")&&this.addConstraint("pattern",this.$element.attr("pattern"),void 0,!0),"undefined"!=typeof this.$element.attr("min")&&"undefined"!=typeof this.$element.attr("max")?this.addConstraint("range",[this.$element.attr("min"),this.$element.attr("max")],void 0,!0):"undefined"!=typeof this.$element.attr("min")?this.addConstraint("min",this.$element.attr("min"),void 0,!0):"undefined"!=typeof this.$element.attr("max")&&this.addConstraint("max",this.$element.attr("max"),void 0,!0),"undefined"!=typeof this.$element.attr("minlength")&&"undefined"!=typeof this.$element.attr("maxlength")?this.addConstraint("length",[this.$element.attr("minlength"),this.$element.attr("maxlength")],void 0,!0):"undefined"!=typeof this.$element.attr("minlength")?this.addConstraint("minlength",this.$element.attr("minlength"),void 0,!0):"undefined"!=typeof this.$element.attr("maxlength")&&this.addConstraint("maxlength",this.$element.attr("maxlength"),void 0,!0);var a=this.$element.attr("type");return"undefined"==typeof a?this:"number"===a?"undefined"==typeof this.$element.attr("step")||0===parseFloat(this.$element.attr("step"))%1?this.addConstraint("type","integer",void 0,!0):this.addConstraint("type","number",void 0,!0):new RegExp(a,"i").test("email url range")?this.addConstraint("type",a,void 0,!0):this},_isRequired:function(){return"undefined"==typeof this.constraintsByName.required?!1:!1!==this.constraintsByName.required.requirements},_getConstraintsSortedPriorities:function(){for(var a=[],b=0;b<this.constraints.length;b++)-1===a.indexOf(this.constraints[b].priority)&&a.push(this.constraints[b].priority);return a.sort(function(a,b){return b-a}),a}};var l=function(){this.__class__="ParsleyFieldMultiple"};l.prototype={addElement:function(a){return this.$elements.push(a),this},refreshConstraints:function(){var b;if(this.constraints=[],this.$element.is("select"))return this.actualizeOptions()._bindConstraints(),this;for(var c=0;c<this.$elements.length;c++)if(a("html").has(this.$elements[c]).length){b=this.$elements[c].data("ParsleyFieldMultiple").refreshConstraints().constraints;for(var d=0;d<b.length;d++)this.addConstraint(b[d].name,b[d].requirements,b[d].priority,b[d].isDomConstraint)}else this.$elements.splice(c,1);return this},getValue:function(){if("undefined"!=typeof this.options.value)return this.options.value;if(this.$element.is("input[type=radio]"))return a("["+this.options.namespace+'multiple="'+this.options.multiple+'"]:checked').val()||"";if(this.$element.is("input[type=checkbox]")){var b=[];return a("["+this.options.namespace+'multiple="'+this.options.multiple+'"]:checked').each(function(){b.push(a(this).val())}),b.length?b:[]}return this.$element.is("select")&&null===this.$element.val()?[]:this.$element.val()},_init:function(a){return this.$elements=[this.$element],this.options.multiple=a,this}};var m=a({}),n={};a.listen=function(a){if("undefined"==typeof n[a]&&(n[a]=[]),"function"==typeof arguments[1])return n[a].push({fn:arguments[1]});if("object"==typeof arguments[1]&&"function"==typeof arguments[2])return n[a].push({fn:arguments[2],ctxt:arguments[1]});throw new Error("Wrong parameters")},a.listenTo=function(a,b,c){if("undefined"==typeof n[b]&&(n[b]=[]),!(a instanceof k||a instanceof i))throw new Error("Must give Parsley instance");if("string"!=typeof b||"function"!=typeof c)throw new Error("Wrong parameters");n[b].push({instance:a,fn:c})},a.unsubscribe=function(a,b){if("undefined"!=typeof n[a]){if("string"!=typeof a||"function"!=typeof b)throw new Error("Wrong arguments");for(var c=0;c<n[a].length;c++)if(n[a][c].fn===b)return n[a].splice(c,1)}},a.unsubscribeTo=function(a,b){if("undefined"!=typeof n[b]){if(!(a instanceof k||a instanceof i))throw new Error("Must give Parsley instance");for(var c=0;c<n[b].length;c++)if("undefined"!=typeof n[b][c].instance&&n[b][c].instance.__id__===a.__id__)return n[b].splice(c,1)}},a.unsubscribeAll=function(a){"undefined"!=typeof n[a]&&delete n[a]},a.emit=function(a,b){if("undefined"!=typeof n[a])for(var c=0;c<n[a].length;c++)if("undefined"!=typeof n[a][c].instance){if(b instanceof k||b instanceof i)if(n[a][c].instance.__id__!==b.__id__){if(n[a][c].instance instanceof i&&b instanceof k)for(var d=0;d<n[a][c].instance.fields.length;d++)if(n[a][c].instance.fields[d].__id__===b.__id__){n[a][c].fn.apply(m,Array.prototype.slice.call(arguments,1));continue}}else n[a][c].fn.apply(m,Array.prototype.slice.call(arguments,1))}else n[a][c].fn.apply("undefined"!=typeof n[a][c].ctxt?n[a][c].ctxt:m,Array.prototype.slice.call(arguments,1))},a.subscribed=function(){return n},window.ParsleyConfig=window.ParsleyConfig||{},window.ParsleyConfig.i18n=window.ParsleyConfig.i18n||{},window.ParsleyConfig.i18n.en=a.extend(window.ParsleyConfig.i18n.en||{},{defaultMessage:"This value seems to be invalid.",type:{email:"This value should be a valid email.",url:"This value should be a valid url.",number:"This value should be a valid number.",integer:"This value should be a valid integer.",digits:"This value should be digits.",alphanum:"This value should be alphanumeric."},notblank:"This value should not be blank.",required:"This value is required.",pattern:"This value seems to be invalid.",min:"This value should be greater than or equal to %s.",max:"This value should be lower than or equal to %s.",range:"This value should be between %s and %s.",minlength:"This value is too short. It should have %s characters or more.",maxlength:"This value is too long. It should have %s characters or fewer.",length:"This value length is invalid. It should be between %s and %s characters long.",mincheck:"You must select at least %s choices.",maxcheck:"You must select %s choices or fewer.",check:"You must select between %s and %s choices.",equalto:"This value should be the same."}),"undefined"!=typeof window.ParsleyValidator&&window.ParsleyValidator.addCatalog("en",window.ParsleyConfig.i18n.en,!0);var o=function(c,d,e){if(this.__class__="Parsley",this.__version__="2.0.6",this.__id__=b.hash(4),"undefined"==typeof c)throw new Error("You must give an element");if("undefined"!=typeof e&&"ParsleyForm"!==e.__class__)throw new Error("Parent instance must be a ParsleyForm instance");return this.init(a(c),d,e)};o.prototype={init:function(a,d,e){if(!a.length)throw new Error("You must bind Parsley on an existing element.");if(this.$element=a,this.$element.data("Parsley")){var f=this.$element.data("Parsley");return"undefined"!=typeof e&&(f.parent=e),f}return this.OptionsFactory=new h(c,b.get(window,"ParsleyConfig")||{},d,this.getNamespace(d)),this.options=this.OptionsFactory.get(this),this.$element.is("form")||b.attr(this.$element,this.options.namespace,"validate")&&!this.$element.is(this.options.inputs)?this.bind("parsleyForm"):this.$element.is(this.options.inputs)&&!this.$element.is(this.options.excluded)?this.isMultiple()?this.handleMultiple(e):this.bind("parsleyField",e):this},isMultiple:function(){return this.$element.is("input[type=radio], input[type=checkbox]")&&"undefined"==typeof this.options.multiple||this.$element.is("select")&&"undefined"!=typeof this.$element.attr("multiple")},handleMultiple:function(c){var d,e,f,g=this;if(this.options=a.extend(this.options,c?c.OptionsFactory.get(c):{},b.attr(this.$element,this.options.namespace)),this.options.multiple?e=this.options.multiple:"undefined"!=typeof this.$element.attr("name")&&this.$element.attr("name").length?e=d=this.$element.attr("name"):"undefined"!=typeof this.$element.attr("id")&&this.$element.attr("id").length&&(e=this.$element.attr("id")),this.$element.is("select")&&"undefined"!=typeof this.$element.attr("multiple"))return this.bind("parsleyFieldMultiple",c,e||this.__id__);if("undefined"==typeof e)return window.console&&window.console.warn&&window.console.warn("To be binded by Parsley, a radio, a checkbox and a multiple select input must have either a name or a multiple option.",this.$element),this;if(e=e.replace(/(:|\.|\[|\]|\{|\}|\$)/g,""),"undefined"!=typeof d&&a('input[name="'+d+'"]').each(function(){a(this).is("input[type=radio], input[type=checkbox]")&&a(this).attr(g.options.namespace+"multiple",e)}),a("["+this.options.namespace+"multiple="+e+"]").length)for(var h=0;h<a("["+this.options.namespace+"multiple="+e+"]").length;h++)if("undefined"!=typeof a(a("["+this.options.namespace+"multiple="+e+"]").get(h)).data("Parsley")){f=a(a("["+this.options.namespace+"multiple="+e+"]").get(h)).data("Parsley"),this.$element.data("ParsleyFieldMultiple")||(f.addElement(this.$element),this.$element.attr(this.options.namespace+"id",f.__id__));break}return this.bind("parsleyField",c,e,!0),f||this.bind("parsleyFieldMultiple",c,e)},getNamespace:function(a){return"undefined"!=typeof this.$element.data("parsleyNamespace")?this.$element.data("parsleyNamespace"):"undefined"!=typeof b.get(a,"namespace")?a.namespace:"undefined"!=typeof b.get(window,"ParsleyConfig.namespace")?window.ParsleyConfig.namespace:c.namespace},bind:function(c,e,f,g){var h;switch(c){case"parsleyForm":h=a.extend(new i(this.$element,this.OptionsFactory),new d,window.ParsleyExtend)._bindFields();break;case"parsleyField":h=a.extend(new k(this.$element,this.OptionsFactory,e),new d,window.ParsleyExtend);break;case"parsleyFieldMultiple":h=a.extend(new k(this.$element,this.OptionsFactory,e),new d,new l,window.ParsleyExtend)._init(f);break;default:throw new Error(c+"is not a supported Parsley type")}return"undefined"!=typeof f&&b.setAttr(this.$element,this.options.namespace,"multiple",f),"undefined"!=typeof g?(this.$element.data("ParsleyFieldMultiple",h),h):(new RegExp("ParsleyF","i").test(h.__class__)&&(this.$element.data("Parsley",h),a.emit("parsley:"+("parsleyForm"===c?"form":"field")+":init",h)),h)}},a.fn.parsley=a.fn.psly=function(b){if(this.length>1){var c=[];return this.each(function(){c.push(a(this).parsley(b))}),c}return a(this).length?new o(this,b):void(window.console&&window.console.warn&&window.console.warn("You must bind Parsley on an existing element."))},window.ParsleyUI="function"==typeof b.get(window,"ParsleyConfig.ParsleyUI")?(new window.ParsleyConfig.ParsleyUI).listen():(new g).listen(),"undefined"==typeof window.ParsleyExtend&&(window.ParsleyExtend={}),"undefined"==typeof window.ParsleyConfig&&(window.ParsleyConfig={}),window.Parsley=window.psly=o,window.ParsleyUtils=b,window.ParsleyValidator=new f(window.ParsleyConfig.validators,window.ParsleyConfig.i18n),!1!==b.get(window,"ParsleyConfig.autoBind")&&a(function(){a("[data-parsley-validate]").length&&a("[data-parsley-validate]").parsley()})}); | ||
!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){function b(a,b){return a.parsleyAdaptedCallback||(a.parsleyAdaptedCallback=function(){var c=Array.prototype.slice.call(arguments,0);c.unshift(this),a.apply(b||q,c)}),a.parsleyAdaptedCallback}function c(a){return 0===a.lastIndexOf(s,0)?a.substr(s.length):a}"undefined"==typeof a&&"undefined"!=typeof window.jQuery&&(a=window.jQuery);var d=1,e={},f={attr:function(a,b,c){var d,e,f=new RegExp("^"+b,"i");if("undefined"==typeof c)c={};else for(var g in c)c.hasOwnProperty(g)&&delete c[g];if("undefined"==typeof a||"undefined"==typeof a[0])return c;e=a[0].attributes;for(var g=e.length;g--;)d=e[g],d&&d.specified&&f.test(d.name)&&(c[this.camelize(d.name.slice(b.length))]=this.deserializeValue(d.value));return c},checkAttr:function(a,b,c){return a.is("["+b+c+"]")},setAttr:function(a,b,c,d){a[0].setAttribute(this.dasherize(b+c),String(d))},generateID:function(){return""+d++},deserializeValue:function(b){var c;try{return b?"true"==b||("false"==b?!1:"null"==b?null:isNaN(c=Number(b))?/^[\[\{]/.test(b)?a.parseJSON(b):b:c):b}catch(d){return b}},camelize:function(a){return a.replace(/-+(.)?/g,function(a,b){return b?b.toUpperCase():""})},dasherize:function(a){return a.replace(/::/g,"/").replace(/([A-Z]+)([A-Z][a-z])/g,"$1_$2").replace(/([a-z\d])([A-Z])/g,"$1_$2").replace(/_/g,"-").toLowerCase()},warn:function(){window.console&&window.console.warn&&window.console.warn.apply(window.console,arguments)},warnOnce:function(a){e[a]||(e[a]=!0,this.warn.apply(this,arguments))},_resetWarnings:function(){e={}},objectCreate:Object.create||function(){var a=function(){};return function(b){if(arguments.length>1)throw Error("Second argument not supported");if("object"!=typeof b)throw TypeError("Argument must be an object");a.prototype=b;var c=new a;return a.prototype=null,c}}()},g={namespace:"data-parsley-",inputs:"input, textarea, select",excluded:"input[type=button], input[type=submit], input[type=reset], input[type=hidden]",priorityEnabled:!0,multiple:null,group:null,uiEnabled:!0,validationThreshold:3,focus:"first",trigger:!1,errorClass:"parsley-error",successClass:"parsley-success",classHandler:function(){},errorsContainer:function(){},errorsWrapper:'<ul class="parsley-errors-list"></ul>',errorTemplate:"<li></li>"},h=function(){};h.prototype={asyncSupport:!1,actualizeOptions:function(){return f.attr(this.$element,this.options.namespace,this.domOptions),this.parent&&this.parent.actualizeOptions&&this.parent.actualizeOptions(),this},_resetOptions:function(a){this.domOptions=f.objectCreate(this.parent.options),this.options=f.objectCreate(this.domOptions);for(var b in a)a.hasOwnProperty(b)&&(this.options[b]=a[b]);this.actualizeOptions()},validateThroughValidator:function(a,b,c){return window.ParsleyValidator.validate(a,b,c)},_listeners:null,on:function(a,b){this._listeners=this._listeners||{};var c=this._listeners[a]=this._listeners[a]||[];return c.push(b),this},subscribe:function(b,c){a.listenTo(this,b.toLowerCase(),c)},off:function(a,b){var c=this._listeners&&this._listeners[a];if(c)if(b)for(var d=c.length;d--;)c[d]===b&&c.splice(d,1);else delete this._listeners[a];return this},unsubscribe:function(b){a.unsubscribeTo(this,b.toLowerCase())},trigger:function(a,b){b=b||this;var c,d=this._listeners&&this._listeners[a];if(d)for(var e=d.length;e--;)if(c=d[e].call(b,b),c===!1)return c;return this.parent?this.parent.trigger(a,b):!0},reset:function(){if("ParsleyForm"!==this.__class__)return this._trigger("reset");for(var a=0;a<this.fields.length;a++)this.fields[a]._trigger("reset");this._trigger("reset")},destroy:function(){if("ParsleyForm"!==this.__class__)return this.$element.removeData("Parsley"),this.$element.removeData("ParsleyFieldMultiple"),void this._trigger("destroy");for(var a=0;a<this.fields.length;a++)this.fields[a].destroy();this.$element.removeData("Parsley"),this._trigger("destroy")},_findRelatedMultiple:function(){return this.parent.$element.find("["+this.options.namespace+'multiple="'+this.options.multiple+'"]')}};var i=function(){var a={},b=function(a){this.__class__="Validator",this.__version__="1.0.1",this.options=a||{},this.bindingKey=this.options.bindingKey||"_validatorjsConstraint"};b.prototype={constructor:b,validate:function(a,b,c){if("string"!=typeof a&&"object"!=typeof a)throw new Error("You must validate an object or a string");return"string"==typeof a||g(a)?this._validateString(a,b,c):this.isBinded(a)?this._validateBindedObject(a,b):this._validateObject(a,b,c)},bind:function(a,b){if("object"!=typeof a)throw new Error("Must bind a Constraint to an object");return a[this.bindingKey]=new c(b),this},unbind:function(a){return"undefined"==typeof a._validatorjsConstraint?this:(delete a[this.bindingKey],this)},isBinded:function(a){return"undefined"!=typeof a[this.bindingKey]},getBinded:function(a){return this.isBinded(a)?a[this.bindingKey]:null},_validateString:function(a,b,c){var f,h=[];g(b)||(b=[b]);for(var i=0;i<b.length;i++){if(!(b[i]instanceof e))throw new Error("You must give an Assert or an Asserts array to validate a string");f=b[i].check(a,c),f instanceof d&&h.push(f)}return h.length?h:!0},_validateObject:function(a,b,d){if("object"!=typeof b)throw new Error("You must give a constraint to validate an object");return b instanceof c?b.check(a,d):new c(b).check(a,d)},_validateBindedObject:function(a,b){return a[this.bindingKey].check(a,b)}},b.errorCode={must_be_a_string:"must_be_a_string",must_be_an_array:"must_be_an_array",must_be_a_number:"must_be_a_number",must_be_a_string_or_array:"must_be_a_string_or_array"};var c=function(a,b){if(this.__class__="Constraint",this.options=b||{},this.nodes={},a)try{this._bootstrap(a)}catch(c){throw new Error("Should give a valid mapping object to Constraint",c,a)}};c.prototype={constructor:c,check:function(a,b){var c,d={};for(var h in this.nodes){for(var i=!1,j=this.get(h),k=g(j)?j:[j],l=k.length-1;l>=0;l--)"Required"!==k[l].__class__||(i=k[l].requiresValidation(b));if(this.has(h,a)||this.options.strict||i)try{this.has(h,this.options.strict||i?a:void 0)||(new e).HaveProperty(h).validate(a),c=this._check(h,a[h],b),(g(c)&&c.length>0||!g(c)&&!f(c))&&(d[h]=c)}catch(m){d[h]=m}}return f(d)?!0:d},add:function(a,b){if(b instanceof e||g(b)&&b[0]instanceof e)return this.nodes[a]=b,this;if("object"==typeof b&&!g(b))return this.nodes[a]=b instanceof c?b:new c(b),this;throw new Error("Should give an Assert, an Asserts array, a Constraint",b)},has:function(a,b){return b="undefined"!=typeof b?b:this.nodes,"undefined"!=typeof b[a]},get:function(a,b){return this.has(a)?this.nodes[a]:b||null},remove:function(a){var b=[];for(var c in this.nodes)c!==a&&(b[c]=this.nodes[c]);return this.nodes=b,this},_bootstrap:function(a){if(a instanceof c)return this.nodes=a.nodes;for(var b in a)this.add(b,a[b])},_check:function(a,b,d){if(this.nodes[a]instanceof e)return this._checkAsserts(b,[this.nodes[a]],d);if(g(this.nodes[a]))return this._checkAsserts(b,this.nodes[a],d);if(this.nodes[a]instanceof c)return this.nodes[a].check(b,d);throw new Error("Invalid node",this.nodes[a])},_checkAsserts:function(a,b,c){for(var d,e=[],f=0;f<b.length;f++)d=b[f].check(a,c),"undefined"!=typeof d&&!0!==d&&e.push(d);return e}};var d=function(a,b,c){if(this.__class__="Violation",!(a instanceof e))throw new Error("Should give an assertion implementing the Assert interface");this.assert=a,this.value=b,"undefined"!=typeof c&&(this.violation=c)};d.prototype={show:function(){var a={assert:this.assert.__class__,value:this.value};return this.violation&&(a.violation=this.violation),a},__toString:function(){return"undefined"!=typeof this.violation&&(this.violation='", '+this.getViolation().constraint+" expected was "+this.getViolation().expected),this.assert.__class__+' assert failed for "'+this.value+this.violation||""},getViolation:function(){var a,b;for(a in this.violation)b=this.violation[a];return{constraint:a,expected:b}}};var e=function(a){this.__class__="Assert",this.__parentClass__=this.__class__,this.groups=[],"undefined"!=typeof a&&this.addGroup(a)};e.prototype={construct:e,requiresValidation:function(a){return a&&!this.hasGroup(a)?!1:!a&&this.hasGroups()?!1:!0},check:function(a,b){if(this.requiresValidation(b))try{return this.validate(a,b)}catch(c){return c}},hasGroup:function(a){return g(a)?this.hasOneOf(a):"Any"===a?!0:this.hasGroups()?-1!==this.groups.indexOf(a):"Default"===a},hasOneOf:function(a){for(var b=0;b<a.length;b++)if(this.hasGroup(a[b]))return!0;return!1},hasGroups:function(){return this.groups.length>0},addGroup:function(a){return g(a)?this.addGroups(a):(this.hasGroup(a)||this.groups.push(a),this)},removeGroup:function(a){for(var b=[],c=0;c<this.groups.length;c++)a!==this.groups[c]&&b.push(this.groups[c]);return this.groups=b,this},addGroups:function(a){for(var b=0;b<a.length;b++)this.addGroup(a[b]);return this},HaveProperty:function(a){return this.__class__="HaveProperty",this.node=a,this.validate=function(a){if("undefined"==typeof a[this.node])throw new d(this,a,{value:this.node});return!0},this},Blank:function(){return this.__class__="Blank",this.validate=function(a){if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(""!==a.replace(/^\s+/g,"").replace(/\s+$/g,""))throw new d(this,a);return!0},this},Callback:function(a){if(this.__class__="Callback",this.arguments=Array.prototype.slice.call(arguments),1===this.arguments.length?this.arguments=[]:this.arguments.splice(0,1),"function"!=typeof a)throw new Error("Callback must be instanciated with a function");return this.fn=a,this.validate=function(a){var b=this.fn.apply(this,[a].concat(this.arguments));if(!0!==b)throw new d(this,a,{result:b});return!0},this},Choice:function(a){if(this.__class__="Choice",!g(a)&&"function"!=typeof a)throw new Error("Choice must be instanciated with an array or a function");return this.list=a,this.validate=function(a){for(var b="function"==typeof this.list?this.list():this.list,c=0;c<b.length;c++)if(a===b[c])return!0;throw new d(this,a,{choices:b})},this},Collection:function(a){return this.__class__="Collection",this.constraint="undefined"!=typeof a?a instanceof e?a:new c(a):!1,this.validate=function(a,c){var e,h=new b,i=0,j={},k=this.groups.length?this.groups:c;if(!g(a))throw new d(this,a,{value:b.errorCode.must_be_an_array});for(var l=0;l<a.length;l++)e=this.constraint?h.validate(a[l],this.constraint,k):h.validate(a[l],k),f(e)||(j[i]=e),i++;return f(j)?!0:j},this},Count:function(a){return this.__class__="Count",this.count=a,this.validate=function(a){if(!g(a))throw new d(this,a,{value:b.errorCode.must_be_an_array});var c="function"==typeof this.count?this.count(a):this.count;if(isNaN(Number(c)))throw new Error("Count must be a valid interger",c);if(c!==a.length)throw new d(this,a,{count:c});return!0},this},Email:function(){return this.__class__="Email",this.validate=function(a){var c=/^((([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;if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(!c.test(a))throw new d(this,a);return!0},this},EqualTo:function(a){if(this.__class__="EqualTo","undefined"==typeof a)throw new Error("EqualTo must be instanciated with a value or a function");return this.reference=a,this.validate=function(a){var b="function"==typeof this.reference?this.reference(a):this.reference;if(b!==a)throw new d(this,a,{value:b});return!0},this},GreaterThan:function(a){if(this.__class__="GreaterThan","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold>=a)throw new d(this,a,{threshold:this.threshold});return!0},this},GreaterThanOrEqual:function(a){if(this.__class__="GreaterThanOrEqual","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold>a)throw new d(this,a,{threshold:this.threshold});return!0},this},InstanceOf:function(a){if(this.__class__="InstanceOf","undefined"==typeof a)throw new Error("InstanceOf must be instanciated with a value");return this.classRef=a,this.validate=function(a){if(!0!=a instanceof this.classRef)throw new d(this,a,{classRef:this.classRef});return!0},this},Length:function(a){if(this.__class__="Length",!a.min&&!a.max)throw new Error("Lenth assert must be instanciated with a { min: x, max: y } object");return this.min=a.min,this.max=a.max,this.validate=function(a){if("string"!=typeof a&&!g(a))throw new d(this,a,{value:b.errorCode.must_be_a_string_or_array});if("undefined"!=typeof this.min&&this.min===this.max&&a.length!==this.min)throw new d(this,a,{min:this.min,max:this.max});if("undefined"!=typeof this.max&&a.length>this.max)throw new d(this,a,{max:this.max});if("undefined"!=typeof this.min&&a.length<this.min)throw new d(this,a,{min:this.min});return!0},this},LessThan:function(a){if(this.__class__="LessThan","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold<=a)throw new d(this,a,{threshold:this.threshold});return!0},this},LessThanOrEqual:function(a){if(this.__class__="LessThanOrEqual","undefined"==typeof a)throw new Error("Should give a threshold value");return this.threshold=a,this.validate=function(a){if(""===a||isNaN(Number(a)))throw new d(this,a,{value:b.errorCode.must_be_a_number});if(this.threshold<a)throw new d(this,a,{threshold:this.threshold});return!0},this},NotNull:function(){return this.__class__="NotNull",this.validate=function(a){if(null===a||"undefined"==typeof a)throw new d(this,a);return!0},this},NotBlank:function(){return this.__class__="NotBlank",this.validate=function(a){if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(""===a.replace(/^\s+/g,"").replace(/\s+$/g,""))throw new d(this,a);return!0},this},Null:function(){return this.__class__="Null",this.validate=function(a){if(null!==a)throw new d(this,a);return!0},this},Range:function(a,b){if(this.__class__="Range","undefined"==typeof a||"undefined"==typeof b)throw new Error("Range assert expects min and max values");return this.min=a,this.max=b,this.validate=function(a){try{return"string"==typeof a&&isNaN(Number(a))||g(a)?(new e).Length({min:this.min,max:this.max}).validate(a):(new e).GreaterThanOrEqual(this.min).validate(a)&&(new e).LessThanOrEqual(this.max).validate(a),!0}catch(b){throw new d(this,a,b.violation)}return!0},this},Regexp:function(a,c){if(this.__class__="Regexp","undefined"==typeof a)throw new Error("You must give a regexp");return this.regexp=a,this.flag=c||"",this.validate=function(a){if("string"!=typeof a)throw new d(this,a,{value:b.errorCode.must_be_a_string});if(!new RegExp(this.regexp,this.flag).test(a))throw new d(this,a,{regexp:this.regexp,flag:this.flag});return!0},this},Required:function(){return this.__class__="Required",this.validate=function(a){if("undefined"==typeof a)throw new d(this,a);try{"string"==typeof a?(new e).NotNull().validate(a)&&(new e).NotBlank().validate(a):!0===g(a)&&(new e).Length({min:1}).validate(a)}catch(b){throw new d(this,a)}return!0},this},Unique:function(a){return this.__class__="Unique","object"==typeof a&&(this.key=a.key),this.validate=function(a){var c,e=[];if(!g(a))throw new d(this,a,{value:b.errorCode.must_be_an_array});for(var f=0;f<a.length;f++)if(c="object"==typeof a[f]?a[f][this.key]:a[f],"undefined"!=typeof c){if(-1!==e.indexOf(c))throw new d(this,a,{value:c});e.push(c)}return!0},this}},a.Assert=e,a.Validator=b,a.Violation=d,a.Constraint=c,Array.prototype.indexOf||(Array.prototype.indexOf=function(a){"use strict";if(null===this)throw new TypeError;var b=Object(this),c=b.length>>>0;if(0===c)return-1;var d=0;if(arguments.length>1&&(d=Number(arguments[1]),d!=d?d=0:0!==d&&d!=1/0&&d!=-(1/0)&&(d=(d>0||-1)*Math.floor(Math.abs(d)))),d>=c)return-1;for(var e=d>=0?d:Math.max(c-Math.abs(d),0);c>e;e++)if(e in b&&b[e]===a)return e;return-1});var f=function(a){for(var b in a)return!1;return!0},g=function(a){return"[object Array]"===Object.prototype.toString.call(a)};return"function"==typeof define&&define.amd?define("vendors/validator.js/dist/validator",[],function(){return a}):"undefined"!=typeof module&&module.exports?module.exports=a:window["undefined"!=typeof validatorjs_ns?validatorjs_ns:"Validator"]=a,a}();i="undefined"!=typeof i?i:"undefined"!=typeof module?module.exports:null;var j=function(a,b){this.__class__="ParsleyValidator",this.Validator=i,this.locale="en",this.init(a||{},b||{})};j.prototype={init:function(b,c){this.catalog=c,this.validators=a.extend({},this.validators);for(var d in b)this.addValidator(d,b[d].fn,b[d].priority,b[d].requirementsTransformer);window.Parsley.trigger("parsley:validator:init")},setLocale:function(a){if("undefined"==typeof this.catalog[a])throw new Error(a+" is not available in the catalog");return this.locale=a,this},addCatalog:function(a,b,c){return"object"==typeof b&&(this.catalog[a]=b),!0===c?this.setLocale(a):this},addMessage:function(a,b,c){return"undefined"==typeof this.catalog[a]&&(this.catalog[a]={}),this.catalog[a][b.toLowerCase()]=c,this},validate:function(){return(new this.Validator.Validator).validate.apply(new i.Validator,arguments)},addValidator:function(a,b,c,d){if(this.validators[a])f.warn('Validator "'+a+'" is already defined.');else if(g.hasOwnProperty(a))return void f.warn('"'+a+'" is a restricted keyword and is not a valid validator name.');return this._setValidator(a,b,c,d)},updateValidator:function(a,b,c,d){return this.validators[a]?this._setValidator(a,b,c,d):(f.warn('Validator "'+a+'" is not already defined.'),this.addValidator(a,b,c,d))},removeValidator:function(a){return this.validators[a]||f.warn('Validator "'+a+'" is not defined.'),delete this.validators[a],this},_setValidator:function(b,c,d,e){return this.validators[b]=function(b){return a.extend((new i.Assert).Callback(c,b),{priority:d,requirementsTransformer:e})},this},getErrorMessage:function(a){var b;if("type"===a.name){var c=this.catalog[this.locale][a.name]||{};b=c[a.requirements]}else b=this.formatMessage(this.catalog[this.locale][a.name],a.requirements);return b||this.catalog[this.locale].defaultMessage||this.catalog.en.defaultMessage},formatMessage:function(a,b){if("object"==typeof b){for(var c in b)a=this.formatMessage(a,b[c]);return a}return"string"==typeof a?a.replace(new RegExp("%s","i"),b):""},validators:{notblank:function(){return a.extend((new i.Assert).NotBlank(),{priority:2})},required:function(){return a.extend((new i.Assert).Required(),{priority:512})},type:function(b){var c;switch(b){case"email":c=(new i.Assert).Email();break;case"range":case"number":c=(new i.Assert).Regexp("^-?(?:\\d+|\\d{1,3}(?:,\\d{3})+)?(?:\\.\\d+)?$");break;case"integer":c=(new i.Assert).Regexp("^-?\\d+$");break;case"digits":c=(new i.Assert).Regexp("^\\d+$");break;case"alphanum":c=(new i.Assert).Regexp("^\\w+$","i");break;case"url":c=(new i.Assert).Regexp("^(?:(?:https?|ftp)://)?(?:\\S+(?::\\S*)?@)?(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:/\\S*)?$","i");break;default:throw new Error("validator type `"+b+"` is not supported")}return a.extend(c,{priority:256})},pattern:function(b){var c="";return/^\/.*\/(?:[gimy]*)$/.test(b)&&(c=b.replace(/.*\/([gimy]*)$/,"$1"),b=b.replace(new RegExp("^/(.*?)/"+c+"$"),"$1")),a.extend((new i.Assert).Regexp(b,c),{priority:64})},minlength:function(b){return a.extend((new i.Assert).Length({min:b}),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},maxlength:function(b){return a.extend((new i.Assert).Length({max:b}),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},length:function(b){return a.extend((new i.Assert).Length({min:b[0],max:b[1]}),{priority:32})},mincheck:function(a){return this.minlength(a)},maxcheck:function(a){return this.maxlength(a)},check:function(a){return this.length(a)},min:function(b){return a.extend((new i.Assert).GreaterThanOrEqual(b),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},max:function(b){return a.extend((new i.Assert).LessThanOrEqual(b),{priority:30,requirementsTransformer:function(){return"string"!=typeof b||isNaN(b)?b:parseInt(b,10)}})},range:function(b){return a.extend((new i.Assert).Range(b[0],b[1]),{priority:32,requirementsTransformer:function(){for(var a=0;a<b.length;a++)b[a]="string"!=typeof b[a]||isNaN(b[a])?b[a]:parseInt(b[a],10);return b}})},equalto:function(b){return a.extend((new i.Assert).EqualTo(b),{priority:256,requirementsTransformer:function(){return a(b).length?a(b).val():b}})}}};var k=function(){this.__class__="ParsleyUI"};k.prototype={listen:function(){var a=this;return window.Parsley.on("form:init",function(){a.setupForm(this)}).on("field:init",function(){a.setupField(this)}).on("field:validated",function(){a.reflow(this)}).on("form:validated",function(){a.focus(this)}).on("field:reset",function(){a.reset(this)}).on("form:destroy",function(){a.destroy(this)}).on("field:destroy",function(){a.destroy(this)}),this},reflow:function(a){if("undefined"!=typeof a._ui&&!1!==a._ui.active){var b=this._diff(a.validationResult,a._ui.lastValidationResult);a._ui.lastValidationResult=a.validationResult,a._ui.validatedOnce=!0,this.manageStatusClass(a),this.manageErrorsMessages(a,b),this.actualizeTriggers(a),(b.kept.length||b.added.length)&&!0!==a._ui.failedOnce&&this.manageFailingFieldTrigger(a)}},getErrorsMessages:function(a){if(!0===a.validationResult)return[];for(var b=[],c=0;c<a.validationResult.length;c++)b.push(this._getErrorMessage(a,a.validationResult[c].assert));return b},manageStatusClass:function(a){a.hasConstraints()&&a.needsValidation()&&!0===a.validationResult?this._successClass(a):a.validationResult.length>0?this._errorClass(a):this._resetClass(a)},manageErrorsMessages:function(b,c){if("undefined"==typeof b.options.errorsMessagesDisabled){if("undefined"!=typeof b.options.errorMessage)return c.added.length||c.kept.length?(this._insertErrorWrapper(b),0===b._ui.$errorsWrapper.find(".parsley-custom-error-message").length&&b._ui.$errorsWrapper.append(a(b.options.errorTemplate).addClass("parsley-custom-error-message")),b._ui.$errorsWrapper.addClass("filled").find(".parsley-custom-error-message").html(b.options.errorMessage)):b._ui.$errorsWrapper.removeClass("filled").find(".parsley-custom-error-message").remove();for(var d=0;d<c.removed.length;d++)this.removeError(b,c.removed[d].assert.name,!0);for(d=0;d<c.added.length;d++)this.addError(b,c.added[d].assert.name,void 0,c.added[d].assert,!0);for(d=0;d<c.kept.length;d++)this.updateError(b,c.kept[d].assert.name,void 0,c.kept[d].assert,!0)}},addError:function(b,c,d,e,f){this._insertErrorWrapper(b),b._ui.$errorsWrapper.addClass("filled").append(a(b.options.errorTemplate).addClass("parsley-"+c).html(d||this._getErrorMessage(b,e))),!0!==f&&this._errorClass(b)},updateError:function(a,b,c,d,e){a._ui.$errorsWrapper.addClass("filled").find(".parsley-"+b).html(c||this._getErrorMessage(a,d)),!0!==e&&this._errorClass(a)},removeError:function(a,b,c){a._ui.$errorsWrapper.removeClass("filled").find(".parsley-"+b).remove(),!0!==c&&this.manageStatusClass(a)},focus:function(a){if(a._focusedField=null,!0===a.validationResult||"none"===a.options.focus)return null;for(var b=0;b<a.fields.length;b++){var c=a.fields[b];if(!0!==c.validationResult&&c.validationResult.length>0&&"undefined"==typeof c.options.noFocus&&(a._focusedField=c.$element,"first"===a.options.focus))break}return null===a._focusedField?null:a._focusedField.focus()},_getErrorMessage:function(a,b){var c=b.name+"Message";return"undefined"!=typeof a.options[c]?window.ParsleyValidator.formatMessage(a.options[c],b.requirements):window.ParsleyValidator.getErrorMessage(b)},_diff:function(a,b,c){for(var d=[],e=[],f=0;f<a.length;f++){for(var g=!1,h=0;h<b.length;h++)if(a[f].assert.name===b[h].assert.name){g=!0;break}g?e.push(a[f]):d.push(a[f])}return{kept:e,added:d,removed:c?[]:this._diff(b,a,!0).added}},setupForm:function(b){b.$element.on("submit.Parsley",!1,a.proxy(b.onSubmitValidate,b)),!1!==b.options.uiEnabled&&b.$element.attr("novalidate","")},setupField:function(b){var c={active:!1};!1!==b.options.uiEnabled&&(c.active=!0,b.$element.attr(b.options.namespace+"id",b.__id__),c.$errorClassHandler=this._manageClassHandler(b),c.errorsWrapperId="parsley-id-"+(b.options.multiple?"multiple-"+b.options.multiple:b.__id__),c.$errorsWrapper=a(b.options.errorsWrapper).attr("id",c.errorsWrapperId),c.lastValidationResult=[],c.validatedOnce=!1,c.validationInformationVisible=!1,b._ui=c,this.actualizeTriggers(b))},_manageClassHandler:function(b){if("string"==typeof b.options.classHandler&&a(b.options.classHandler).length)return a(b.options.classHandler);var c=b.options.classHandler(b);return"undefined"!=typeof c&&c.length?c:!b.options.multiple||b.$element.is("select")?b.$element:b.$element.parent()},_insertErrorWrapper:function(b){var c;if(0!==b._ui.$errorsWrapper.parent().length)return b._ui.$errorsWrapper.parent();if("string"==typeof b.options.errorsContainer){if(a(b.options.errorsContainer).length)return a(b.options.errorsContainer).append(b._ui.$errorsWrapper);f.warn("The errors container `"+b.options.errorsContainer+"` does not exist in DOM")}else"function"==typeof b.options.errorsContainer&&(c=b.options.errorsContainer(b));if("undefined"!=typeof c&&c.length)return c.append(b._ui.$errorsWrapper);var d=b.$element;return b.options.multiple&&(d=d.parent()),d.after(b._ui.$errorsWrapper)},actualizeTriggers:function(b){var c=b.$element;if(b.options.multiple&&(c=a("["+b.options.namespace+'multiple="'+b.options.multiple+'"]')),c.off(".Parsley"),!1!==b.options.trigger){var d=b.options.trigger.replace(/^\s+/g,"").replace(/\s+$/g,"");""!==d&&c.on(d.split(" ").join(".Parsley ")+".Parsley",a.proxy("function"==typeof b.eventValidate?b.eventValidate:this.eventValidate,b))}},eventValidate:function(a){new RegExp("key").test(a.type)&&!this._ui.validationInformationVisible&&this.getValue().length<=this.options.validationThreshold||(this._ui.validatedOnce=!0,this.validate())},manageFailingFieldTrigger:function(b){return b._ui.failedOnce=!0,b.options.multiple&&a("["+b.options.namespace+'multiple="'+b.options.multiple+'"]').each(function(){return new RegExp("change","i").test(a(this).parsley().options.trigger||"")?void 0:a(this).on("change.ParsleyFailedOnce",!1,a.proxy(b.validate,b))}),b.$element.is("select")&&!new RegExp("change","i").test(b.options.trigger||"")?b.$element.on("change.ParsleyFailedOnce",!1,a.proxy(b.validate,b)):new RegExp("keyup","i").test(b.options.trigger||"")?void 0:b.$element.on("keyup.ParsleyFailedOnce",!1,a.proxy(b.validate,b))},reset:function(a){this.actualizeTriggers(a),a.$element.off(".ParsleyFailedOnce"),"undefined"!=typeof a._ui&&"ParsleyForm"!==a.__class__&&(a._ui.$errorsWrapper.removeClass("filled").children().remove(),this._resetClass(a),a._ui.validatedOnce=!1,a._ui.lastValidationResult=[],a._ui.validationInformationVisible=!1,a._ui.failedOnce=!1)},destroy:function(a){this.reset(a),"ParsleyForm"!==a.__class__&&("undefined"!=typeof a._ui&&a._ui.$errorsWrapper.remove(),delete a._ui)},_successClass:function(a){a._ui.validationInformationVisible=!0,a._ui.$errorClassHandler.removeClass(a.options.errorClass).addClass(a.options.successClass)},_errorClass:function(a){a._ui.validationInformationVisible=!0,a._ui.$errorClassHandler.removeClass(a.options.successClass).addClass(a.options.errorClass)},_resetClass:function(a){a._ui.$errorClassHandler.removeClass(a.options.successClass).removeClass(a.options.errorClass)}};var l=function(b,c,d){this.__class__="ParsleyForm",this.__id__=f.generateID(),this.$element=a(b),this.domOptions=c,this.options=d,this.parent=window.Parsley,this.fields=[],this.validationResult=null};l.prototype={onSubmitValidate:function(b){return this.validate(void 0,void 0,b),(!1===this.validationResult||!this._trigger("submit"))&&b instanceof a.Event&&(b.stopImmediatePropagation(),b.preventDefault()),this},validate:function(a,b,c){this.submitEvent=c,this.validationResult=!0;var d=[];return this._trigger("validate"),this._refreshFields(),this._withoutReactualizingFormOptions(function(){for(var c=0;c<this.fields.length;c++)(!a||this._isFieldInGroup(this.fields[c],a))&&(d=this.fields[c].validate(b),!0!==d&&d.length>0&&this.validationResult&&(this.validationResult=!1))}),this._trigger(this.validationResult?"success":"error"),this._trigger("validated"),this.validationResult},isValid:function(a,b){return this._refreshFields(),this._withoutReactualizingFormOptions(function(){for(var c=0;c<this.fields.length;c++)if((!a||this._isFieldInGroup(this.fields[c],a))&&!1===this.fields[c].isValid(b))return!1;return!0})},_isFieldInGroup:function(b,c){return a.isArray(b.options.group)?-1!==a.inArray(c,b.options.group):b.options.group===c},_refreshFields:function(){return this.actualizeOptions()._bindFields()},_bindFields:function(){var b=this,c=this.fields;return this.fields=[],this.fieldsMappedById={},this._withoutReactualizingFormOptions(function(){this.$element.find(this.options.inputs).not(this.options.excluded).each(function(){var a=new t.Factory(this,{},b);"ParsleyField"!==a.__class__&&"ParsleyFieldMultiple"!==a.__class__||!0===a.options.excluded||"undefined"==typeof b.fieldsMappedById[a.__class__+"-"+a.__id__]&&(b.fieldsMappedById[a.__class__+"-"+a.__id__]=a,b.fields.push(a))}),a(c).not(b.fields).each(function(){this._trigger("reset")})}),this},_withoutReactualizingFormOptions:function(a){var b=this.actualizeOptions;this.actualizeOptions=function(){return this};var c=a.call(this);return this.actualizeOptions=b,c},_trigger:function(a){return a="form:"+a,this.trigger.apply(this,arguments)}};var m=function(b,c,d,e,g){var h={};if(!new RegExp("ParsleyField").test(b.__class__))throw new Error("ParsleyField or ParsleyFieldMultiple instance expected");if("function"==typeof window.ParsleyValidator.validators[c]&&(h=window.ParsleyValidator.validators[c](d)),"Assert"!==h.__parentClass__)throw new Error("Valid validator expected");var i=function(){return"undefined"!=typeof b.options[c+"Priority"]?b.options[c+"Priority"]:h.priority||2};return e=e||i(),"function"==typeof h.requirementsTransformer&&(d=h.requirementsTransformer(),h=window.ParsleyValidator.validators[c](d)),a.extend(h,{name:c,requirements:d,priority:e,groups:[e],isDomConstraint:g||f.checkAttr(b.$element,b.options.namespace,c)})},n=function(b,c,d,e){this.__class__="ParsleyField",this.__id__=f.generateID(),this.$element=a(b),"undefined"!=typeof e&&(this.parent=e),this.options=d,this.domOptions=c,this.constraints=[],this.constraintsByName={},this.validationResult=[],this._bindConstraints(); | ||
};n.prototype={validate:function(a){return this.value=this.getValue(),this._trigger("validate"),this._trigger(this.isValid(a,this.value)?"success":"error"),this._trigger("validated"),this.validationResult},hasConstraints:function(){return 0!==this.constraints.length},needsValidation:function(a){return"undefined"==typeof a&&(a=this.getValue()),a.length||this._isRequired()||"undefined"!=typeof this.options.validateIfEmpty?!0:!1},isValid:function(a,b){if(this.refreshConstraints(),this.validationResult=!0,!this.hasConstraints())return!0;if(("undefined"==typeof b||null===b)&&(b=this.getValue()),!this.needsValidation(b)&&!0!==a)return!0;var c=["Any"];!1!==this.options.priorityEnabled&&(c=this._getConstraintsSortedPriorities());for(var d=0;d<c.length;d++)if(!0!==(this.validationResult=this.validateThroughValidator(b,this.constraints,c[d])))return!1;return!0},getValue:function(){var a;return a="function"==typeof this.options.value?this.options.value(this):"undefined"!=typeof this.options.value?this.options.value:this.$element.val(),"undefined"==typeof a||null===a?"":!0===this.options.trimValue?a.replace(/^\s+|\s+$/g,""):a},refreshConstraints:function(){return this.actualizeOptions()._bindConstraints()},addConstraint:function(a,b,c,d){if("function"==typeof window.ParsleyValidator.validators[a]){var e=new m(this,a,b,c,d);"undefined"!==this.constraintsByName[e.name]&&this.removeConstraint(e.name),this.constraints.push(e),this.constraintsByName[e.name]=e}return this},removeConstraint:function(a){for(var b=0;b<this.constraints.length;b++)if(a===this.constraints[b].name){this.constraints.splice(b,1);break}return delete this.constraintsByName[a],this},updateConstraint:function(a,b,c){return this.removeConstraint(a).addConstraint(a,b,c)},_bindConstraints:function(){for(var a=[],b={},c=0;c<this.constraints.length;c++)!1===this.constraints[c].isDomConstraint&&(a.push(this.constraints[c]),b[this.constraints[c].name]=this.constraints[c]);this.constraints=a,this.constraintsByName=b;for(var d in this.options)this.addConstraint(d,this.options[d]);return this._bindHtml5Constraints()},_bindHtml5Constraints:function(){(this.$element.hasClass("required")||this.$element.attr("required"))&&this.addConstraint("required",!0,void 0,!0),"string"==typeof this.$element.attr("pattern")&&this.addConstraint("pattern",this.$element.attr("pattern"),void 0,!0),"undefined"!=typeof this.$element.attr("min")&&"undefined"!=typeof this.$element.attr("max")?this.addConstraint("range",[this.$element.attr("min"),this.$element.attr("max")],void 0,!0):"undefined"!=typeof this.$element.attr("min")?this.addConstraint("min",this.$element.attr("min"),void 0,!0):"undefined"!=typeof this.$element.attr("max")&&this.addConstraint("max",this.$element.attr("max"),void 0,!0),"undefined"!=typeof this.$element.attr("minlength")&&"undefined"!=typeof this.$element.attr("maxlength")?this.addConstraint("length",[this.$element.attr("minlength"),this.$element.attr("maxlength")],void 0,!0):"undefined"!=typeof this.$element.attr("minlength")?this.addConstraint("minlength",this.$element.attr("minlength"),void 0,!0):"undefined"!=typeof this.$element.attr("maxlength")&&this.addConstraint("maxlength",this.$element.attr("maxlength"),void 0,!0);var a=this.$element.attr("type");return"undefined"==typeof a?this:"number"===a?"undefined"==typeof this.$element.attr("step")||0===parseFloat(this.$element.attr("step"))%1?this.addConstraint("type","integer",void 0,!0):this.addConstraint("type","number",void 0,!0):/^(email|url|range)$/i.test(a)?this.addConstraint("type",a,void 0,!0):this},_isRequired:function(){return"undefined"==typeof this.constraintsByName.required?!1:!1!==this.constraintsByName.required.requirements},_trigger:function(a){return a="field:"+a,this.trigger.apply(this,arguments)},_getConstraintsSortedPriorities:function(){for(var a=[],b=0;b<this.constraints.length;b++)-1===a.indexOf(this.constraints[b].priority)&&a.push(this.constraints[b].priority);return a.sort(function(a,b){return b-a}),a}};var o=function(){this.__class__="ParsleyFieldMultiple"};o.prototype={addElement:function(a){return this.$elements.push(a),this},refreshConstraints:function(){var b;if(this.constraints=[],this.$element.is("select"))return this.actualizeOptions()._bindConstraints(),this;for(var c=0;c<this.$elements.length;c++)if(a("html").has(this.$elements[c]).length){b=this.$elements[c].data("ParsleyFieldMultiple").refreshConstraints().constraints;for(var d=0;d<b.length;d++)this.addConstraint(b[d].name,b[d].requirements,b[d].priority,b[d].isDomConstraint)}else this.$elements.splice(c,1);return this},getValue:function(){if("undefined"!=typeof this.options.value)return this.options.value;if(this.$element.is("input[type=radio]"))return this._findRelatedMultiple().filter(":checked").val()||"";if(this.$element.is("input[type=checkbox]")){var b=[];return this._findRelatedMultiple().filter(":checked").each(function(){b.push(a(this).val())}),b}return this.$element.is("select")&&null===this.$element.val()?[]:this.$element.val()},_init:function(){return this.$elements=[this.$element],this}};var p=function(b,c,d){this.$element=a(b);var e=this.$element.data("Parsley");if(e)return"undefined"!=typeof d&&e.parent===window.Parsley&&(e.parent=d,e._resetOptions(e.options)),e;if(!this.$element.length)throw new Error("You must bind Parsley on an existing element.");if("undefined"!=typeof d&&"ParsleyForm"!==d.__class__)throw new Error("Parent instance must be a ParsleyForm instance");return this.parent=d||window.Parsley,this.init(c)};p.prototype={init:function(a){return this.__class__="Parsley",this.__version__="2.1.2",this.__id__=f.generateID(),this._resetOptions(a),this.$element.is("form")||f.checkAttr(this.$element,this.options.namespace,"validate")&&!this.$element.is(this.options.inputs)?this.bind("parsleyForm"):this.isMultiple()?this.handleMultiple():this.bind("parsleyField")},isMultiple:function(){return this.$element.is("input[type=radio], input[type=checkbox]")||this.$element.is("select")&&"undefined"!=typeof this.$element.attr("multiple")},handleMultiple:function(){var b,c,d=this;if(this.options.multiple||("undefined"!=typeof this.$element.attr("name")&&this.$element.attr("name").length?this.options.multiple=b=this.$element.attr("name"):"undefined"!=typeof this.$element.attr("id")&&this.$element.attr("id").length&&(this.options.multiple=this.$element.attr("id"))),this.$element.is("select")&&"undefined"!=typeof this.$element.attr("multiple"))return this.options.multiple=this.options.multiple||this.__id__,this.bind("parsleyFieldMultiple");if(!this.options.multiple)return f.warn("To be bound by Parsley, a radio, a checkbox and a multiple select input must have either a name or a multiple option.",this.$element),this;this.options.multiple=this.options.multiple.replace(/(:|\.|\[|\]|\{|\}|\$)/g,""),"undefined"!=typeof b&&a('input[name="'+b+'"]').each(function(){a(this).is("input[type=radio], input[type=checkbox]")&&a(this).attr(d.options.namespace+"multiple",d.options.multiple)});for(var e=this._findRelatedMultiple(),g=0;g<e.length;g++)if(c=a(e.get(g)).data("Parsley"),"undefined"!=typeof c){this.$element.data("ParsleyFieldMultiple")||c.addElement(this.$element);break}return this.bind("parsleyField",!0),c||this.bind("parsleyFieldMultiple")},bind:function(b,c){var d;switch(b){case"parsleyForm":d=a.extend(new l(this.$element,this.domOptions,this.options),window.ParsleyExtend)._bindFields();break;case"parsleyField":d=a.extend(new n(this.$element,this.domOptions,this.options,this.parent),window.ParsleyExtend);break;case"parsleyFieldMultiple":d=a.extend(new n(this.$element,this.domOptions,this.options,this.parent),new o,window.ParsleyExtend)._init();break;default:throw new Error(b+"is not a supported Parsley type")}return this.options.multiple&&f.setAttr(this.$element,this.options.namespace,"multiple",this.options.multiple),"undefined"!=typeof c?(this.$element.data("ParsleyFieldMultiple",d),d):(this.$element.data("Parsley",d),d._trigger("init"),d)}};var q=a({}),r=function(){f.warnOnce("Parsley's pubsub module is deprecated; use the corresponding jQuery event method instead")},s="parsley:";a.listen=function(a,d){var e;if(r(),"object"==typeof arguments[1]&&"function"==typeof arguments[2]&&(e=arguments[1],d=arguments[2]),"function"!=typeof arguments[1])throw new Error("Wrong parameters");window.Parsley.on(c(a),b(d,e))},a.listenTo=function(a,d,e){if(r(),!(a instanceof n||a instanceof l))throw new Error("Must give Parsley instance");if("string"!=typeof d||"function"!=typeof e)throw new Error("Wrong parameters");a.on(c(d),b(e))},a.unsubscribe=function(a,b){if(r(),"string"!=typeof a||"function"!=typeof b)throw new Error("Wrong arguments");window.Parsley.off(c(a),b.parsleyAdaptedCallback)},a.unsubscribeTo=function(a,b){if(r(),!(a instanceof n||a instanceof l))throw new Error("Must give Parsley instance");a.off(c(b))},a.unsubscribeAll=function(b){r(),window.Parsley.off(c(b)),a("form,input,textarea,select").each(function(){var d=a(this).data("Parsley");d&&d.off(c(b))})},a.emit=function(a,b){r();var d=b instanceof n||b instanceof l,e=Array.prototype.slice.call(arguments,d?2:1);e.unshift(c(a)),d||(b=window.Parsley),b.trigger.apply(b,e)},window.ParsleyConfig=window.ParsleyConfig||{},window.ParsleyConfig.i18n=window.ParsleyConfig.i18n||{},window.ParsleyConfig.i18n.en=jQuery.extend(window.ParsleyConfig.i18n.en||{},{defaultMessage:"This value seems to be invalid.",type:{email:"This value should be a valid email.",url:"This value should be a valid url.",number:"This value should be a valid number.",integer:"This value should be a valid integer.",digits:"This value should be digits.",alphanum:"This value should be alphanumeric."},notblank:"This value should not be blank.",required:"This value is required.",pattern:"This value seems to be invalid.",min:"This value should be greater than or equal to %s.",max:"This value should be lower than or equal to %s.",range:"This value should be between %s and %s.",minlength:"This value is too short. It should have %s characters or more.",maxlength:"This value is too long. It should have %s characters or fewer.",length:"This value length is invalid. It should be between %s and %s characters long.",mincheck:"You must select at least %s choices.",maxcheck:"You must select %s choices or fewer.",check:"You must select between %s and %s choices.",equalto:"This value should be the same."}),"undefined"!=typeof window.ParsleyValidator&&window.ParsleyValidator.addCatalog("en",window.ParsleyConfig.i18n.en,!0);var t=a.extend(new h,{$element:a(document),actualizeOptions:null,_resetOptions:null,Factory:p,version:"2.1.2"});a.extend(n.prototype,h.prototype),a.extend(l.prototype,h.prototype),a.extend(p.prototype,h.prototype),a.fn.parsley=a.fn.psly=function(b){if(this.length>1){var c=[];return this.each(function(){c.push(a(this).parsley(b))}),c}return a(this).length?new p(this,b):void f.warn("You must bind Parsley on an existing element.")},"undefined"==typeof window.ParsleyExtend&&(window.ParsleyExtend={}),t.options=a.extend(f.objectCreate(g),window.ParsleyConfig),window.ParsleyConfig=t.options,window.Parsley=window.psly=t,window.ParsleyUtils=f,window.ParsleyValidator=new j(window.ParsleyConfig.validators,window.ParsleyConfig.i18n),window.ParsleyUI="function"==typeof window.ParsleyConfig.ParsleyUI?(new window.ParsleyConfig.ParsleyUI).listen():(new k).listen(),!1!==window.ParsleyConfig.autoBind&&a(function(){a("[data-parsley-validate]").length&&a("[data-parsley-validate]").parsley()})}); |
@@ -26,3 +26,3 @@ module.exports = function (grunt) { | ||
options: { | ||
sync: ['author', 'name', 'version', 'license', 'main', 'keywords'], | ||
sync: ['author', 'name', 'license', 'main', 'keywords'], | ||
from: 'package.json', | ||
@@ -185,6 +185,7 @@ to: 'bower.json' | ||
grunt.registerTask('configure', ['bower:install']); | ||
grunt.registerTask('build', ['requirejs', 'replace:dist', 'uglify:min']); | ||
grunt.registerTask('build-std', ['requirejs', 'replace:dist', 'uglify:min']); | ||
grunt.registerTask('build-remote', ['concat:remote', 'uglify:remote']); | ||
grunt.registerTask('build-annotated-source', ['docco:source', 'replace:annotated']); | ||
grunt.registerTask('build-all', ['configure', 'clean:dist', 'build', 'build-remote', 'build-annotated-source', 'sync']); | ||
grunt.registerTask('build', ['configure', 'clean:dist', 'build-std', 'build-remote', 'build-annotated-source', 'sync']); | ||
grunt.registerTask('build-all', ['build']); | ||
}; | ||
@@ -195,11 +196,2 @@ | ||
function convert(name, path, contents) { | ||
// Convert ParsleyDefaults and ParsleyUtils that needs a special treatment | ||
if (/(defaults|utils)/.test(path)) { | ||
name = (/parsley\/([\w-]+)/.exec(name)[1]); | ||
return contents | ||
.replace(/define\([\w\W]*?return/, " var Parsley" + name.charAt(0).toUpperCase() + name.slice(1) + " =") | ||
.replace(rdefineEnd, ""); | ||
} | ||
// Update original validatorjs for non-AMD implementation | ||
@@ -206,0 +198,0 @@ if (/(dist\/validator.js)/.test(path)) { |
{ | ||
"name": "parsleyjs", | ||
"version": "2.0.7", | ||
"version": "2.1.2", | ||
"homepage": "http://parsleyjs.org", | ||
@@ -33,3 +33,3 @@ "license": "MIT", | ||
"grunt-contrib-clean": "~0.5.0", | ||
"grunt-contrib-uglify": "~0.2.7", | ||
"grunt-contrib-uglify": "~0.8.0", | ||
"grunt-docco": "~0.3.2", | ||
@@ -42,3 +42,5 @@ "grunt-contrib-watch": "~0.5.3", | ||
"test": "mocha-phantomjs test/index.html", | ||
"test-all": "mocha-phantomjs test/index.html && mocha-phantomjs test/env/amd.html && mocha-phantomjs test/env/browserify.html" | ||
"test-all": "mocha-phantomjs test/index.html && mocha-phantomjs test/env/amd.html && mocha-phantomjs test/env/browserify.html", | ||
"test-amd": "mocha-phantomjs test/env/amd.html", | ||
"test-browserify": "mocha-phantomjs test/env/browserify.html" | ||
}, | ||
@@ -45,0 +47,0 @@ "spm": { |
@@ -9,3 +9,3 @@ # Parsley | ||
2.0.7 | ||
2.1.2 | ||
@@ -22,3 +22,3 @@ ## Doc | ||
See `CONTRIBUTING.md` file | ||
See the [`CONTRIBUTING.md` file](https://github.com/guillaumepotier/Parsley.js/blob/master/CONTRIBUTING.md) | ||
@@ -34,2 +34,3 @@ ## Integrations | ||
* [OSSCDN by MaxCDN](http://osscdn.com/#/parsleyjs) | ||
* [Drupal] (https://www.drupal.org/project/parsley) | ||
@@ -36,0 +37,0 @@ ## Install dev environment |
@@ -14,3 +14,3 @@ requirejs.config({ | ||
'*': { | ||
jquery: 'vendors/jquery/jquery', | ||
jquery: 'vendors/jquery/dist/jquery', | ||
validator: 'vendors/validator.js/dist/validator' | ||
@@ -21,3 +21,3 @@ } | ||
shim: { | ||
'vendors/jquery/jquery': { | ||
'vendors/jquery/dist/jquery': { | ||
exports: '$' | ||
@@ -24,0 +24,0 @@ }, |
// This plugin replace Parsley default form behavior that auto bind its fields children | ||
// With this plugin you must register in constructor your form's fields and their constraints | ||
// You have this way a total javascript control over your form validation, and nothing needed in DOM | ||
(function($){ | ||
window.ParsleyConfig = $.extend(true, window.ParsleyConfig, { autoBind: false }); | ||
@@ -44,1 +46,3 @@ window.ParsleyExtend = window.ParsleyExtend || {}; | ||
}); | ||
})(jQuery); |
@@ -7,7 +7,9 @@ // `window.ParsleyExtend`, like `ParsleyAbstract`, is inherited by `ParsleyField` and `ParsleyForm` | ||
// Because returns promises instead of booleans. | ||
(function($){ | ||
window.ParsleyExtend = window.ParsleyExtend || {}; | ||
window.ParsleyExtend = $.extend(window.ParsleyExtend, { | ||
window.ParsleyExtend = $.extend(true, window.ParsleyExtend, { | ||
asyncSupport: true, | ||
asyncValidators: $.extend({ | ||
asyncValidators: { | ||
'default': { | ||
@@ -26,3 +28,3 @@ fn: function (xhr) { | ||
} | ||
}, window.ParsleyExtend.asyncValidators), | ||
}, | ||
@@ -72,3 +74,3 @@ addAsyncValidator: function (name, fn, url, options) { | ||
// If user do not have prevented the event, re-submit form | ||
if (!that.submitEvent.isDefaultPrevented()) | ||
if (that._trigger('submit') && !that.submitEvent.isDefaultPrevented()) | ||
that.$element.trigger($.extend($.Event('submit'), { parsley: true })); | ||
@@ -83,3 +85,3 @@ }); | ||
if (new RegExp('key').test(event.type)) | ||
if (!this._ui.validationInformationVisible && this.getValue().length <= this.options.validationThreshold) | ||
if (!this._ui.validationInformationVisible && this.getValue().length <= this.options.validationThreshold) | ||
return; | ||
@@ -99,3 +101,3 @@ | ||
$.emit('parsley:form:validate', this); | ||
this._trigger('validate'); | ||
@@ -113,9 +115,9 @@ for (var i = 0; i < this.fields.length; i++) { | ||
.done(function () { | ||
$.emit('parsley:form:success', that); | ||
that._trigger('success'); | ||
}) | ||
.fail(function () { | ||
$.emit('parsley:form:error', that); | ||
that._trigger('error'); | ||
}) | ||
.always(function () { | ||
$.emit('parsley:form:validated', that); | ||
that._trigger('validated'); | ||
}); | ||
@@ -143,13 +145,13 @@ }, | ||
$.emit('parsley:field:validate', this); | ||
this._trigger('validate'); | ||
return this._asyncIsValidField(force) | ||
.done(function () { | ||
$.emit('parsley:field:success', that); | ||
that._trigger('success'); | ||
}) | ||
.fail(function () { | ||
$.emit('parsley:field:error', that); | ||
that._trigger('error'); | ||
}) | ||
.always(function () { | ||
$.emit('parsley:field:validated', that); | ||
that._trigger('validated'); | ||
}); | ||
@@ -220,3 +222,3 @@ }, | ||
// Make ajax call | ||
this._xhr = $.ajax(ajaxOptions) | ||
this._xhr = $.ajax(ajaxOptions); | ||
@@ -272,1 +274,7 @@ // Store remote call result to avoid next calls with exact same parameters | ||
}; | ||
window.Parsley.on('form:submit', function () { | ||
this._remoteCache = {}; | ||
}); | ||
})(jQuery); |
@@ -9,3 +9,3 @@ (function () { | ||
// gt, gte, lt, lte extra validators | ||
// gt, gte, lt, lte, notequalto extra validators | ||
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
@@ -45,2 +45,10 @@ window.ParsleyConfig.validators = window.ParsleyConfig.validators || {}; | ||
}; | ||
// Not equal to validator | ||
window.ParsleyConfig.validators.lte = { | ||
fn: function (value, requirement) { | ||
return parseFloat(value) <= parseRequirement(requirement); | ||
}, | ||
priority: 32 | ||
}; | ||
})(); |
@@ -6,3 +6,3 @@ // luhn extra validators | ||
window.ParsleyConfig.validators.luhn = { | ||
fn: function(value) { | ||
fn: function (value) { | ||
value = value.replace(/[ -]/g, ''); | ||
@@ -9,0 +9,0 @@ var digit, n, sum, _j, _len1, _ref2; |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.ar = $.extend(window.ParsleyConfig.i18n.ar || {}, { | ||
window.ParsleyConfig.i18n.ar = jQuery.extend(window.ParsleyConfig.i18n.ar || {}, { | ||
defaultMessage: "تأكد من صحة القيمة المدخل", | ||
@@ -9,0 +9,0 @@ type: { |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.bg = $.extend(window.ParsleyConfig.i18n.bg || {}, { | ||
window.ParsleyConfig.i18n.bg = jQuery.extend(window.ParsleyConfig.i18n.bg || {}, { | ||
defaultMessage: "Невалидна стойност.", | ||
@@ -9,0 +9,0 @@ type: { |
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
window.ParsleyConfig.i18n = window.ParsleyConfig.i18n || {}; | ||
window.ParsleyConfig.i18n.cs = $.extend(window.ParsleyConfig.i18n.cs || {}, { | ||
window.ParsleyConfig.i18n.cs = jQuery.extend(window.ParsleyConfig.i18n.cs || {}, { | ||
dateiso: "Tato položka musí být datum ve formátu RRRR-MM-DD.", | ||
@@ -6,0 +6,0 @@ minwords: "Tato položka musí mít délku nejméně %s slov.", |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.cs = $.extend(window.ParsleyConfig.i18n.cs || {}, { | ||
window.ParsleyConfig.i18n.cs = jQuery.extend(window.ParsleyConfig.i18n.cs || {}, { | ||
defaultMessage: "Tato položka je neplatná.", | ||
@@ -20,4 +20,4 @@ type: { | ||
pattern: "Tato položka je neplatná.", | ||
min: "Tato položka musí být menší nebo rovna %s.", | ||
max: "Tato položka musí být větší nebo rovna %s.", | ||
min: "Tato položka musí být větší nebo rovna %s.", | ||
max: "Tato položka musí být menší nebo rovna %s.", | ||
range: "Tato položka musí být v rozsahu od %s do %s.", | ||
@@ -24,0 +24,0 @@ minlength: "Tato položka musí mít nejméně %s znaků.", |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.da = $.extend(window.ParsleyConfig.i18n.da || {}, { | ||
window.ParsleyConfig.i18n.da = jQuery.extend(window.ParsleyConfig.i18n.da || {}, { | ||
defaultMessage: "Indtast venligst en korrekt værdi.", | ||
@@ -35,2 +35,1 @@ type: { | ||
window.ParsleyValidator.addCatalog('da', window.ParsleyConfig.i18n.da, true); | ||
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
window.ParsleyConfig.i18n = window.ParsleyConfig.i18n || {}; | ||
window.ParsleyConfig.i18n.de = $.extend(window.ParsleyConfig.i18n.de || {}, { | ||
window.ParsleyConfig.i18n.de = jQuery.extend(window.ParsleyConfig.i18n.de || {}, { | ||
dateiso: "Die Eingabe muss ein gültiges Datum sein (YYYY-MM-DD).", | ||
@@ -6,0 +6,0 @@ minwords: "Die Eingabe ist zu kurz. Sie muss aus %s oder mehr Wörtern bestehen.", |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.de = $.extend(window.ParsleyConfig.i18n.de || {}, { | ||
window.ParsleyConfig.i18n.de = jQuery.extend(window.ParsleyConfig.i18n.de || {}, { | ||
defaultMessage: "Die Eingabe scheint nicht korrekt zu sein.", | ||
@@ -26,2 +26,5 @@ type: { | ||
length: "Die Länge der Eingabe ist ungültig. Es müssen zwischen %s und %s Zeichen eingegeben werden.", | ||
mincheck: "Wählen Sie mindestens %s Angaben aus.", | ||
maxcheck: "Wählen Sie maximal %s Angaben aus.", | ||
check: "Wählen Sie zwischen %s und %s Angaben.", | ||
equalto: "Dieses Feld muss dem anderen entsprechen." | ||
@@ -28,0 +31,0 @@ }); |
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
window.ParsleyConfig.i18n = window.ParsleyConfig.i18n || {}; | ||
window.ParsleyConfig.i18n.en = $.extend(window.ParsleyConfig.i18n.en || {}, { | ||
window.ParsleyConfig.i18n.en = jQuery.extend(window.ParsleyConfig.i18n.en || {}, { | ||
dateiso: "This value should be a valid date (YYYY-MM-DD).", | ||
@@ -12,3 +12,4 @@ minwords: "This value is too short. It should have %s words or more.", | ||
lt: "This value should be less.", | ||
lte: "This value should be less or equal." | ||
lte: "This value should be less or equal.", | ||
notequalto: "This value should be different." | ||
}); |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.en = $.extend(window.ParsleyConfig.i18n.en || {}, { | ||
window.ParsleyConfig.i18n.en = jQuery.extend(window.ParsleyConfig.i18n.en || {}, { | ||
defaultMessage: "This value seems to be invalid.", | ||
@@ -9,0 +9,0 @@ type: { |
@@ -5,3 +5,3 @@ // ParsleyConfig definition if not already set | ||
window.ParsleyConfig.i18n.es = $.extend(window.ParsleyConfig.i18n.es || {}, { | ||
window.ParsleyConfig.i18n.es = jQuery.extend(window.ParsleyConfig.i18n.es || {}, { | ||
defaultMessage: "Este valor parece ser inválido.", | ||
@@ -8,0 +8,0 @@ type: { |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.fa = $.extend(window.ParsleyConfig.i18n.fa || {}, { | ||
window.ParsleyConfig.i18n.fa = jQuery.extend(window.ParsleyConfig.i18n.fa || {}, { | ||
defaultMessage: "این مقدار صحیح نمی باشد", | ||
@@ -9,0 +9,0 @@ type: { |
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
window.ParsleyConfig.i18n = window.ParsleyConfig.i18n || {}; | ||
window.ParsleyConfig.i18n.fi = $.extend(window.ParsleyConfig.i18n.fi || {}, { | ||
window.ParsleyConfig.i18n.fi = jQuery.extend(window.ParsleyConfig.i18n.fi || {}, { | ||
dateiso: "Syötä oikea päivämäärä (YYYY-MM-DD)." | ||
}); |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.fi = $.extend(window.ParsleyConfig.i18n.fi || {}, { | ||
window.ParsleyConfig.i18n.fi = jQuery.extend(window.ParsleyConfig.i18n.fi || {}, { | ||
defaultMessage: "Syötetty arvo on virheellinen.", | ||
@@ -20,3 +20,3 @@ type: { | ||
pattern: "Syötetty arvo on virheellinen.", | ||
min: "Syötä arvo joka on yhtä suuri tai suurempi kuin %s.", | ||
min: "Syötä arvo joka on yhtä suuri tai suurempi kuin %s.", | ||
max: "Syötä arvo joka on pienempi tai yhtä suuri kuin %s.", | ||
@@ -23,0 +23,0 @@ range: "Syötä arvo väliltä: %s-%s.", |
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
window.ParsleyConfig.i18n = window.ParsleyConfig.i18n || {}; | ||
window.ParsleyConfig.i18n.fr = $.extend(window.ParsleyConfig.i18n.fr || {}, { | ||
dateiso: "Cette valeur n'est pas une date valide (YYYY-MM-DD)." | ||
window.ParsleyConfig.i18n.fr = jQuery.extend(window.ParsleyConfig.i18n.fr || {}, { | ||
dateiso: "Cette valeur n'est pas une date valide (YYYY-MM-DD).", | ||
notequalto: "Cette valeur doit être différente." | ||
}); |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.fr = $.extend(window.ParsleyConfig.i18n.fr || {}, { | ||
window.ParsleyConfig.i18n.fr = jQuery.extend(window.ParsleyConfig.i18n.fr || {}, { | ||
defaultMessage: "Cette valeur semble non valide.", | ||
@@ -9,0 +9,0 @@ type: { |
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
window.ParsleyConfig.i18n = window.ParsleyConfig.i18n || {}; | ||
window.ParsleyConfig.i18n.he = $.extend(window.ParsleyConfig.i18n.he || {}, { | ||
window.ParsleyConfig.i18n.he = jQuery.extend(window.ParsleyConfig.i18n.he || {}, { | ||
dateiso: "ערך זה צריך להיות תאריך בפורמט (YYYY-MM-DD)." | ||
}); |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.he = $.extend(window.ParsleyConfig.i18n.he || {}, { | ||
window.ParsleyConfig.i18n.he = jQuery.extend(window.ParsleyConfig.i18n.he || {}, { | ||
defaultMessage: "נראה כי ערך זה אינו תקף.", | ||
@@ -9,0 +9,0 @@ type: { |
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
window.ParsleyConfig.i18n = window.ParsleyConfig.i18n || {}; | ||
window.ParsleyConfig.i18n.id = $.extend(window.ParsleyConfig.i18n.id || {}, { | ||
window.ParsleyConfig.i18n.id = jQuery.extend(window.ParsleyConfig.i18n.id || {}, { | ||
dateiso: "Harus tanggal yang valid (YYYY-MM-DD)." | ||
}); |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.id = $.extend(window.ParsleyConfig.i18n.id || {}, { | ||
window.ParsleyConfig.i18n.id = jQuery.extend(window.ParsleyConfig.i18n.id || {}, { | ||
defaultMessage: "tidak valid", | ||
@@ -9,0 +9,0 @@ type: { |
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
window.ParsleyConfig.i18n = window.ParsleyConfig.i18n || {}; | ||
window.ParsleyConfig.i18n.it = $.extend(window.ParsleyConfig.i18n.it || {}, { | ||
window.ParsleyConfig.i18n.it = jQuery.extend(window.ParsleyConfig.i18n.it || {}, { | ||
dateiso: "Inserire una data valida (AAAA-MM-GG)." | ||
}); |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.it = $.extend(window.ParsleyConfig.i18n.it || {}, { | ||
window.ParsleyConfig.i18n.it = jQuery.extend(window.ParsleyConfig.i18n.it || {}, { | ||
defaultMessage: "Questo valore sembra essere non valido.", | ||
@@ -9,0 +9,0 @@ type: { |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.ja = $.extend(window.ParsleyConfig.i18n.ja || {}, { | ||
window.ParsleyConfig.i18n.ja = jQuery.extend(window.ParsleyConfig.i18n.ja || {}, { | ||
defaultMessage: "無効な値です。", | ||
@@ -9,0 +9,0 @@ type: { |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.ko = $.extend(window.ParsleyConfig.i18n.ko || {}, { | ||
window.ParsleyConfig.i18n.ko = jQuery.extend(window.ParsleyConfig.i18n.ko || {}, { | ||
defaultMessage: "입력하신 내용이 올바르지 않습니다.", | ||
@@ -9,0 +9,0 @@ type: { |
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
window.ParsleyConfig.i18n = window.ParsleyConfig.i18n || {}; | ||
window.ParsleyConfig.i18n.ms_MY = $.extend(window.ParsleyConfig.i18n.ms_MY || {}, { | ||
window.ParsleyConfig.i18n.ms_MY = jQuery.extend(window.ParsleyConfig.i18n.ms_MY || {}, { | ||
dateiso: "Nilai hendaklah berbentuk tarikh yang sah (YYYY-MM-DD).", | ||
minwords: "Ayat terlalu pendek. Ianya perlu sekurang-kurangnya %s patah perkataan.", | ||
maxwords: "Ayat terlalu panjang. Ianya tidak boleh melebihi %s patah perkataan.", | ||
words: "Panjang ayat tidak sah. Jumlah perkataan adalah diantara %s hingga %s patah perkataan.", | ||
words: "Panjang ayat tidak sah. Jumlah perkataan adalah diantara %s hingga %s patah perkataan.", | ||
gt: "Nilai lebih besar diperlukan.", | ||
@@ -10,0 +10,0 @@ gte: "Nilai hendaklah lebih besar atau sama.", |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.ms_MY = $.extend(window.ParsleyConfig.i18n.ms_MY || {}, { | ||
window.ParsleyConfig.i18n.ms_MY = jQuery.extend(window.ParsleyConfig.i18n.ms_MY || {}, { | ||
defaultMessage: "Nilai tidak sah.", | ||
@@ -9,0 +9,0 @@ type: { |
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
window.ParsleyConfig.i18n = window.ParsleyConfig.i18n || {}; | ||
window.ParsleyConfig.i18n.nl = $.extend(window.ParsleyConfig.i18n.nl || {}, { | ||
window.ParsleyConfig.i18n.nl = jQuery.extend(window.ParsleyConfig.i18n.nl || {}, { | ||
dateiso: "Deze waarde moet een datum in het volgende formaat zijn: (YYYY-MM-DD).", | ||
@@ -6,0 +6,0 @@ minwords: "Deze waarde moet minstens %s woorden bevatten.", |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.nl = $.extend(window.ParsleyConfig.i18n.nl || {}, { | ||
window.ParsleyConfig.i18n.nl = jQuery.extend(window.ParsleyConfig.i18n.nl || {}, { | ||
defaultMessage: "Deze waarde lijkt onjuist.", | ||
@@ -9,0 +9,0 @@ type: { |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.pl = $.extend(window.ParsleyConfig.i18n.pl || {}, { | ||
window.ParsleyConfig.i18n.pl = jQuery.extend(window.ParsleyConfig.i18n.pl || {}, { | ||
defaultMessage: "Wartość wygląda na nieprawidłową", | ||
@@ -9,0 +9,0 @@ type: { |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n['pt-br'] = $.extend(window.ParsleyConfig.i18n['pt-br'] || {}, { | ||
window.ParsleyConfig.i18n['pt-br'] = jQuery.extend(window.ParsleyConfig.i18n['pt-br'] || {}, { | ||
defaultMessage: "Este valor parece ser inválido.", | ||
@@ -9,0 +9,0 @@ type: { |
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
window.ParsleyConfig.i18n = window.ParsleyConfig.i18n || {}; | ||
window.ParsleyConfig.i18n.ru = $.extend(window.ParsleyConfig.i18n.ru || {}, { | ||
window.ParsleyConfig.i18n.ru = jQuery.extend(window.ParsleyConfig.i18n.ru || {}, { | ||
dateiso: "Это значение должно быть корректной датой (ГГГГ-ММ-ДД).", | ||
@@ -6,0 +6,0 @@ minwords: "Это значение должно содержать не менее %s слов.", |
@@ -11,3 +11,3 @@ //Parsley localization for Russian language | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.ru = $.extend(window.ParsleyConfig.i18n.ru || {}, { | ||
window.ParsleyConfig.i18n.ru = jQuery.extend(window.ParsleyConfig.i18n.ru || {}, { | ||
defaultMessage: "Некорректное значение.", | ||
@@ -14,0 +14,0 @@ type: { |
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
window.ParsleyConfig.i18n = window.ParsleyConfig.i18n || {}; | ||
window.ParsleyConfig.i18n.sv = $.extend(window.ParsleyConfig.i18n.sv || {}, { | ||
window.ParsleyConfig.i18n.sv = jQuery.extend(window.ParsleyConfig.i18n.sv || {}, { | ||
dateiso: "Ange ett giltigt datum (ÅÅÅÅ-MM-DD)." | ||
}); |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.sv = $.extend(window.ParsleyConfig.i18n.sv || {}, { | ||
window.ParsleyConfig.i18n.sv = jQuery.extend(window.ParsleyConfig.i18n.sv || {}, { | ||
defaultMessage: "Ogiltigt värde.", | ||
@@ -9,0 +9,0 @@ type: { |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.th = $.extend(window.ParsleyConfig.i18n.th || {}, { | ||
window.ParsleyConfig.i18n.th = jQuery.extend(window.ParsleyConfig.i18n.th || {}, { | ||
defaultMessage: "ค่านี้ดูเหมือนว่าจะไม่ถูกต้อง", | ||
@@ -9,0 +9,0 @@ type: { |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.tr = $.extend(window.ParsleyConfig.i18n.tr || {}, { | ||
window.ParsleyConfig.i18n.tr = jQuery.extend(window.ParsleyConfig.i18n.tr || {}, { | ||
defaultMessage: "Bu değer geçerli değil.", | ||
@@ -9,0 +9,0 @@ type: { |
window.ParsleyConfig = window.ParsleyConfig || {}; | ||
window.ParsleyConfig.i18n = window.ParsleyConfig.i18n || {}; | ||
window.ParsleyConfig.i18n.zh_cn = $.extend(window.ParsleyConfig.i18n.zh_cn || {}, { | ||
window.ParsleyConfig.i18n.zh_cn = jQuery.extend(window.ParsleyConfig.i18n.zh_cn || {}, { | ||
dateiso: "请输入正确格式的日期 (YYYY-MM-DD)." | ||
}); |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.zh_cn = $.extend(window.ParsleyConfig.i18n.zh_cn || {}, { | ||
window.ParsleyConfig.i18n.zh_cn = jQuery.extend(window.ParsleyConfig.i18n.zh_cn || {}, { | ||
defaultMessage: "不正确的值", | ||
@@ -9,0 +9,0 @@ type: { |
@@ -6,3 +6,3 @@ // ParsleyConfig definition if not already set | ||
// Define then the messages | ||
window.ParsleyConfig.i18n.zh_tw = $.extend(window.ParsleyConfig.i18n.zh_tw || {}, { | ||
window.ParsleyConfig.i18n.zh_tw = jQuery.extend(window.ParsleyConfig.i18n.zh_tw || {}, { | ||
defaultMessage: "這個值似乎是無效的。", | ||
@@ -9,0 +9,0 @@ type: { |
// Parsley.js @@version | ||
// http://parsleyjs.org | ||
// (c) 20012-2014 Guillaume Potier, Wisembly | ||
// (c) 2012-2015 Guillaume Potier, Wisembly | ||
// Parsley may be freely distributed under the MIT license. | ||
@@ -18,12 +18,12 @@ | ||
'parsley/validator', | ||
// `ParsleyUI` static class. Handle all UI and UX | ||
// `ParsleyUI` static class. Handles all UI and UX | ||
'parsley/ui', | ||
// Handle default javascript config and DOM-API config | ||
'parsley/factory/options', | ||
// `ParsleyForm` Class. Handle form validation | ||
// `ParsleyForm` Class. Handles form validation | ||
'parsley/form', | ||
// `ParsleyField` Class. Handle field validation | ||
// `ParsleyField` Class. Handles field validation | ||
'parsley/field', | ||
// `Multiple` Class. Extend `ParsleyField` to generate `ParsleyFieldMultiple` | ||
'parsley/multiple', | ||
// Factory to create Parsley instances (Form, Field or FieldMultiple) | ||
'parsley/factory', | ||
// Tiny Parsley Pub / Sub mechanism, used for `ParsleyUI` and Listeners | ||
@@ -33,188 +33,20 @@ 'parsley/pubsub', | ||
'i18n/en' | ||
], function (ParsleyUtils, ParsleyDefaults, ParsleyAbstract, ParsleyValidator, ParsleyUI, ParsleyOptionsFactory, ParsleyForm, ParsleyField, ParsleyMultiple) { | ||
// ### Parsley factory | ||
var Parsley = function (element, options, parsleyFormInstance) { | ||
this.__class__ = 'Parsley'; | ||
this.__version__ = '@@version'; | ||
this.__id__ = ParsleyUtils.hash(4); | ||
], function (ParsleyUtils, ParsleyDefaults, ParsleyAbstract, ParsleyValidator, ParsleyUI, ParsleyForm, ParsleyField, ParsleyMultiple, ParsleyFactory) { | ||
// Parsley must be instantiated with a DOM element or jQuery $element | ||
if ('undefined' === typeof element) | ||
throw new Error('You must give an element'); | ||
// Inherit `on`, `off` & `trigger` to Parsley: | ||
var Parsley = $.extend(new ParsleyAbstract(), { | ||
$element: $(document), | ||
actualizeOptions: null, | ||
_resetOptions: null, | ||
Factory: ParsleyFactory, | ||
version: '@@version' | ||
}); | ||
if ('undefined' !== typeof parsleyFormInstance && 'ParsleyForm' !== parsleyFormInstance.__class__) | ||
throw new Error('Parent instance must be a ParsleyForm instance'); | ||
// Supplement ParsleyField and Form with ParsleyAbstract | ||
// This way, the constructors will have access to those methods | ||
$.extend(ParsleyField.prototype, ParsleyAbstract.prototype); | ||
$.extend(ParsleyForm.prototype, ParsleyAbstract.prototype); | ||
// Inherit actualizeOptions and _resetOptions: | ||
$.extend(ParsleyFactory.prototype, ParsleyAbstract.prototype); | ||
return this.init($(element), options, parsleyFormInstance); | ||
}; | ||
Parsley.prototype = { | ||
init: function ($element, options, parsleyFormInstance) { | ||
if (!$element.length) | ||
throw new Error('You must bind Parsley on an existing element.'); | ||
this.$element = $element; | ||
// If element have already been binded, returns its saved Parsley instance | ||
if (this.$element.data('Parsley')) { | ||
var savedparsleyFormInstance = this.$element.data('Parsley'); | ||
// If saved instance have been binded without a ParsleyForm parent and there is one given in this call, add it | ||
if ('undefined' !== typeof parsleyFormInstance) | ||
savedparsleyFormInstance.parent = parsleyFormInstance; | ||
return savedparsleyFormInstance; | ||
} | ||
// Handle 'static' options | ||
this.OptionsFactory = new ParsleyOptionsFactory(ParsleyDefaults, ParsleyUtils.get(window, 'ParsleyConfig') || {}, options, this.getNamespace(options)); | ||
this.options = this.OptionsFactory.get(this); | ||
// A ParsleyForm instance is obviously a `<form>` elem but also every node that is not an input and have `data-parsley-validate` attribute | ||
if (this.$element.is('form') || (ParsleyUtils.attr(this.$element, this.options.namespace, 'validate') && !this.$element.is(this.options.inputs))) | ||
return this.bind('parsleyForm'); | ||
// Every other supported element and not excluded element is binded as a `ParsleyField` or `ParsleyFieldMultiple` | ||
else if (this.$element.is(this.options.inputs) && !this.$element.is(this.options.excluded)) | ||
return this.isMultiple() ? this.handleMultiple(parsleyFormInstance) : this.bind('parsleyField', parsleyFormInstance); | ||
return this; | ||
}, | ||
isMultiple: function () { | ||
return (this.$element.is('input[type=radio], input[type=checkbox]') && 'undefined' === typeof this.options.multiple) || (this.$element.is('select') && 'undefined' !== typeof this.$element.attr('multiple')); | ||
}, | ||
// Multiples fields are a real nightmare :( | ||
// Maybe some refacto would be appreciated here... | ||
handleMultiple: function (parsleyFormInstance) { | ||
var | ||
that = this, | ||
name, | ||
multiple, | ||
parsleyMultipleInstance; | ||
// Get parsleyFormInstance options if exist, mixed with element attributes | ||
this.options = $.extend(this.options, parsleyFormInstance ? parsleyFormInstance.OptionsFactory.get(parsleyFormInstance) : {}, ParsleyUtils.attr(this.$element, this.options.namespace)); | ||
// Handle multiple name | ||
if (this.options.multiple) | ||
multiple = this.options.multiple; | ||
else if ('undefined' !== typeof this.$element.attr('name') && this.$element.attr('name').length) | ||
multiple = name = this.$element.attr('name'); | ||
else if ('undefined' !== typeof this.$element.attr('id') && this.$element.attr('id').length) | ||
multiple = this.$element.attr('id'); | ||
// Special select multiple input | ||
if (this.$element.is('select') && 'undefined' !== typeof this.$element.attr('multiple')) { | ||
return this.bind('parsleyFieldMultiple', parsleyFormInstance, multiple || this.__id__); | ||
// Else for radio / checkboxes, we need a `name` or `data-parsley-multiple` to properly bind it | ||
} else if ('undefined' === typeof multiple) { | ||
if (window.console && window.console.warn) | ||
window.console.warn('To be binded by Parsley, a radio, a checkbox and a multiple select input must have either a name or a multiple option.', this.$element); | ||
return this; | ||
} | ||
// Remove special chars | ||
multiple = multiple.replace(/(:|\.|\[|\]|\{|\}|\$)/g, ''); | ||
// Add proper `data-parsley-multiple` to siblings if we have a valid multiple name | ||
if ('undefined' !== typeof name) { | ||
$('input[name="' + name + '"]').each(function () { | ||
if ($(this).is('input[type=radio], input[type=checkbox]')) | ||
$(this).attr(that.options.namespace + 'multiple', multiple); | ||
}); | ||
} | ||
// Check here if we don't already have a related multiple instance saved | ||
if ($('[' + this.options.namespace + 'multiple=' + multiple +']').length) { | ||
for (var i = 0; i < $('[' + this.options.namespace + 'multiple=' + multiple +']').length; i++) { | ||
if ('undefined' !== typeof $($('[' + this.options.namespace + 'multiple=' + multiple +']').get(i)).data('Parsley')) { | ||
parsleyMultipleInstance = $($('[' + this.options.namespace + 'multiple=' + multiple +']').get(i)).data('Parsley'); | ||
if (!this.$element.data('ParsleyFieldMultiple')) { | ||
parsleyMultipleInstance.addElement(this.$element); | ||
this.$element.attr(this.options.namespace + 'id', parsleyMultipleInstance.__id__); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
// Create a secret ParsleyField instance for every multiple field. It would be stored in `data('ParsleyFieldMultiple')` | ||
// And would be useful later to access classic `ParsleyField` stuff while being in a `ParsleyFieldMultiple` instance | ||
this.bind('parsleyField', parsleyFormInstance, multiple, true); | ||
return parsleyMultipleInstance || this.bind('parsleyFieldMultiple', parsleyFormInstance, multiple); | ||
}, | ||
// Retrieve namespace used for DOM-API | ||
getNamespace: function (options) { | ||
// `data-parsley-namespace=<namespace>` | ||
if ('undefined' !== typeof this.$element.data('parsleyNamespace')) | ||
return this.$element.data('parsleyNamespace'); | ||
if ('undefined' !== typeof ParsleyUtils.get(options, 'namespace')) | ||
return options.namespace; | ||
if ('undefined' !== typeof ParsleyUtils.get(window, 'ParsleyConfig.namespace')) | ||
return window.ParsleyConfig.namespace; | ||
return ParsleyDefaults.namespace; | ||
}, | ||
// Return proper `ParsleyForm`, `ParsleyField` or `ParsleyFieldMultiple` | ||
bind: function (type, parentParsleyFormInstance, multiple, doNotStore) { | ||
var parsleyInstance; | ||
switch (type) { | ||
case 'parsleyForm': | ||
parsleyInstance = $.extend( | ||
new ParsleyForm(this.$element, this.OptionsFactory), | ||
new ParsleyAbstract(), | ||
window.ParsleyExtend | ||
)._bindFields(); | ||
break; | ||
case 'parsleyField': | ||
parsleyInstance = $.extend( | ||
new ParsleyField(this.$element, this.OptionsFactory, parentParsleyFormInstance), | ||
new ParsleyAbstract(), | ||
window.ParsleyExtend | ||
); | ||
break; | ||
case 'parsleyFieldMultiple': | ||
parsleyInstance = $.extend( | ||
new ParsleyField(this.$element, this.OptionsFactory, parentParsleyFormInstance), | ||
new ParsleyAbstract(), | ||
new ParsleyMultiple(), | ||
window.ParsleyExtend | ||
)._init(multiple); | ||
break; | ||
default: | ||
throw new Error(type + 'is not a supported Parsley type'); | ||
} | ||
if ('undefined' !== typeof multiple) | ||
ParsleyUtils.setAttr(this.$element, this.options.namespace, 'multiple', multiple); | ||
if ('undefined' !== typeof doNotStore) { | ||
this.$element.data('ParsleyFieldMultiple', parsleyInstance); | ||
return parsleyInstance; | ||
} | ||
// Store instance if `ParsleyForm`, `ParsleyField` or `ParsleyFieldMultiple` | ||
if (new RegExp('ParsleyF', 'i').test(parsleyInstance.__class__)) { | ||
// Store for later access the freshly binded instance in DOM element itself using jQuery `data()` | ||
this.$element.data('Parsley', parsleyInstance); | ||
// Tell the world we got a new ParsleyForm or ParsleyField instance! | ||
$.emit('parsley:' + ('parsleyForm' === type ? 'form' : 'field') + ':init', parsleyInstance); | ||
} | ||
return parsleyInstance; | ||
} | ||
}; | ||
// ### jQuery API | ||
@@ -235,4 +67,3 @@ // `$('.elem').parsley(options)` or `$('.elem').psly(options)` | ||
if (!$(this).length) { | ||
if (window.console && window.console.warn) | ||
window.console.warn('You must bind Parsley on an existing element.'); | ||
ParsleyUtils.warn('You must bind Parsley on an existing element.'); | ||
@@ -242,20 +73,14 @@ return; | ||
return new Parsley(this, options); | ||
return new ParsleyFactory(this, options); | ||
}; | ||
// ### ParsleyUI | ||
// UI is a class apart that only listen to some events and them modify DOM accordingly | ||
// Could be overriden by defining a `window.ParsleyConfig.ParsleyUI` appropriate class (with `listen()` method basically) | ||
window.ParsleyUI = 'function' === typeof ParsleyUtils.get(window, 'ParsleyConfig.ParsleyUI') ? | ||
new window.ParsleyConfig.ParsleyUI().listen() : new ParsleyUI().listen(); | ||
// ### ParsleyField and ParsleyForm extension | ||
// Ensure that defined if not already the case | ||
// Ensure the extension is now defined if it wasn't previously | ||
if ('undefined' === typeof window.ParsleyExtend) | ||
window.ParsleyExtend = {}; | ||
// ### ParsleyConfig | ||
// Ensure that defined if not already the case | ||
if ('undefined' === typeof window.ParsleyConfig) | ||
window.ParsleyConfig = {}; | ||
// ### Parsley config | ||
// Inherit from ParsleyDefault, and copy over any existing values | ||
Parsley.options = $.extend(ParsleyUtils.objectCreate(ParsleyDefaults), window.ParsleyConfig); | ||
window.ParsleyConfig = Parsley.options; // Old way of accessing global options | ||
@@ -267,5 +92,11 @@ // ### Globals | ||
// ### ParsleyUI | ||
// UI is a separate class that only listens to some events and then modifies the DOM accordingly | ||
// Could be overriden by defining a `window.ParsleyConfig.ParsleyUI` appropriate class (with `listen()` method basically) | ||
window.ParsleyUI = 'function' === typeof window.ParsleyConfig.ParsleyUI ? | ||
new window.ParsleyConfig.ParsleyUI().listen() : new ParsleyUI().listen(); | ||
// ### PARSLEY auto-binding | ||
// Prevent it by setting `ParsleyConfig.autoBind` to `false` | ||
if (false !== ParsleyUtils.get(window, 'ParsleyConfig.autoBind')) | ||
if (false !== window.ParsleyConfig.autoBind) | ||
$(function () { | ||
@@ -272,0 +103,0 @@ // Works only on `data-parsley-validate`. |
define('parsley/abstract', [ | ||
], function () { | ||
var ParsleyAbstract = function() {}; | ||
'parsley/utils' | ||
], function (ParsleyUtils) { | ||
var ParsleyAbstract = function () {}; | ||
@@ -9,7 +10,19 @@ ParsleyAbstract.prototype = { | ||
actualizeOptions: function () { | ||
this.options = this.OptionsFactory.get(this); | ||
ParsleyUtils.attr(this.$element, this.options.namespace, this.domOptions); | ||
if (this.parent && this.parent.actualizeOptions) | ||
this.parent.actualizeOptions(); | ||
return this; | ||
}, | ||
_resetOptions: function (initOptions) { | ||
this.domOptions = ParsleyUtils.objectCreate(this.parent.options); | ||
this.options = ParsleyUtils.objectCreate(this.domOptions); | ||
// Shallow copy of ownProperties of initOptions: | ||
for (var i in initOptions) { | ||
if (initOptions.hasOwnProperty(i)) | ||
this.options[i] = initOptions[i]; | ||
} | ||
this.actualizeOptions(); | ||
}, | ||
// ParsleyValidator validate proxy function . Could be replaced by third party scripts | ||
@@ -20,16 +33,58 @@ validateThroughValidator: function (value, constraints, priority) { | ||
// Subscribe an event and a handler for a specific field or a specific form | ||
// If on a ParsleyForm instance, it will be attached to form instance and also | ||
// To every field instance for this form | ||
subscribe: function (name, fn) { | ||
_listeners: null, | ||
// Register a callback for the given event name. | ||
// Callback is called with context as the first argument and the `this`. | ||
// The context is the current parsley instance, or window.Parsley if global. | ||
// A return value of `false` will interrupt the calls | ||
on: function (name, fn) { | ||
this._listeners = this._listeners || {}; | ||
var queue = this._listeners[name] = this._listeners[name] || []; | ||
queue.push(fn); | ||
return this; | ||
}, | ||
// Deprecated. Use `on` instead. | ||
subscribe: function(name, fn) { | ||
$.listenTo(this, name.toLowerCase(), fn); | ||
}, | ||
// Unregister a callback (or all if none is given) for the given event name | ||
off: function (name, fn) { | ||
var queue = this._listeners && this._listeners[name]; | ||
if (queue) { | ||
if (!fn) { | ||
delete this._listeners[name]; | ||
} else { | ||
for(var i = queue.length; i--; ) | ||
if (queue[i] === fn) | ||
queue.splice(i, 1); | ||
} | ||
} | ||
return this; | ||
}, | ||
// Same as subscribe above. Unsubscribe an event for field, or form + its fields | ||
unsubscribe: function (name) { | ||
// Deprecated. Use `off` | ||
unsubscribe: function(name, fn) { | ||
$.unsubscribeTo(this, name.toLowerCase()); | ||
}, | ||
return this; | ||
// Trigger an event of the given name. | ||
// A return value of `false` interrupts the callback chain. | ||
// Returns false if execution was interrupted. | ||
trigger: function (name, target) { | ||
target = target || this; | ||
var queue = this._listeners && this._listeners[name]; | ||
var result, parentResult; | ||
if (queue) { | ||
for(var i = queue.length; i--; ) { | ||
result = queue[i].call(target, target); | ||
if (result === false) return result; | ||
} | ||
} | ||
if (this.parent) { | ||
return this.parent.trigger(name, target); | ||
} | ||
return true; | ||
}, | ||
@@ -41,9 +96,9 @@ | ||
if ('ParsleyForm' !== this.__class__) | ||
return $.emit('parsley:field:reset', this); | ||
return this._trigger('reset'); | ||
// Form case: emit a reset event for each field | ||
for (var i = 0; i < this.fields.length; i++) | ||
$.emit('parsley:field:reset', this.fields[i]); | ||
this.fields[i]._trigger('reset'); | ||
$.emit('parsley:form:reset', this); | ||
this._trigger('reset'); | ||
}, | ||
@@ -57,3 +112,3 @@ | ||
this.$element.removeData('ParsleyFieldMultiple'); | ||
$.emit('parsley:field:destroy', this); | ||
this._trigger('destroy'); | ||
@@ -68,3 +123,7 @@ return; | ||
this.$element.removeData('Parsley'); | ||
$.emit('parsley:form:destroy', this); | ||
this._trigger('destroy'); | ||
}, | ||
_findRelatedMultiple: function() { | ||
return this.parent.$element.find('[' + this.options.namespace + 'multiple="' + this.options.multiple +'"]'); | ||
} | ||
@@ -71,0 +130,0 @@ }; |
@@ -7,3 +7,3 @@ // All these options could be overriden and specified directly in DOM using | ||
define('parsley/defaults', function () { | ||
return { | ||
var ParsleyDefaults = { | ||
// ### General | ||
@@ -23,2 +23,10 @@ | ||
// ### Field only | ||
// identifier used to group together inputs (e.g. radio buttons...) | ||
multiple: null, | ||
// identifier (or array of identifiers) used to validate only a select group of inputs | ||
group: null, | ||
// ### UI | ||
@@ -57,2 +65,4 @@ // Enable\Disable error messages | ||
}; | ||
return ParsleyDefaults; | ||
}); |
@@ -7,3 +7,3 @@ define('parsley/factory/constraint', [ | ||
if (!new RegExp('ParsleyField').test(ParsleyUtils.get(parsleyField, '__class__'))) | ||
if (!new RegExp('ParsleyField').test(parsleyField.__class__)) | ||
throw new Error('ParsleyField or ParsleyFieldMultiple instance expected'); | ||
@@ -20,3 +20,3 @@ | ||
return ParsleyUtils.get(assert, 'priority') || 2; | ||
return assert.priority || 2; | ||
}; | ||
@@ -38,3 +38,3 @@ | ||
groups: [priority], | ||
isDomConstraint: isDomConstraint || ParsleyUtils.attr(parsleyField.$element, parsleyField.options.namespace, name) | ||
isDomConstraint: isDomConstraint || ParsleyUtils.checkAttr(parsleyField.$element, parsleyField.options.namespace, name) | ||
}); | ||
@@ -41,0 +41,0 @@ }; |
@@ -6,20 +6,16 @@ define('parsley/field', [ | ||
], function (ConstraintFactory, ParsleyUI, ParsleyUtils) { | ||
var ParsleyField = function (field, OptionsFactory, parsleyFormInstance) { | ||
var ParsleyField = function (field, domOptions, options, parsleyFormInstance) { | ||
this.__class__ = 'ParsleyField'; | ||
this.__id__ = ParsleyUtils.hash(4); | ||
this.__id__ = ParsleyUtils.generateID(); | ||
this.$element = $(field); | ||
// If we have a parent `ParsleyForm` instance given, use its `OptionsFactory`, and save parent | ||
// Set parent if we have one | ||
if ('undefined' !== typeof parsleyFormInstance) { | ||
this.parent = parsleyFormInstance; | ||
this.OptionsFactory = this.parent.OptionsFactory; | ||
this.options = this.OptionsFactory.get(this); | ||
// Else, take the `Parsley` one | ||
} else { | ||
this.OptionsFactory = OptionsFactory; | ||
this.options = this.OptionsFactory.get(this); | ||
} | ||
this.options = options; | ||
this.domOptions = domOptions; | ||
// Initialize some properties | ||
@@ -36,6 +32,5 @@ this.constraints = []; | ||
// # Public API | ||
// Validate field and $.emit some events for mainly `ParsleyUI` | ||
// Validate field and trigger some events for mainly `ParsleyUI` | ||
// @returns validationResult: | ||
// - `true` if all constraints pass | ||
// - `[]` if not required field and empty (not validated) | ||
// - `true` if field valid | ||
// - `[Violation, [Violation...]]` if there were validation errors | ||
@@ -46,8 +41,8 @@ validate: function (force) { | ||
// Field Validate event. `this.value` could be altered for custom needs | ||
$.emit('parsley:field:validate', this); | ||
this._trigger('validate'); | ||
$.emit('parsley:field:' + (this.isValid(force, this.value) ? 'success' : 'error'), this); | ||
this._trigger(this.isValid(force, this.value) ? 'success' : 'error'); | ||
// Field validated event. `this.validationResult` could be altered for custom needs too | ||
$.emit('parsley:field:validated', this); | ||
this._trigger('validated'); | ||
@@ -57,12 +52,31 @@ return this.validationResult; | ||
hasConstraints: function () { | ||
return 0 !== this.constraints.length; | ||
}, | ||
// An empty optional field does not need validation | ||
needsValidation: function (value) { | ||
if ('undefined' === typeof value) | ||
value = this.getValue(); | ||
// If a field is empty and not required, it is valid | ||
// Except if `data-parsley-validate-if-empty` explicitely added, useful for some custom validators | ||
if (!value.length && !this._isRequired() && 'undefined' === typeof this.options.validateIfEmpty) | ||
return false; | ||
return true; | ||
}, | ||
// Just validate field. Do not trigger any event | ||
// Same @return as `validate()` | ||
// - `false` if there are constraints and at least one of them failed | ||
// - `true` in all other cases | ||
isValid: function (force, value) { | ||
// Recompute options and rebind constraints to have latest changes | ||
this.refreshConstraints(); | ||
this.validationResult = true; | ||
// Sort priorities to validate more important first | ||
var priorities = this._getConstraintsSortedPriorities(); | ||
if (0 === priorities.length) | ||
return this.validationResult = []; | ||
// A field without constraint is valid | ||
if (!this.hasConstraints()) | ||
return true; | ||
// Value could be passed as argument, needed to add more power to 'parsley:field:validate' | ||
@@ -72,12 +86,12 @@ if ('undefined' === typeof value || null === value) | ||
// If a field is empty and not required, leave it alone, it's just fine | ||
// Except if `data-parsley-validate-if-empty` explicitely added, useful for some custom validators | ||
if (!value.length && !this._isRequired() && 'undefined' === typeof this.options.validateIfEmpty && true !== force) | ||
return this.validationResult = []; | ||
if (!this.needsValidation(value) && true !== force) | ||
return true; | ||
// If we want to validate field against all constraints, just call Validator and let it do the job | ||
if (false === this.options.priorityEnabled) | ||
return true === (this.validationResult = this.validateThroughValidator(value, this.constraints, 'Any')); | ||
// Else, iterate over priorities one by one, and validate related asserts one by one | ||
var priorities = ['Any']; | ||
if (false !== this.options.priorityEnabled) { | ||
// Sort priorities to validate more important first | ||
priorities = this._getConstraintsSortedPriorities(); | ||
} | ||
// Iterate over priorities one by one, and validate related asserts one by one | ||
for (var i = 0; i < priorities.length; i++) | ||
@@ -94,4 +108,6 @@ if (true !== (this.validationResult = this.validateThroughValidator(value, this.constraints, priorities[i]))) | ||
// Value could be overriden in DOM | ||
if ('undefined' !== typeof this.options.value) | ||
// Value could be overriden in DOM or with explicit options | ||
if ('function' === typeof this.options.value) | ||
value = this.options.value(this); | ||
else if ('undefined' !== typeof this.options.value) | ||
value = this.options.value; | ||
@@ -128,3 +144,2 @@ else | ||
addConstraint: function (name, requirements, priority, isDomConstraint) { | ||
name = name.toLowerCase(); | ||
@@ -210,3 +225,3 @@ if ('function' === typeof window.ParsleyValidator.validators[name]) { | ||
// length | ||
@@ -239,3 +254,3 @@ if ('undefined' !== typeof this.$element.attr('minlength') && 'undefined' !== typeof this.$element.attr('maxlength')) | ||
// Regular other HTML5 supported types | ||
} else if (new RegExp(type, 'i').test('email url range')) { | ||
} else if (/^(email|url|range)$/i.test(type)) { | ||
return this.addConstraint('type', type, undefined, true); | ||
@@ -256,2 +271,9 @@ } | ||
// Internal only. | ||
// Shortcut to trigger an event | ||
_trigger: function (eventName) { | ||
eventName = 'field:' + eventName; | ||
return this.trigger.apply(this, arguments); | ||
}, | ||
// Internal only. | ||
// Sort constraints by priority DESC | ||
@@ -258,0 +280,0 @@ _getConstraintsSortedPriorities: function () { |
@@ -5,14 +5,13 @@ define('parsley/form', [ | ||
], function (ParsleyAbstract, ParsleyUtils) { | ||
var ParsleyForm = function (element, OptionsFactory) { | ||
var ParsleyForm = function (element, domOptions, options) { | ||
this.__class__ = 'ParsleyForm'; | ||
this.__id__ = ParsleyUtils.hash(4); | ||
this.__id__ = ParsleyUtils.generateID(); | ||
if ('OptionsFactory' !== ParsleyUtils.get(OptionsFactory, '__class__')) | ||
throw new Error('You must give an OptionsFactory instance'); | ||
this.OptionsFactory = OptionsFactory; | ||
this.$element = $(element); | ||
this.domOptions = domOptions; | ||
this.options = options; | ||
this.parent = window.Parsley; | ||
this.fields = []; | ||
this.validationResult = null; | ||
this.options = this.OptionsFactory.get(this); | ||
}; | ||
@@ -25,3 +24,3 @@ | ||
// prevent form submission if validation fails | ||
if (false === this.validationResult && event instanceof $.Event) { | ||
if ((false === this.validationResult || !this._trigger('submit')) && event instanceof $.Event) { | ||
event.stopImmediatePropagation(); | ||
@@ -41,3 +40,4 @@ event.preventDefault(); | ||
$.emit('parsley:form:validate', this); | ||
// fire validate event to eventually modify things before very validation | ||
this._trigger('validate'); | ||
@@ -47,17 +47,19 @@ // Refresh form DOM options and form's fields that could have changed | ||
// loop through fields to validate them one by one | ||
for (var i = 0; i < this.fields.length; i++) { | ||
this._withoutReactualizingFormOptions(function(){ | ||
// loop through fields to validate them one by one | ||
for (var i = 0; i < this.fields.length; i++) { | ||
// do not validate a field if not the same as given validation group | ||
if (group && !this._isFieldInGroup(this.fields[i], group)) | ||
continue; | ||
// do not validate a field if not the same as given validation group | ||
if (group && !this._isFieldInGroup(this.fields[i], group)) | ||
continue; | ||
fieldValidationResult = this.fields[i].validate(force); | ||
fieldValidationResult = this.fields[i].validate(force); | ||
if (true !== fieldValidationResult && fieldValidationResult.length > 0 && this.validationResult) | ||
this.validationResult = false; | ||
} | ||
if (true !== fieldValidationResult && fieldValidationResult.length > 0 && this.validationResult) | ||
this.validationResult = false; | ||
} | ||
}); | ||
$.emit('parsley:form:' + (this.validationResult ? 'success' : 'error'), this); | ||
$.emit('parsley:form:validated', this); | ||
this._trigger(this.validationResult ? 'success' : 'error'); | ||
this._trigger('validated'); | ||
@@ -71,17 +73,19 @@ return this.validationResult; | ||
for (var i = 0; i < this.fields.length; i++) { | ||
return this._withoutReactualizingFormOptions(function(){ | ||
for (var i = 0; i < this.fields.length; i++) { | ||
// do not validate a field if not the same as given validation group | ||
if (group && !this._isFieldInGroup(this.fields[i], group)) | ||
continue; | ||
// do not validate a field if not the same as given validation group | ||
if (group && !this._isFieldInGroup(this.fields[i], group)) | ||
continue; | ||
if (false === this.fields[i].isValid(force)) | ||
return false; | ||
} | ||
if (false === this.fields[i].isValid(force)) | ||
return false; | ||
} | ||
return true; | ||
return true; | ||
}); | ||
}, | ||
_isFieldInGroup: function (field, group) { | ||
if(ParsleyUtils.isArray(field.options.group)) | ||
if($.isArray(field.options.group)) | ||
return -1 !== $.inArray(group, field.options.group); | ||
@@ -96,3 +100,4 @@ return field.options.group === group; | ||
_bindFields: function () { | ||
var self = this; | ||
var self = this, | ||
oldFields = this.fields; | ||
@@ -102,15 +107,47 @@ this.fields = []; | ||
this.$element.find(this.options.inputs).each(function () { | ||
var fieldInstance = new window.Parsley(this, {}, self); | ||
this._withoutReactualizingFormOptions(function(){ | ||
this.$element | ||
.find(this.options.inputs) | ||
.not(this.options.excluded) | ||
.each(function () { | ||
var fieldInstance = new Parsley.Factory(this, {}, self); | ||
// Only add valid and not excluded `ParsleyField` and `ParsleyFieldMultiple` children | ||
if (('ParsleyField' === fieldInstance.__class__ || 'ParsleyFieldMultiple' === fieldInstance.__class__) && !fieldInstance.$element.is(fieldInstance.options.excluded)) | ||
if ('undefined' === typeof self.fieldsMappedById[fieldInstance.__class__ + '-' + fieldInstance.__id__]) { | ||
self.fieldsMappedById[fieldInstance.__class__ + '-' + fieldInstance.__id__] = fieldInstance; | ||
self.fields.push(fieldInstance); | ||
} | ||
// Only add valid and not excluded `ParsleyField` and `ParsleyFieldMultiple` children | ||
if (('ParsleyField' === fieldInstance.__class__ || 'ParsleyFieldMultiple' === fieldInstance.__class__) && (true !== fieldInstance.options.excluded)) | ||
if ('undefined' === typeof self.fieldsMappedById[fieldInstance.__class__ + '-' + fieldInstance.__id__]) { | ||
self.fieldsMappedById[fieldInstance.__class__ + '-' + fieldInstance.__id__] = fieldInstance; | ||
self.fields.push(fieldInstance); | ||
} | ||
}); | ||
$(oldFields).not(self.fields).each(function () { | ||
this._trigger('reset'); | ||
}); | ||
}); | ||
return this; | ||
}, | ||
return this; | ||
// Internal only. | ||
// Looping on a form's fields to do validation or similar | ||
// will trigger reactualizing options on all of them, which | ||
// in turn will reactualize the form's options. | ||
// To avoid calling actualizeOptions so many times on the form | ||
// for nothing, _withoutReactualizingFormOptions temporarily disables | ||
// the method actualizeOptions on this form while `fn` is called. | ||
_withoutReactualizingFormOptions: function (fn) { | ||
var oldActualizeOptions = this.actualizeOptions; | ||
this.actualizeOptions = function() { return this }; | ||
var result = fn.call(this); // Keep the current `this`. | ||
this.actualizeOptions = oldActualizeOptions; | ||
return result; | ||
}, | ||
// Internal only. | ||
// Shortcut to trigger an event | ||
// Returns true iff event is not interrupted and default not prevented. | ||
_trigger: function (eventName) { | ||
eventName = 'form:' + eventName; | ||
return this.trigger.apply(this, arguments); | ||
} | ||
}; | ||
@@ -117,0 +154,0 @@ |
@@ -54,3 +54,3 @@ define('parsley/multiple', [ | ||
if (this.$element.is('input[type=radio]')) | ||
return $('[' + this.options.namespace + 'multiple="' + this.options.multiple + '"]:checked').val() || ''; | ||
return this._findRelatedMultiple().filter(':checked').val() || ''; | ||
@@ -61,7 +61,7 @@ // checkbox input case | ||
$('[' + this.options.namespace + 'multiple="' + this.options.multiple + '"]:checked').each(function () { | ||
this._findRelatedMultiple().filter(':checked').each(function () { | ||
values.push($(this).val()); | ||
}); | ||
return values.length ? values : []; | ||
return values; | ||
} | ||
@@ -77,5 +77,4 @@ | ||
_init: function (multiple) { | ||
_init: function () { | ||
this.$elements = [this.$element]; | ||
this.options.multiple = multiple; | ||
@@ -82,0 +81,0 @@ return this; |
define('parsley/pubsub', [ | ||
'parsley/field', | ||
'parsley/form' | ||
], function (ParsleyField, ParsleyForm) { | ||
'parsley/form', | ||
'parsley/utils' | ||
], function (ParsleyField, ParsleyForm, ParsleyUtils) { | ||
var | ||
o = $({}), | ||
subscribed = {}; | ||
deprecated = function () { | ||
ParsleyUtils.warnOnce("Parsley's pubsub module is deprecated; use the corresponding jQuery event method instead"); | ||
}; | ||
// $.listen(name, callback); | ||
// $.listen(name, context, callback); | ||
$.listen = function (name) { | ||
if ('undefined' === typeof subscribed[name]) | ||
subscribed[name] = []; | ||
// Returns an event handler that calls `fn` with the arguments it expects | ||
function adapt(fn, context) { | ||
// Store to allow unbinding | ||
if (!fn.parsleyAdaptedCallback) { | ||
fn.parsleyAdaptedCallback = function () { | ||
var args = Array.prototype.slice.call(arguments, 0); | ||
args.unshift(this); | ||
fn.apply(context || o, args); | ||
}; | ||
} | ||
return fn.parsleyAdaptedCallback; | ||
} | ||
if ('function' === typeof arguments[1]) | ||
return subscribed[name].push({ fn: arguments[1] }); | ||
var eventPrefix = 'parsley:'; | ||
// Converts 'parsley:form:validate' into 'form:validate' | ||
function eventName(name) { | ||
if (name.lastIndexOf(eventPrefix, 0) === 0) | ||
return name.substr(eventPrefix.length); | ||
return name; | ||
} | ||
if ('object' === typeof arguments[1] && 'function' === typeof arguments[2]) | ||
return subscribed[name].push({ fn: arguments[2], ctxt: arguments[1] }); | ||
// $.listen is deprecated. Use Parsley.on instead. | ||
$.listen = function (name, callback) { | ||
var context; | ||
deprecated(); | ||
if ('object' === typeof arguments[1] && 'function' === typeof arguments[2]) { | ||
context = arguments[1]; | ||
callback = arguments[2]; | ||
} | ||
throw new Error('Wrong parameters'); | ||
if ('function' !== typeof arguments[1]) | ||
throw new Error('Wrong parameters'); | ||
window.Parsley.on(eventName(name), adapt(callback, context)); | ||
}; | ||
$.listenTo = function (instance, name, fn) { | ||
if ('undefined' === typeof subscribed[name]) | ||
subscribed[name] = []; | ||
deprecated(); | ||
if (!(instance instanceof ParsleyField) && !(instance instanceof ParsleyForm)) | ||
@@ -34,71 +56,42 @@ throw new Error('Must give Parsley instance'); | ||
subscribed[name].push({ instance: instance, fn: fn }); | ||
instance.on(eventName(name), adapt(fn)); | ||
}; | ||
$.unsubscribe = function (name, fn) { | ||
if ('undefined' === typeof subscribed[name]) | ||
return; | ||
deprecated(); | ||
if ('string' !== typeof name || 'function' !== typeof fn) | ||
throw new Error('Wrong arguments'); | ||
for (var i = 0; i < subscribed[name].length; i++) | ||
if (subscribed[name][i].fn === fn) | ||
return subscribed[name].splice(i, 1); | ||
window.Parsley.off(eventName(name), fn.parsleyAdaptedCallback); | ||
}; | ||
$.unsubscribeTo = function (instance, name) { | ||
if ('undefined' === typeof subscribed[name]) | ||
return; | ||
deprecated(); | ||
if (!(instance instanceof ParsleyField) && !(instance instanceof ParsleyForm)) | ||
throw new Error('Must give Parsley instance'); | ||
for (var i = 0; i < subscribed[name].length; i++) | ||
if ('undefined' !== typeof subscribed[name][i].instance && subscribed[name][i].instance.__id__ === instance.__id__) | ||
return subscribed[name].splice(i, 1); | ||
instance.off(eventName(name)); | ||
}; | ||
$.unsubscribeAll = function (name) { | ||
if ('undefined' === typeof subscribed[name]) | ||
return; | ||
delete subscribed[name]; | ||
deprecated(); | ||
window.Parsley.off(eventName(name)); | ||
$('form,input,textarea,select').each(function() { | ||
var instance = $(this).data('Parsley'); | ||
if (instance) { | ||
instance.off(eventName(name)); | ||
} | ||
}); | ||
}; | ||
// $.emit(name [, arguments...]); | ||
// $.emit(name, instance [, arguments...]); | ||
// $.emit is deprecated. Use jQuery events instead. | ||
$.emit = function (name, instance) { | ||
if ('undefined' === typeof subscribed[name]) | ||
return; | ||
// loop through registered callbacks for this event | ||
for (var i = 0; i < subscribed[name].length; i++) { | ||
// if instance is not registered, simple emit | ||
if ('undefined' === typeof subscribed[name][i].instance) { | ||
subscribed[name][i].fn.apply('undefined' !== typeof subscribed[name][i].ctxt ? subscribed[name][i].ctxt : o, Array.prototype.slice.call(arguments, 1)); | ||
continue; | ||
} | ||
// if instance registered but no instance given for the emit, continue | ||
if (!(instance instanceof ParsleyField) && !(instance instanceof ParsleyForm)) | ||
continue; | ||
// if instance is registered and same id, emit | ||
if (subscribed[name][i].instance.__id__ === instance.__id__) { | ||
subscribed[name][i].fn.apply(o, Array.prototype.slice.call(arguments, 1)); | ||
continue; | ||
} | ||
// if registered instance is a Form and fired one is a Field, loop over all its fields and emit if field found | ||
if (subscribed[name][i].instance instanceof ParsleyForm && instance instanceof ParsleyField) | ||
for (var j = 0; j < subscribed[name][i].instance.fields.length; j++) | ||
if (subscribed[name][i].instance.fields[j].__id__ === instance.__id__) { | ||
subscribed[name][i].fn.apply(o, Array.prototype.slice.call(arguments, 1)); | ||
continue; | ||
} | ||
deprecated(); | ||
var instanceGiven = (instance instanceof ParsleyField) || (instance instanceof ParsleyForm); | ||
var args = Array.prototype.slice.call(arguments, instanceGiven ? 2 : 1); | ||
args.unshift(eventName(name)); | ||
if (!instanceGiven) { | ||
instance = window.Parsley; | ||
} | ||
instance.trigger.apply(instance, args); | ||
}; | ||
$.subscribed = function () { return subscribed; }; | ||
}); |
@@ -10,13 +10,12 @@ define('parsley/ui', [ | ||
listen: function () { | ||
$.listen('parsley:form:init', this, this.setupForm); | ||
$.listen('parsley:field:init', this, this.setupField); | ||
var that = this; | ||
window.Parsley | ||
.on('form:init', function () { that.setupForm (this); } ) | ||
.on('field:init', function () { that.setupField(this); } ) | ||
.on('field:validated', function () { that.reflow (this); } ) | ||
.on('form:validated', function () { that.focus (this); } ) | ||
.on('field:reset', function () { that.reset (this); } ) | ||
.on('form:destroy', function () { that.destroy (this); } ) | ||
.on('field:destroy', function () { that.destroy (this); } ); | ||
$.listen('parsley:field:validated', this, this.reflow); | ||
$.listen('parsley:form:validated', this, this.focus); | ||
$.listen('parsley:field:reset', this, this.reset); | ||
$.listen('parsley:form:destroy', this, this.destroy); | ||
$.listen('parsley:field:destroy', this, this.destroy); | ||
return this; | ||
@@ -49,3 +48,3 @@ }, | ||
// If field is not valid for the first time, bind keyup trigger to ease UX and quickly inform user | ||
if ((diff.kept.length || diff.added.length) && 'undefined' === typeof fieldInstance._ui.failedOnce) | ||
if ((diff.kept.length || diff.added.length) && true !== fieldInstance._ui.failedOnce) | ||
this.manageFailingFieldTrigger(fieldInstance); | ||
@@ -69,3 +68,3 @@ }, | ||
manageStatusClass: function (fieldInstance) { | ||
if (true === fieldInstance.validationResult) | ||
if (fieldInstance.hasConstraints() && fieldInstance.needsValidation() && true === fieldInstance.validationResult) | ||
this._successClass(fieldInstance); | ||
@@ -85,2 +84,4 @@ else if (fieldInstance.validationResult.length > 0) | ||
if ((diff.added.length || diff.kept.length)) { | ||
this._insertErrorWrapper(fieldInstance); | ||
if (0 === fieldInstance._ui.$errorsWrapper.find('.parsley-custom-error-message').length) | ||
@@ -119,2 +120,3 @@ fieldInstance._ui.$errorsWrapper | ||
addError: function (fieldInstance, name, message, assert, doNotUpdateClass) { | ||
this._insertErrorWrapper(fieldInstance); | ||
fieldInstance._ui.$errorsWrapper | ||
@@ -157,16 +159,15 @@ .addClass('filled') | ||
focus: function (formInstance) { | ||
if (true === formInstance.validationResult || 'none' === formInstance.options.focus) | ||
return formInstance._focusedField = null; | ||
formInstance._focusedField = null; | ||
for (var i = 0; i < formInstance.fields.length; i++) | ||
if (true !== formInstance.fields[i].validationResult && formInstance.fields[i].validationResult.length > 0 && 'undefined' === typeof formInstance.fields[i].options.noFocus) { | ||
if ('first' === formInstance.options.focus) { | ||
formInstance._focusedField = formInstance.fields[i].$element; | ||
return formInstance._focusedField.focus(); | ||
} | ||
if (true === formInstance.validationResult || 'none' === formInstance.options.focus) | ||
return null; | ||
formInstance._focusedField = formInstance.fields[i].$element; | ||
for (var i = 0; i < formInstance.fields.length; i++) { | ||
var field = formInstance.fields[i]; | ||
if (true !== field.validationResult && field.validationResult.length > 0 && 'undefined' === typeof field.options.noFocus) { | ||
formInstance._focusedField = field.$element; | ||
if ('first' === formInstance.options.focus) | ||
break; | ||
} | ||
} | ||
@@ -242,3 +243,3 @@ if (null === formInstance._focusedField) | ||
// $errorsWrapper is a div that would contain the various field errors, it will be appended into $errorsContainer | ||
_ui.errorsWrapperId = 'parsley-id-' + ('undefined' !== typeof fieldInstance.options.multiple ? 'multiple-' + fieldInstance.options.multiple : fieldInstance.__id__); | ||
_ui.errorsWrapperId = 'parsley-id-' + (fieldInstance.options.multiple ? 'multiple-' + fieldInstance.options.multiple : fieldInstance.__id__); | ||
_ui.$errorsWrapper = $(fieldInstance.options.errorsWrapper).attr('id', _ui.errorsWrapperId); | ||
@@ -254,8 +255,2 @@ | ||
// Stops excluded inputs from getting errorContainer added | ||
if( !fieldInstance.$element.is(fieldInstance.options.excluded) ) { | ||
/** Mess with DOM now **/ | ||
this._insertErrorWrapper(fieldInstance); | ||
} | ||
// Bind triggers first time | ||
@@ -279,3 +274,3 @@ this.actualizeTriggers(fieldInstance); | ||
// Otherwise, if simple element (input, texatrea, select...) it will perfectly host the classes | ||
if ('undefined' === typeof fieldInstance.options.multiple || fieldInstance.$element.is('select')) | ||
if (!fieldInstance.options.multiple || fieldInstance.$element.is('select')) | ||
return fieldInstance.$element; | ||
@@ -290,7 +285,11 @@ | ||
// Nothing to do if already inserted | ||
if (0 !== fieldInstance._ui.$errorsWrapper.parent().length) | ||
return fieldInstance._ui.$errorsWrapper.parent(); | ||
if ('string' === typeof fieldInstance.options.errorsContainer) { | ||
if ($(fieldInstance.options.errorsContainer).length) | ||
return $(fieldInstance.options.errorsContainer).append(fieldInstance._ui.$errorsWrapper); | ||
else if (window.console && window.console.warn) | ||
window.console.warn('The errors container `' + fieldInstance.options.errorsContainer + '` does not exist in DOM'); | ||
else | ||
ParsleyUtils.warn('The errors container `' + fieldInstance.options.errorsContainer + '` does not exist in DOM'); | ||
} | ||
@@ -303,3 +302,6 @@ else if ('function' === typeof fieldInstance.options.errorsContainer) | ||
return 'undefined' === typeof fieldInstance.options.multiple ? fieldInstance.$element.after(fieldInstance._ui.$errorsWrapper) : fieldInstance.$element.parent().after(fieldInstance._ui.$errorsWrapper); | ||
var $from = fieldInstance.$element; | ||
if (fieldInstance.options.multiple) | ||
$from = $from.parent(); | ||
return $from.after(fieldInstance._ui.$errorsWrapper); | ||
}, | ||
@@ -310,3 +312,3 @@ | ||
if (fieldInstance.options.multiple) | ||
$toBind = $('[' + fieldInstance.options.namespace + 'multiple="' + fieldInstance.options.multiple + '"]') | ||
$toBind = $('[' + fieldInstance.options.namespace + 'multiple="' + fieldInstance.options.multiple + '"]'); | ||
@@ -332,3 +334,3 @@ // Remove Parsley events already binded on this field | ||
// Called through $.proxy with fieldInstance. `this` context is ParsleyField | ||
eventValidate: function(event) { | ||
eventValidate: function (event) { | ||
// For keyup, keypress, keydown... events that could be a little bit obstrusive | ||
@@ -367,3 +369,3 @@ // do not validate if val length < min threshold on first validation. Once field have been validated once and info | ||
// Reset all event listeners | ||
parsleyInstance.$element.off('.Parsley'); | ||
this.actualizeTriggers(parsleyInstance); | ||
parsleyInstance.$element.off('.ParsleyFailedOnce'); | ||
@@ -391,2 +393,3 @@ | ||
parsleyInstance._ui.validationInformationVisible = false; | ||
parsleyInstance._ui.failedOnce = false; | ||
}, | ||
@@ -393,0 +396,0 @@ |
define('parsley/utils', function () { | ||
return { | ||
var globalID = 1, | ||
pastWarnings = {}; | ||
var ParsleyUtils = { | ||
// Parsley DOM-API | ||
// returns object from dom attributes and values | ||
// if attr is given, returns bool if attr present in DOM or not | ||
attr: function ($element, namespace, checkAttr) { | ||
attr: function ($element, namespace, obj) { | ||
var | ||
attribute, | ||
obj = {}, | ||
msie = this.msieversion(), | ||
attribute, attributes, | ||
regex = new RegExp('^' + namespace, 'i'); | ||
if ('undefined' === typeof obj) | ||
obj = {}; | ||
else { | ||
// Clear all own properties. This won't affect prototype's values | ||
for (var i in obj) { | ||
if (obj.hasOwnProperty(i)) | ||
delete obj[i]; | ||
} | ||
} | ||
if ('undefined' === typeof $element || 'undefined' === typeof $element[0]) | ||
return {}; | ||
return obj; | ||
for (var i in $element[0].attributes) { | ||
attribute = $element[0].attributes[i]; | ||
attributes = $element[0].attributes; | ||
for (var i = attributes.length; i--; ) { | ||
attribute = attributes[i]; | ||
if ('undefined' !== typeof attribute && null !== attribute && (!msie || msie >= 8 || attribute.specified) && regex.test(attribute.name)) { | ||
if ('undefined' !== typeof checkAttr && new RegExp(checkAttr + '$', 'i').test(attribute.name)) | ||
return true; | ||
obj[this.camelize(attribute.name.replace(namespace, ''))] = this.deserializeValue(attribute.value); | ||
if (attribute && attribute.specified && regex.test(attribute.name)) { | ||
obj[this.camelize(attribute.name.slice(namespace.length))] = this.deserializeValue(attribute.value); | ||
} | ||
} | ||
return 'undefined' === typeof checkAttr ? obj : false; | ||
return obj; | ||
}, | ||
checkAttr: function ($element, namespace, checkAttr) { | ||
return $element.is('[' + namespace + checkAttr + ']'); | ||
}, | ||
setAttr: function ($element, namespace, attr, value) { | ||
@@ -34,32 +46,7 @@ $element[0].setAttribute(this.dasherize(namespace + attr), String(value)); | ||
// Recursive object / array getter | ||
get: function (obj, path) { | ||
var | ||
i = 0, | ||
paths = (path || '').split('.'); | ||
while (this.isObject(obj) || this.isArray(obj)) { | ||
obj = obj[paths[i++]]; | ||
if (i === paths.length) | ||
return obj; | ||
} | ||
return undefined; | ||
generateID: function () { | ||
return '' + globalID++; | ||
}, | ||
hash: function (length) { | ||
return String(Math.random()).substring(2, length ? length + 2 : 9); | ||
}, | ||
/** Third party functions **/ | ||
// Underscore isArray | ||
isArray: function (mixed) { | ||
return Object.prototype.toString.call(mixed) === '[object Array]'; | ||
}, | ||
// Underscore isObject | ||
isObject: function (mixed) { | ||
return mixed === Object(mixed); | ||
}, | ||
// Zepto deserialize function | ||
@@ -83,3 +70,3 @@ deserializeValue: function (value) { | ||
camelize: function (str) { | ||
return str.replace(/-+(.)?/g, function(match, chr) { | ||
return str.replace(/-+(.)?/g, function (match, chr) { | ||
return chr ? chr.toUpperCase() : ''; | ||
@@ -98,15 +85,37 @@ }); | ||
// http://support.microsoft.com/kb/167820 | ||
// http://stackoverflow.com/questions/19999388/jquery-check-if-user-is-using-ie | ||
msieversion: function () { | ||
var | ||
ua = window.navigator.userAgent, | ||
msie = ua.indexOf('MSIE '); | ||
warn: function() { | ||
if (window.console && window.console.warn) | ||
window.console.warn.apply(window.console, arguments); | ||
}, | ||
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) | ||
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10); | ||
warnOnce: function(msg) { | ||
if (!pastWarnings[msg]) { | ||
pastWarnings[msg] = true; | ||
this.warn.apply(this, arguments); | ||
} | ||
}, | ||
return 0; | ||
} | ||
_resetWarnings: function() { | ||
pastWarnings = {}; | ||
}, | ||
// Object.create polyfill, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create#Polyfill | ||
objectCreate: Object.create || (function () { | ||
var Object = function () {}; | ||
return function (prototype) { | ||
if (arguments.length > 1) { | ||
throw Error('Second argument not supported'); | ||
} | ||
if (typeof prototype != 'object') { | ||
throw TypeError('Argument must be an object'); | ||
} | ||
Object.prototype = prototype; | ||
var result = new Object(); | ||
Object.prototype = null; | ||
return result; | ||
}; | ||
})() | ||
}; | ||
return ParsleyUtils; | ||
}); |
define('parsley/validator', [ | ||
'parsley/defaults', | ||
'validator' | ||
], function (Validator) { | ||
], function (ParsleyDefaults, Validator) { | ||
@@ -21,2 +22,4 @@ // This is needed for Browserify usage that requires Validator.js through module.exports | ||
this.catalog = catalog; | ||
// Copy prototype's validators: | ||
this.validators = $.extend({}, this.validators); | ||
@@ -26,3 +29,3 @@ for (var name in validators) | ||
$.emit('parsley:validator:init'); | ||
window.Parsley.trigger('parsley:validator:init'); | ||
}, | ||
@@ -67,17 +70,23 @@ | ||
addValidator: function (name, fn, priority, requirementsTransformer) { | ||
this.validators[name.toLowerCase()] = function (requirements) { | ||
return $.extend(new Validator.Assert().Callback(fn, requirements), { | ||
priority: priority, | ||
requirementsTransformer: requirementsTransformer | ||
}); | ||
if (this.validators[name]) | ||
ParsleyUtils.warn('Validator "' + name + '" is already defined.'); | ||
else if (ParsleyDefaults.hasOwnProperty(name)) { | ||
ParsleyUtils.warn('"' + name + '" is a restricted keyword and is not a valid validator name.'); | ||
return; | ||
}; | ||
return this; | ||
return this._setValidator(name, fn, priority, requirementsTransformer); | ||
}, | ||
updateValidator: function (name, fn, priority, requirementsTransformer) { | ||
return this.addValidator(name, fn, priority, requirementsTransformer); | ||
if (!this.validators[name]) { | ||
ParsleyUtils.warn('Validator "' + name + '" is not already defined.'); | ||
return this.addValidator(name, fn, priority, requirementsTransformer); | ||
} | ||
return this._setValidator(name, fn, priority, requirementsTransformer); | ||
}, | ||
removeValidator: function (name) { | ||
if (!this.validators[name]) | ||
ParsleyUtils.warn('Validator "' + name + '" is not defined.'); | ||
delete this.validators[name]; | ||
@@ -88,2 +97,13 @@ | ||
_setValidator: function (name, fn, priority, requirementsTransformer) { | ||
this.validators[name] = function (requirements) { | ||
return $.extend(new Validator.Assert().Callback(fn, requirements), { | ||
priority: priority, | ||
requirementsTransformer: requirementsTransformer | ||
}); | ||
}; | ||
return this; | ||
}, | ||
getErrorMessage: function (constraint) { | ||
@@ -93,8 +113,9 @@ var message; | ||
// Type constraints are a bit different, we have to match their requirements too to find right error message | ||
if ('type' === constraint.name) | ||
message = this.catalog[this.locale][constraint.name][constraint.requirements]; | ||
else | ||
if ('type' === constraint.name) { | ||
var typeMessages = this.catalog[this.locale][constraint.name] || {}; | ||
message = typeMessages[constraint.requirements]; | ||
} else | ||
message = this.formatMessage(this.catalog[this.locale][constraint.name], constraint.requirements); | ||
return '' !== message ? message : this.catalog[this.locale].defaultMessage; | ||
return message || this.catalog[this.locale].defaultMessage || this.catalog.en.defaultMessage; | ||
}, | ||
@@ -146,3 +167,38 @@ | ||
case 'url': | ||
assert = new Validator.Assert().Regexp('(https?:\\/\\/)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,24}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)', 'i'); | ||
// Thanks to https://gist.github.com/dperini/729294 | ||
// Voted best validator in https://mathiasbynens.be/demo/url-regex | ||
// Modified to make scheme optional and allow local IPs | ||
assert = new Validator.Assert().Regexp( | ||
"^" + | ||
// protocol identifier | ||
"(?:(?:https?|ftp)://)?" + // ** mod: make scheme optional | ||
// user:pass authentication | ||
"(?:\\S+(?::\\S*)?@)?" + | ||
"(?:" + | ||
// IP address exclusion | ||
// private & local networks | ||
// "(?!(?:10|127)(?:\\.\\d{1,3}){3})" + // ** mod: allow local networks | ||
// "(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" + // ** mod: allow local networks | ||
// "(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" + // ** mod: allow local networks | ||
// IP address dotted notation octets | ||
// excludes loopback network 0.0.0.0 | ||
// excludes reserved space >= 224.0.0.0 | ||
// excludes network & broacast addresses | ||
// (first & last IP address of each class) | ||
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" + | ||
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" + | ||
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" + | ||
"|" + | ||
// host name | ||
"(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" + | ||
// domain name | ||
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" + | ||
// TLD identifier | ||
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" + | ||
")" + | ||
// port number | ||
"(?::\\d{2,5})?" + | ||
// resource path | ||
"(?:/\\S*)?" + | ||
"$", 'i'); | ||
break; | ||
@@ -149,0 +205,0 @@ default: |
@@ -12,4 +12,7 @@ /*! | ||
define(['jquery'], factory); | ||
} else if (typeof exports === 'object') { | ||
// Node/CommonJS | ||
module.exports = factory(require('jquery')); | ||
} else { | ||
// No AMD. Register plugin with global jQuery object. | ||
// Register plugin with global jQuery object. | ||
factory(jQuery); | ||
@@ -16,0 +19,0 @@ } |
@@ -18,3 +18,3 @@ requirejs.config({ | ||
'validator': 'vendors/validator.js/dist/validator', | ||
'jquery': 'vendors/jquery/jquery', | ||
'jquery': 'vendors/jquery/dist/jquery', | ||
'expect': 'modules/expect.js/index', | ||
@@ -27,3 +27,3 @@ 'mocha': 'modules/mocha/mocha', | ||
shim: { | ||
'vendors/jquery/jquery': { | ||
'vendors/jquery/dist/jquery': { | ||
exports: '$' | ||
@@ -30,0 +30,0 @@ }, |
@@ -6,3 +6,3 @@ requirejs.config({ | ||
vendors: '../bower_components', | ||
jquery: '../bower_components/jquery/jquery' | ||
jquery: '../bower_components/jquery/dist/jquery' | ||
}, | ||
@@ -12,3 +12,3 @@ map: { | ||
parsley: 'dist/parsley', | ||
jquery: 'vendors/jquery/jquery' | ||
jquery: 'vendors/jquery/dist/jquery' | ||
} | ||
@@ -15,0 +15,0 @@ } |
@@ -5,3 +5,3 @@ requirejs.config({ | ||
paths: { | ||
jquery: 'bower_components/jquery/jquery', | ||
jquery: 'bower_components/jquery/dist/jquery', | ||
vendors: 'bower_components', | ||
@@ -20,3 +20,3 @@ modules: 'node_modules' | ||
shim: { | ||
'vendors/jquery/jquery': { | ||
'vendors/jquery/dist/jquery': { | ||
exports: '$' | ||
@@ -49,3 +49,3 @@ }, | ||
it('should have Parsley defined', function () { | ||
expect(window.Parsley).to.be.a('function'); | ||
expect(window.Parsley).to.be.a('object'); | ||
}); | ||
@@ -57,8 +57,5 @@ it('should register some window globals', function () { | ||
}); | ||
it('should throw an error if no element given', function () { | ||
expect(Parsley).to.throwException(); | ||
}); | ||
it('should return ParsleyForm instance if instantiated on a form', function () { | ||
$('body').append('<form id="element"></form>'); | ||
var parsleyInstance = new Parsley($('#element')); | ||
var parsleyInstance = $('#element').parsley(); | ||
expect(parsleyInstance).to.be.an('object'); | ||
@@ -69,3 +66,3 @@ expect(parsleyInstance.__class__).to.be('ParsleyForm'); | ||
$('body').append('<input id="element" />'); | ||
var parsleyInstance = new Parsley($('#element')); | ||
var parsleyInstance = $('#element').parsley(); | ||
expect(parsleyInstance).to.be.an('object'); | ||
@@ -72,0 +69,0 @@ expect(parsleyInstance.__class__).to.be('ParsleyField'); |
@@ -1,2 +0,2 @@ | ||
window.jQuery = $ = require('../../bower_components/jquery/jquery.js'); | ||
window.jQuery = $ = require('jquery.js'); | ||
require('../../dist/parsley.js'); | ||
@@ -11,3 +11,3 @@ | ||
it('should have Parsley defined', function () { | ||
expect(window.Parsley).to.be.a('function'); | ||
expect(window.Parsley).to.be.a('object'); | ||
}); | ||
@@ -19,8 +19,5 @@ it('should register some window globals', function () { | ||
}); | ||
it('should throw an error if no element given', function () { | ||
expect(Parsley).to.throwException(); | ||
}); | ||
it('should return ParsleyForm instance if instantiated on a form', function () { | ||
$('body').append('<form id="element"></form>'); | ||
var parsleyInstance = new Parsley($('#element')); | ||
var parsleyInstance = $('#element').parsley(); | ||
expect(parsleyInstance).to.be.an('object'); | ||
@@ -31,3 +28,3 @@ expect(parsleyInstance.__class__).to.be('ParsleyForm'); | ||
$('body').append('<input id="element" />'); | ||
var parsleyInstance = new Parsley($('#element')); | ||
var parsleyInstance = $('#element').parsley(); | ||
expect(parsleyInstance).to.be.an('object'); | ||
@@ -34,0 +31,0 @@ expect(parsleyInstance.__class__).to.be('ParsleyField'); |
define(function () { | ||
return function (Parsley) { | ||
return function () { | ||
describe('ParsleyAbstract', function () { | ||
it('should provide a actualizeOptions() method', function () { | ||
$('body').append('<input type="email" data-parsley-pattern="[A-F][0-9]{5}" data-parsley-required id="element" />'); | ||
var parsleyField = new Parsley('#element', { foo: 'bar' }); | ||
expect(parsleyField.options).have.key('pattern'); | ||
expect(parsleyField.options).have.key('required'); | ||
var parsleyField = $('#element').parsley({ foo: 'bar' }); | ||
expect(parsleyField.options.pattern).to.eql('[A-F][0-9]{5}'); | ||
expect(parsleyField.options.required).to.eql(''); | ||
@@ -13,29 +13,8 @@ $('#element').removeAttr('data-parsley-pattern'); | ||
expect(parsleyField.options).not.to.have.key('pattern'); | ||
expect(parsleyField.options).have.key('required'); | ||
expect(parsleyField.options.pattern).to.be(undefined); | ||
expect(parsleyField.options.required).to.eql(''); | ||
}); | ||
it('should use subscribe()', function (done) { | ||
$('body').append('<input type="email" data-parsley-pattern="[A-F][0-9]{5}" data-parsley-required id="element" />'); | ||
var parsleyField = new Parsley('#element'); | ||
parsleyField.subscribe('parsley:field:foo', function (instance, val) { | ||
expect(instance.__id__).to.be(parsleyField.__id__); | ||
expect(val).to.be('baz'); | ||
done(); | ||
}); | ||
$.emit('parsley:field:foo', 'bar'); | ||
$.emit('parsley:field:foo', parsleyField, 'baz'); | ||
}); | ||
it('should use unsubscribe()', function () { | ||
$('body').append('<input type="email" id="element" />'); | ||
var parsleyInstance = $('#element').parsley(); | ||
parsleyInstance.subscribe('foo', function () { return 'bar'; }); | ||
expect($.subscribed().foo.length).to.be(1); | ||
parsleyInstance.unsubscribe('foo'); | ||
expect($.subscribed().foo.length).to.be(0); | ||
}); | ||
it('should use reset() on field', function () { | ||
$('body').append('<input type="email" data-parsley-pattern="[A-F][0-9]{5}" data-parsley-required id="element" />'); | ||
var parsleyField = new Parsley('#element'); | ||
var parsleyField = $('#element').parsley(); | ||
parsleyField.validate(); | ||
@@ -54,11 +33,11 @@ expect($('#parsley-id-' + parsleyField.__id__ + ' li').length).to.be(1); | ||
'</form>'); | ||
var parsleyForm = new Parsley($('#element')); | ||
var parsleyForm = $('#element').parsley(); | ||
parsleyForm.validate(); | ||
expect($('#parsley-id-' + $('#field1').psly().__id__ + ' li').length).to.be(1); | ||
parsleyForm.subscribe('parsley:form:reset', function () { | ||
$('#element').parsley().on('form:reset', function () { | ||
done(); | ||
}); | ||
parsleyForm.reset(); | ||
parsleyForm.reset(); | ||
expect($('#parsley-id-' + $('#field1').psly().__id__ + ' li').length).to.be(0); | ||
@@ -68,5 +47,5 @@ }); | ||
$('body').append('<input type="email" data-parsley-pattern="[A-F][0-9]{5}" data-parsley-required id="element" />'); | ||
var parsleyField = new Parsley('#element'); | ||
var parsleyField = $('#element').parsley(); | ||
parsleyField.subscribe('parsley:field:destroy', function () { | ||
$('#element').parsley().on('field:destroy', function () { | ||
done(); | ||
@@ -89,41 +68,41 @@ }); | ||
'</form>'); | ||
var parsleyForm = new Parsley($('#element')); | ||
var fieldEventsCount = 0; | ||
var parsleyForm = $('#element').parsley(); | ||
var fieldEventsCount = 0, formEventsCount = 0; | ||
// Test that a subscribed field event on parent form would be triggered by fields too | ||
// Here we only have field1 and field2 as valid parsley fields | ||
parsleyForm.subscribe('parsley:field:destroy', function () { | ||
$('#element').parsley().on('field:destroy', function () { | ||
fieldEventsCount++; | ||
}); | ||
parsleyForm.subscribe('parsley:form:destroy', function () { | ||
// we properly triggered before the 2 field:destroy events for this form | ||
expect(fieldEventsCount).to.be(2); | ||
$('#element').parsley().on('form:destroy', function () { | ||
formEventsCount++; | ||
}); | ||
// we should never enter here since parsley form instance is destroyed | ||
$.listen('parsley:form:validate', function () { | ||
expect(true).to.be(false); | ||
}); | ||
expect($('#element').data('Parsley')).to.have.key('__class__'); | ||
expect($('#element').data('Parsley').__class__).to.be('ParsleyForm'); | ||
expect($('#field1').data('Parsley')).to.have.key('__class__'); | ||
expect($('#field1').data('Parsley').__class__).to.be('ParsleyField'); | ||
// test that a submit event does not trigger parsley validation anymore | ||
$('#element').on('submit', function (e) { | ||
e.preventDefault(); | ||
parsleyForm.destroy(); | ||
expect($('#element').data('Parsley')).to.be(undefined); | ||
expect($('#field1').data('Parsley')).to.be(undefined); | ||
expect(fieldEventsCount).to.be(2); | ||
expect(formEventsCount).to.be(1); | ||
// we should never enter here since parsley form instance is destroyed | ||
window.Parsley.on('form:validate', function () { | ||
expect(true).to.be(false); | ||
}); | ||
$.unsubscribeAll('parsley:form:validate'); | ||
done(); | ||
}); | ||
// test that a submit event does not trigger parsley validation anymore | ||
$('#element').on('submit', function (e) { | ||
e.preventDefault(); | ||
$('#element').submit(); | ||
expect($('#element').data('Parsley')).to.be(undefined); | ||
expect($('#field1').data('Parsley')).to.be(undefined); | ||
window.Parsley.off('form:validate'); | ||
done(); | ||
}); | ||
expect($('#element').data('Parsley')).to.have.key('__class__'); | ||
expect($('#element').data('Parsley').__class__).to.be('ParsleyForm'); | ||
expect($('#field1').data('Parsley')).to.have.key('__class__'); | ||
expect($('#field1').data('Parsley').__class__).to.be('ParsleyField'); | ||
parsleyForm.destroy(); | ||
$('#element').submit(); | ||
}); | ||
@@ -130,0 +109,0 @@ afterEach(function () { |
@@ -5,2 +5,3 @@ define('features/extra', [ | ||
'extra/validator/words', | ||
'extra/validator/notequalto', | ||
], function () { | ||
@@ -14,7 +15,12 @@ | ||
expect(parsleyValidator.validate('', parsleyValidator.validators.dateiso())).not.to.be(true); | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.dateiso())).not.to.be(true); | ||
expect(parsleyValidator.validate('1986-30-01', parsleyValidator.validators.dateiso())).not.to.be(true); | ||
expect(parsleyValidator.validate('1986-12-45', parsleyValidator.validators.dateiso())).not.to.be(true); | ||
expect(parsleyValidator.validate('1986-12-01', parsleyValidator.validators.dateiso())).to.be(true); | ||
var expectValidation = function(value, name, requirements) { | ||
var validator = parsleyValidator.validators[name](requirements); | ||
return expect(parsleyValidator.validate(value, validator)); | ||
}; | ||
expectValidation('', 'dateiso').not.to.be(true); | ||
expectValidation('foo', 'dateiso').not.to.be(true); | ||
expectValidation('1986-30-01', 'dateiso').not.to.be(true); | ||
expectValidation('1986-12-45', 'dateiso').not.to.be(true); | ||
expectValidation('1986-12-01', 'dateiso').to.be(true); | ||
}); | ||
@@ -154,2 +160,16 @@ it('should have gt validator', function () { | ||
}); | ||
it('should have a notequalto validator', function () { | ||
$('body').append('<input type="text" id="element" data-parsley-notequalto="hello" value="hello"/>' | ||
+ '<input type="text" class="fixture not" value="world"/>'); | ||
var p = $('#element').psly(); | ||
expect(p.isValid()).to.be(false); | ||
$('#element').val('world'); | ||
expect(p.isValid()).to.be(true); | ||
$('#element').attr('data-parsley-notequalto', '.not'); | ||
expect(p.isValid()).to.be(false); | ||
$('#element').val('hello'); | ||
expect(p.isValid()).to.be(true); | ||
}); | ||
it('should have a bind.js plugin allowing to give pure json validation config to parsley constructor', function (done) { | ||
@@ -187,3 +207,3 @@ require(['extra/plugin/bind'], function () { | ||
afterEach(function () { | ||
$('#element, .parsley-errors-list').remove(); | ||
$('#element, .fixture, .parsley-errors-list').remove(); | ||
}); | ||
@@ -190,0 +210,0 @@ }); |
define(function () { | ||
return function (ParsleyField, Parsley) { | ||
return function (ParsleyField) { | ||
describe('ParsleyField', function () { | ||
@@ -12,3 +12,3 @@ it('should be a function', function () { | ||
$('body').append('<input type="text" id="element" data-parsley-required />'); | ||
var parsleyField = new Parsley($('#element')); | ||
var parsleyField = $('#element').parsley(); | ||
expect(parsleyField.constraints.length).to.be(1); | ||
@@ -22,3 +22,3 @@ expect(parsleyField.constraints[0].__class__).to.be('Required'); | ||
$('body').append('<input type="email" id="element" />'); | ||
var parsleyField = new Parsley($('#element')); | ||
var parsleyField = $('#element').parsley(); | ||
expect(parsleyField.constraints.length).to.be(1); | ||
@@ -30,5 +30,15 @@ expect(parsleyField.constraints[0].__class__).to.be('Email'); | ||
}); | ||
it('should ignore unknown types', function () { | ||
$('body').append('<input type="" id="element" />'); | ||
var parsleyField = $('#element').parsley(); | ||
expect(parsleyField.constraints.length).to.be(0); | ||
}); | ||
it('should ignore mistyped types', function () { | ||
$('body').append('<input type=" email" id="element" />'); | ||
var parsleyField = $('#element').parsley(); | ||
expect(parsleyField.constraints.length).to.be(0); | ||
}); | ||
it('should have a proper addConstraint() javascript method', function () { | ||
$('body').append('<input type="text" id="element" />'); | ||
var parsleyField = new Parsley($('#element')) | ||
var parsleyField = $('#element').parsley() | ||
.addConstraint('required', true); | ||
@@ -52,3 +62,3 @@ expect(parsleyField.constraints.length).to.be(1); | ||
$('body').append('<input type="text" id="element" />'); | ||
var parsleyField = new Parsley($('#element')) | ||
var parsleyField = $('#element').parsley() | ||
.addConstraint('required', true); | ||
@@ -65,3 +75,3 @@ | ||
$('body').append('<input type="text" id="element" />'); | ||
var parsleyField = new Parsley($('#element')) | ||
var parsleyField = $('#element').parsley() | ||
.addConstraint('required', true) | ||
@@ -74,5 +84,5 @@ .addConstraint('notblank', true) | ||
}); | ||
it('should return an empty array for fields withoud constraints', function () { | ||
it('should return true for fields without constraints', function () { | ||
$('body').append('<input type="text" id="element" value="hola" data-parsley-minlength="5" />'); | ||
var parsleyField = new Parsley($('#element')); | ||
var parsleyField = $('#element').parsley(); | ||
// Start with some validation errors: | ||
@@ -82,7 +92,7 @@ expect(parsleyField.isValid()).to.eql(false); | ||
$('#element').removeAttr('data-parsley-minlength'); | ||
expect(parsleyField.isValid()).to.eql([]); | ||
expect(parsleyField.isValid()).to.be(true); | ||
}); | ||
it('should properly bind HTML5 supported constraints', function () { | ||
$('body').append('<input type="email" pattern="\\w+" id="element" required min="5" max="100" minlength="1" maxlength="3" />'); | ||
var parsleyField = new Parsley($('#element')); | ||
var parsleyField = $('#element').parsley(); | ||
// 5 validators: type=email, pattern, required, (min+max => range) and (minlength+maxlength => length) | ||
@@ -99,3 +109,3 @@ expect(parsleyField.constraints.length).to.be(5); | ||
$('body').append('<input type="number" id="element" />'); | ||
var parsleyField = new Parsley($('#element')); | ||
var parsleyField = $('#element').parsley(); | ||
expect(parsleyField.constraints[0].requirements).to.be('integer'); | ||
@@ -105,3 +115,3 @@ }); | ||
$('body').append('<input type="number" id="element" step="3" />'); | ||
var parsleyField = new Parsley($('#element')); | ||
var parsleyField = $('#element').parsley(); | ||
expect(parsleyField.constraints[0].requirements).to.be('integer'); | ||
@@ -111,3 +121,3 @@ }); | ||
$('body').append('<input type="number" id="element" step="0.3" />'); | ||
var parsleyField = new Parsley($('#element')); | ||
var parsleyField = $('#element').parsley(); | ||
expect(parsleyField.constraints[0].requirements).to.be('number'); | ||
@@ -117,3 +127,3 @@ }); | ||
$('body').append('<input type="number" id="element" step="any" />'); | ||
var parsleyField = new Parsley($('#element')); | ||
var parsleyField = $('#element').parsley(); | ||
expect(parsleyField.constraints[0].requirements).to.be('number'); | ||
@@ -123,3 +133,3 @@ }); | ||
$('body').append('<input type="text" id="element" value="" />'); | ||
var parsleyField = new Parsley($('#element')) | ||
var parsleyField = $('#element').parsley() | ||
.addConstraint('required', true); | ||
@@ -132,3 +142,3 @@ expect(parsleyField.isValid()).to.be(false); | ||
$('body').append('<input type="text" id="element" value="foo" />'); | ||
var parsleyField = new Parsley($('#element')) | ||
var parsleyField = $('#element').parsley() | ||
.addConstraint('type', 'email'); | ||
@@ -143,3 +153,3 @@ expect(parsleyField.isValid()).to.be(false); | ||
$('body').append('<input type="text" id="element" value="" />'); | ||
ParsleyValidator.addValidator('multiple', function (value, multiple) { | ||
window.ParsleyValidator.addValidator('ismultiple', function (value, multiple) { | ||
if (!isNaN(parseFloat(value)) && isFinite(value)) | ||
@@ -151,5 +161,5 @@ return !(Number(value) % multiple); | ||
var parsleyField = new Parsley($('#element')) | ||
.addConstraint('multiple', 2); | ||
expect(parsleyField.isValid()).to.eql([]); | ||
var parsleyField = $('#element').parsley() | ||
.addConstraint('ismultiple', 2); | ||
expect(parsleyField.isValid()).to.eql(true); | ||
$('#element').val('1'); | ||
@@ -159,14 +169,14 @@ expect(parsleyField.isValid()).to.be(false); | ||
expect(parsleyField.isValid()).to.be(true); | ||
parsleyField.updateConstraint('multiple', 3); | ||
parsleyField.updateConstraint('ismultiple', 3); | ||
expect(parsleyField.isValid()).to.be(false); | ||
$('#element').val('9'); | ||
expect(parsleyField.isValid()).to.be(true); | ||
ParsleyValidator.removeValidator('multiple'); | ||
window.ParsleyValidator.removeValidator('ismultiple'); | ||
}); | ||
it('should properly compute constraints on each validation', function () { | ||
$('body').append('<input type="email" data-parsley-required id="element" />'); | ||
ParsleyValidator.addValidator('foobazer', function (value) { | ||
window.ParsleyValidator.addValidator('foobazer', function (value) { | ||
return 'foobar' === value; | ||
}, 2); | ||
ParsleyValidator.addValidator('multiple', function (value, multiple) { | ||
window.ParsleyValidator.addValidator('ismultiple', function (value, multiple) { | ||
if (!isNaN(parseFloat(value)) && isFinite(value)) | ||
@@ -178,4 +188,4 @@ return !(Number(value) % multiple); | ||
var parsleyField = new Parsley($('#element')) | ||
.addConstraint('multiple', 4) | ||
var parsleyField = $('#element').parsley() | ||
.addConstraint('ismultiple', 4) | ||
.addConstraint('foobazer', true); | ||
@@ -188,11 +198,11 @@ parsleyField.refreshConstraints(); | ||
parsleyField | ||
.removeConstraint('multiple') | ||
.removeConstraint('ismultiple') | ||
.refreshConstraints(); | ||
expect(parsleyField.constraints.length).to.be(2); | ||
ParsleyValidator.removeValidator('foobazer'); | ||
ParsleyValidator.removeValidator('multiple'); | ||
window.ParsleyValidator.removeValidator('foobazer'); | ||
window.ParsleyValidator.removeValidator('ismultiple'); | ||
}); | ||
it('should handle constraints priorities on validation', function () { | ||
$('body').append('<input type="email" pattern="[A-F][0-9]{5}" required id="element" />'); | ||
var parsleyField = new Parsley($('#element')); | ||
var parsleyField = $('#element').parsley(); | ||
expect(parsleyField.isValid()).to.be(false); | ||
@@ -212,52 +222,56 @@ expect(parsleyField.validationResult.length).to.be(1); | ||
$('body').append('<input type="email" pattern="[A-F][0-9]{5}" required id="element" />'); | ||
var parsleyField = new Parsley($('#element'), { priorityEnabled: false }); | ||
var parsleyField = $('#element').parsley({ priorityEnabled: false }); | ||
expect(parsleyField.isValid()).to.be(false); | ||
expect(parsleyField.validationResult.length).to.be(3); | ||
}); | ||
it('should fire parsley:field:validate event', function (done) { | ||
it('should trigger field:validate event', function (done) { | ||
$('body').append('<input type="email" pattern="[A-F][0-9]{5}" required id="element" />'); | ||
$.listenTo($('#element').psly(), 'parsley:field:validate', function (instance) { | ||
$('#element').psly() | ||
.on('field:validate', function () { | ||
// we are before validation! | ||
expect(instance.validationResult.length).to.be(0); | ||
expect(this.validationResult.length).to.be(0); | ||
done(); | ||
}); | ||
$('#element').psly().validate(); | ||
}) | ||
.validate(); | ||
}); | ||
it('should fire parsley:field:validated event', function (done) { | ||
it('should trigger field:validated event', function (done) { | ||
$('body').append('<input type="email" pattern="[A-F][0-9]{5}" required id="element" />'); | ||
$.listenTo($('#element').psly(), 'parsley:field:validated', function (instance) { | ||
$('#element').psly() | ||
.on('field:validated', function () { | ||
// we are after validation! | ||
expect(instance.validationResult.length).to.be(1); | ||
expect(this.validationResult.length).to.be(1); | ||
done(); | ||
}); | ||
$('#element').psly().validate(); | ||
}) | ||
.validate(); | ||
}); | ||
it('should fire parsley:field:error event', function (done) { | ||
it('should trigger field:error event', function (done) { | ||
$('body').append('<input type="email" pattern="[A-F][0-9]{5}" required id="element" />'); | ||
$.listenTo($('#element').psly(), 'parsley:field:error', function (instance) { | ||
expect(instance.validationResult.length).to.be(1); | ||
$('#element').psly() | ||
.on('field:error', function () { | ||
expect(this.validationResult.length).to.be(1); | ||
done(); | ||
}); | ||
$('#element').psly().validate(); | ||
}) | ||
.validate(); | ||
}); | ||
it('should fire parsley:field:success event', function (done) { | ||
it('should trigger parsley:field:success event', function (done) { | ||
$('body').append('<input type="email" required id="element" value="foo@bar.baz" />'); | ||
$.listenTo($('#element').psly(), 'parsley:field:success', function (instance) { | ||
expect(instance.validationResult).to.be(true); | ||
$('#element').psly() | ||
.on('field:success', function () { | ||
expect(this.validationResult).to.be(true); | ||
done(); | ||
}); | ||
$('#element').psly().validate(); | ||
}) | ||
.validate(); | ||
}); | ||
it('should have validateIfEmpty option', function () { | ||
$('body').append('<input type="email" data-parsley-rangelength="[5, 10]" id="element" />'); | ||
expect($('#element').psly().isValid()).to.be.eql([]); | ||
expect($('#element').psly().isValid()).to.be.eql(true); | ||
$('#element').attr('data-parsley-validate-if-empty', ''); | ||
expect($('#element').psly().isValid()).to.be.eql(false); | ||
}); | ||
it('should allow `this.value` alteration with parsley:field:validate event', function () { | ||
it('should allow `this.value` alteration with field:validate.parsley event', function () { | ||
$('body').append('<input type="email" required id="element" value="foo@bar.baz" />'); | ||
expect($('#element').parsley().validate()).to.be(true); | ||
$('#element').parsley().subscribe('parsley:field:validate', function (fieldInstance) { | ||
fieldInstance.value = ''; | ||
$('#element').parsley().on('field:validate', function () { | ||
this.value = ''; | ||
}); | ||
@@ -269,7 +283,14 @@ | ||
$('body').append('<input type="email" id="element" />'); | ||
expect($('#element').parsley().isValid()).to.be.eql([]); | ||
expect($('#element').parsley().validate()).to.be.eql([]); | ||
expect($('#element').parsley().isValid()).to.be.eql(true); | ||
expect($('#element').parsley().validate()).to.be.eql(true); | ||
expect($('#element').parsley().isValid(true)).to.be(false); | ||
expect($('#element').parsley().validate(true).length).to.be(1); | ||
}); | ||
it('should allow passing a specific value to `isValid` method', function () { | ||
expect($('<input type="email" value="">').parsley().isValid(false)).to.be(true); | ||
expect($('<input type="email" value="foo">').parsley().isValid()).to.be(false); | ||
expect($('<input type="email" value="foo">').parsley().isValid(false, "")).to.be(true); | ||
expect($('<input type="email" value="">').parsley().isValid(true)).to.be(false); | ||
expect($('<input type="email" value="foo">').parsley().isValid(true, "")).to.be(false); | ||
}); | ||
it('should have a trim-value option', function () { | ||
@@ -281,2 +302,26 @@ $('body').append('<input type="text" id="element" value=" foo " />'); | ||
}); | ||
it('should inherit options from the form, even if the form is bound after', function () { | ||
$('body').append('<form id="element" data-parsley-required>' + | ||
'<input type="text"/></form>'); | ||
var psly = $('#element input').parsley(); | ||
expect(psly.isValid()).not.to.be(false); | ||
$('#element').parsley(); | ||
expect(psly.isValid()).to.be(false); | ||
}); | ||
it('should have options that can be set easily', function () { | ||
var psly = $('<input type="text"/>').parsley(); | ||
psly.options.required = true; | ||
expect(psly.isValid()).to.be(false); | ||
}); | ||
it('should have a value option', function () { | ||
$('body').append('<input type="text" id="element"/>'); | ||
expect($('#element').parsley({value: 'foo'}).getValue()).to.be('foo'); | ||
}); | ||
it('should accept a function as value option', function () { | ||
$('body').append('<input type="text" id="element"/>'); | ||
var str = 'fo'; | ||
var parsley = $('#element').parsley({value: function () { return str = str + 'o' } }); | ||
expect(parsley.getValue()).to.be('foo'); | ||
expect(parsley.getValue()).to.be('fooo'); | ||
}); | ||
it('should properly handle null or undefined values', function () { | ||
@@ -287,4 +332,2 @@ $('body').append('<input type="text" id="element" required value/>'); | ||
afterEach(function () { | ||
window.ParsleyConfig = { i18n: window.ParsleyConfig.i18n, validators: window.ParsleyConfig.validators }; | ||
$('#element, .parsley-errors-list').remove(); | ||
@@ -291,0 +334,0 @@ }); |
define(function () { | ||
return function (ParsleyForm, Parsley) { | ||
return function (ParsleyForm) { | ||
describe('ParsleyForm', function () { | ||
@@ -7,5 +7,2 @@ it('should be a function', function () { | ||
}); | ||
it('should throw an error if no element given', function () { | ||
expect(ParsleyForm).to.throwException(); | ||
}); | ||
it('should bind parsleyFields children', function () { | ||
@@ -18,3 +15,3 @@ $('body').append( | ||
'</form>'); | ||
var parsleyForm = new Parsley($('#element')); | ||
var parsleyForm = $('#element').parsley(); | ||
expect(parsleyForm.fields.length).to.be(2); | ||
@@ -30,5 +27,6 @@ }); | ||
'<input id="field3" disabled />' + // Disabled, excluded buy custom options below | ||
'<input id="field-excluded" data-parsley-excluded="true" />' + // Disabled, excluded buy custom options below | ||
'<input type="submit"/>' + // Excluded field, not valid | ||
'</form>'); | ||
var parsleyForm = new Parsley($('#element'), { excluded: '[disabled], input[type=button], input[type=submit], input[type=reset]' }); | ||
var parsleyForm = $('#element').parsley({ excluded: '[disabled], input[type=button], input[type=submit], input[type=reset]' }); | ||
expect(parsleyForm.fields.length).to.be(2); | ||
@@ -43,9 +41,9 @@ }); | ||
'</form>'); | ||
var parsleyForm = new Parsley($('#element')); | ||
var parsleyForm = $('#element').parsley(); | ||
expect(parsleyForm.fields.length).to.be(2); | ||
expect(new Parsley('#field1').options.trigger).to.be('change'); | ||
expect(new Parsley('#field1').options).to.have.key('required'); | ||
expect(new Parsley('#field1').options).to.not.have.key('notblank'); | ||
expect(new Parsley('#field3').options).to.have.key('notblank'); | ||
expect(new Parsley('#field3').options).to.not.have.key('required'); | ||
expect($('#field1').parsley().options.trigger).to.be('change'); | ||
expect($('#field1').parsley().options.required).to.eql(true); | ||
expect($('#field1').parsley().options.notblank).to.be(undefined); | ||
expect($('#field3').parsley().options.notblank).to.eql(true); | ||
expect($('#field3').parsley().options.required).to.be(undefined); | ||
}); | ||
@@ -59,3 +57,3 @@ it('should properly store validation state after `validate()`', function () { | ||
'</form>'); | ||
var parsleyForm = new Parsley($('#element')); | ||
var parsleyForm = $('#element').parsley(); | ||
parsleyForm.validate(); | ||
@@ -74,3 +72,3 @@ expect(parsleyForm.validationResult).to.be(false); | ||
'</form>'); | ||
var parsleyForm = new Parsley($('#element')); | ||
var parsleyForm = $('#element').parsley(); | ||
expect(parsleyForm.isValid()).to.be(false); | ||
@@ -89,3 +87,3 @@ $('#field1').val('value'); | ||
'</form>'); | ||
var parsleyForm = new Parsley($('#element')); | ||
var parsleyForm = $('#element').parsley(); | ||
expect(parsleyForm.isValid()).to.be(false); | ||
@@ -111,8 +109,8 @@ $('#field1').val('value'); | ||
'</form>'); | ||
var parsleyForm = new Parsley($('#element')); | ||
var parsleyForm = $('#element').parsley(); | ||
// parsley.remote hack because if valid, parsley remote re-send form | ||
parsleyForm.subscribe('parsley:form:validate', function (formInstance) { | ||
if (formInstance.asyncSupport) | ||
formInstance.submitEvent._originalPreventDefault(); | ||
$('#element').parsley().on('form:validate', function () { | ||
if (this.asyncSupport) | ||
this.submitEvent._originalPreventDefault(); | ||
}); | ||
@@ -163,3 +161,3 @@ | ||
it('should fire the right callbacks in the right order', function () { | ||
var $form = $('<form><input type="string" required /><form>').appendTo($('body')); | ||
var $form = $('<form id="element"><input type="string" required /><form>').appendTo($('body')); | ||
$form.on('submit', function (e) { | ||
@@ -170,17 +168,17 @@ e.preventDefault(); | ||
var callbacks = []; | ||
var parsleyInstance = $form.parsley(); | ||
$.each(['validate', 'error', 'success', 'validated'], function(i, cb) { | ||
parsleyInstance.subscribe('parsley:form:' + cb, function() { | ||
$.each(['validate', 'error', 'success', 'validated', 'submit'], function (i, cb) { | ||
$form.parsley().on('form:' + cb, function () { | ||
callbacks.push(cb); | ||
}); | ||
}); | ||
$form.parsley(); | ||
$form.submit(); | ||
$form.find('input').val('Hello'); | ||
$form.submit(); | ||
expect(callbacks.join()).to.be('validate,error,validated,validate,success,validated'); | ||
expect(callbacks.join()).to.be('validate,error,validated,validate,success,validated,submit'); | ||
}); | ||
it('should fire "parsley:form:validate" to give the opportunity for changes before validation occurs', function() { | ||
it('should fire "form:validate.parsley" to give the opportunity for changes before validation occurs', function() { | ||
var $form = $('<form><input type="string" required /><form>').appendTo($('body')); | ||
$form.parsley().subscribe('parsley:form:validate', function(psly) { | ||
psly.$element.find('input').remove(); | ||
$form.parsley().on('form:validate', function () { | ||
this.$element.find('input').remove(); | ||
}); | ||
@@ -191,15 +189,67 @@ expect($form.parsley().validate()).to.be(true); | ||
$('body').append('<form id="element"><input type="text" required/></form>'); | ||
var parsleyInstance = $('#element').parsley(); | ||
var parsleyInstance = $('#element').parsley() | ||
.on('form:validated', function () { | ||
done(); | ||
}); | ||
$('#element').on('submit', function () { | ||
// It sould never pass here! | ||
expect(true).to.be(false); | ||
}); | ||
}) | ||
.submit(); | ||
}); | ||
parsleyInstance.subscribe('parsley:form:validated', function () { | ||
it('should fire form:submit.event and be interruptable when validated', function (done) { | ||
$('<form id="element"></form>') | ||
.appendTo('body') | ||
.parsley() | ||
.on('form:submit', function() { | ||
done(); | ||
return false; | ||
}); | ||
$('#element').submit(); | ||
}); | ||
it('should fire field:reset event if fields are removed or excluded', function () { | ||
var parsleyInstance, | ||
steps = [], | ||
step = 'init', | ||
parsleyForm = $('<form id="element"><input type="text" required></form>') | ||
.appendTo('body') | ||
.parsley() | ||
.on('field:reset', function() { | ||
steps.push('form: ' + step); | ||
expect(this).to.be(parsleyInstance); | ||
}) | ||
; | ||
parsleyInstance = $('#element input').parsley() | ||
.on('field:reset', function() { | ||
steps.push('field: ' + step); | ||
expect(this).to.be(parsleyInstance); | ||
}); | ||
parsleyForm.validate(); | ||
parsleyForm.validate(); | ||
parsleyForm.options.excluded = '[required]'; | ||
step = 'excluded'; | ||
parsleyForm.validate(); | ||
parsleyForm.validate(); | ||
parsleyForm.options.excluded = ''; | ||
step = 'not excluded'; | ||
parsleyForm.validate(); | ||
parsleyForm.validate(); | ||
var $i = $('#element input').detach(); | ||
step = 'detached'; | ||
parsleyForm.validate(); | ||
parsleyForm.validate(); | ||
$i.appendTo('form'); | ||
step = 'reattached'; | ||
parsleyForm.validate(); | ||
parsleyForm.validate(); | ||
$i.remove(); | ||
step = 'removed'; | ||
parsleyForm.validate(); | ||
parsleyForm.validate(); | ||
expect(steps).to.eql(['field: excluded', 'form: excluded', 'field: detached', 'form: detached', 'field: removed', 'form: removed']); | ||
}); | ||
afterEach(function () { | ||
@@ -206,0 +256,0 @@ $('#element').remove(); |
@@ -10,5 +10,8 @@ define(function () { | ||
'<input type="checkbox" name="$hello$" id="check3" value="3" />' + | ||
'<input type="checkbox" name="hello world[ x ]" id="check4" value="4" />' + | ||
'<input type="checkbox" value="foo" />' + | ||
'</form>'); | ||
$('#element').parsley(); | ||
expectWarning(function() { | ||
$('#element').parsley(); | ||
}); | ||
}); | ||
@@ -36,3 +39,5 @@ it('should return same ParsleyMultiple instance for each field in same multiple group, and it should count as one field in form', function () { | ||
'</form>'); | ||
$('#element').parsley(); | ||
expectWarning(function(){ | ||
$('#element').parsley(); | ||
}); | ||
expect($('#check1').attr('data-parsley-multiple')).to.be('check'); | ||
@@ -91,3 +96,3 @@ expect($('#check2').attr('data-parsley-multiple')).to.be('check'); | ||
// if not required, field is optional and do not fail | ||
expect($('#check1').parsley().isValid()).to.be.eql([]); | ||
expect($('#check1').parsley().isValid()).to.be.eql(true); | ||
expect($('#element').parsley().isValid()).to.be(true); | ||
@@ -111,3 +116,3 @@ | ||
'</select>'); | ||
var parsleyField = new Parsley($('#element')); | ||
var parsleyField = $('#element').parsley(); | ||
expect(parsleyField.__class__).to.be('ParsleyFieldMultiple'); | ||
@@ -134,6 +139,7 @@ expect(parsleyField.options.multiple).to.be('foo'); | ||
$('body').append('<input type="radio" value="foo" />'); | ||
window.console.warn = sinon.spy(); | ||
var parsleyInstance = $('input[type=radio]').psly(); | ||
var parsleyInstance = | ||
expectWarning(function() { | ||
return $('input[type=radio]').psly(); | ||
}); | ||
expect(parsleyInstance.__class__).to.be('Parsley'); | ||
expect(window.console.warn.called).to.be(true); | ||
$('input[type=radio]').attr('id', 'element'); | ||
@@ -192,5 +198,9 @@ parsleyInstance = $('#element').parsley(); | ||
'<input name="foo" id="check" type="checkbox" value="1"/>' + | ||
'<input name="foo" id="check-2" type="checkbox" value="2"/>' + | ||
'</form>' + | ||
'<form id="element-2">' + | ||
'<input name="foo" id="other-check" type="checkbox" value="3"/>' + | ||
'</form>'); | ||
$('#element').parsley(); | ||
expect($('#check').parsley().$elements.length).to.be(1); | ||
$('#element, #element-2').parsley(); | ||
expect($('#check').parsley().$elements.length).to.be(2); | ||
}); | ||
@@ -228,5 +238,3 @@ it('should handle form namespace configuration inheritance and click events while multiple binding through ParsleyForm', function () { | ||
afterEach(function () { | ||
window.ParsleyConfig = { i18n: window.ParsleyConfig.i18n, validators: window.ParsleyConfig.validators }; | ||
$('#element, .parsley-errors-list').remove(); | ||
$('#element, #element-2, .parsley-errors-list').remove(); | ||
}); | ||
@@ -233,0 +241,0 @@ }); |
define(function () { | ||
return function (Parsley) { | ||
describe('ParsleyBase', function () { | ||
return function (ParsleyFactory) { | ||
describe('ParsleyFactory', function () { | ||
it('should be a function', function () { | ||
expect(Parsley).to.be.a('function'); | ||
expect(ParsleyFactory).to.be.a('function'); | ||
}); | ||
@@ -13,7 +13,7 @@ it('should register some window globals', function () { | ||
it('should throw an error if no element given', function () { | ||
expect(Parsley).to.throwException(); | ||
expect(ParsleyFactory).to.throwException(); | ||
}); | ||
it('should return ParsleyForm instance if instantiated on a form', function () { | ||
$('body').append('<form id="element"></form>'); | ||
var parsleyInstance = new Parsley($('#element')); | ||
var parsleyInstance = new ParsleyFactory($('#element')); | ||
expect(parsleyInstance).to.be.an('object'); | ||
@@ -24,18 +24,17 @@ expect(parsleyInstance.__class__).to.be('ParsleyForm'); | ||
$('body').append('<input id="element" />'); | ||
var parsleyInstance = new Parsley($('#element')); | ||
var parsleyInstance = new ParsleyFactory($('#element')); | ||
expect(parsleyInstance).to.be.an('object'); | ||
expect(parsleyInstance.__class__).to.be('ParsleyField'); | ||
}); | ||
it('should return Parsley if instantiated on an unsupported element', function () { | ||
it('should return ParsleyField even if instantiated on an unsupported element', function () { | ||
$('body').append('<div id="element"></div>'); | ||
var parsleyInstance = new Parsley($('#element')); | ||
var parsleyInstance = new ParsleyFactory($('#element')); | ||
expect(parsleyInstance).to.be.an('object'); | ||
expect(parsleyInstance.__class__).to.be('Parsley'); | ||
expect(parsleyInstance.__class__).to.be('ParsleyField'); | ||
}); | ||
it('should return Parsley instance if instantiated on an excluded field type, and do not have an errors container', function () { | ||
it('should return ParsleyField instance even if instantiated on an excluded field type, and do not have an errors container', function () { | ||
$('body').append('<input type="submit" id="element" />'); | ||
var parsleyInstance = new Parsley($('#element')); | ||
var parsleyInstance = new ParsleyFactory($('#element')); | ||
expect(parsleyInstance).to.be.an('object'); | ||
expect(parsleyInstance.__class__).to.be('Parsley'); | ||
expect($('#parsley-id-' + parsleyInstance.__id__).length).to.be(0); | ||
expect(parsleyInstance.__class__).to.be('ParsleyField'); | ||
}); | ||
@@ -55,3 +54,3 @@ it('should have excluded fields by default', function () { | ||
$('body').append('<div id="element" data-parsley-validate></div>'); | ||
var parsleyInstance = new Parsley($('#element')); | ||
var parsleyInstance = new ParsleyFactory($('#element')); | ||
expect(parsleyInstance).to.be.an('object'); | ||
@@ -64,18 +63,21 @@ expect(parsleyInstance.__class__).to.be('ParsleyForm'); | ||
// default ParsleyOptions.namespace | ||
expect(new Parsley($('#element')).OptionsFactory.staticOptions.namespace).to.be('data-parsley-'); | ||
expect(new ParsleyFactory($('#element')).options.namespace).to.be('data-parsley-'); | ||
// global JS config | ||
$('#element').parsley().destroy() | ||
window.ParsleyConfig.namespace = 'data-foo-'; | ||
expect(new Parsley($('#element')).OptionsFactory.staticOptions.namespace).to.be('data-foo-'); | ||
expect(new ParsleyFactory($('#element')).options.namespace).to.be('data-foo-'); | ||
// option on the go | ||
expect(new Parsley($('#element'), { | ||
$('#element').parsley().destroy() | ||
expect(new ParsleyFactory($('#element'), { | ||
namespace: "data-bar-" | ||
}).OptionsFactory.staticOptions.namespace).to.be('data-bar-'); | ||
}).options.namespace).to.be('data-bar-'); | ||
// data- DOM-API | ||
$('#element').parsley().destroy() | ||
$('#element').attr('data-parsley-namespace', 'data-baz-'); | ||
expect(new Parsley($('#element'), { | ||
expect(new ParsleyFactory($('#element'), { | ||
namespace: "data-bar-" | ||
}).OptionsFactory.staticOptions.namespace).to.be('data-baz-'); | ||
}).options.namespace).to.be('data-bar-'); | ||
delete window.ParsleyConfig.namespace; | ||
@@ -86,3 +88,3 @@ }); | ||
window.ParsleyConfig = $.extend(window.ParsleyConfig, {bar: "baz", baz:"qux"}); | ||
var parsleyInstance = new Parsley($('#element'), { qux: "bux" }); | ||
var parsleyInstance = new ParsleyFactory($('#element'), { qux: "bux" }); | ||
expect(parsleyInstance.options.foo).to.be('bar'); | ||
@@ -92,2 +94,4 @@ expect(parsleyInstance.options.baz).to.be('baz'); | ||
expect(parsleyInstance.options.qux).to.be('bux'); | ||
delete ParsleyConfig.bar; | ||
delete ParsleyConfig.baz; | ||
}); | ||
@@ -102,5 +106,5 @@ it('should have a jquery plugin API', function () { | ||
it('should have a jquery API returning undefined if done on a non existing element', function () { | ||
window.console.warn = sinon.spy(); | ||
expect($('#foo').parsley()).to.be(undefined); | ||
expect(window.console.warn.called).to.be(true); | ||
expectWarning(function() { | ||
expect($('#foo').parsley()).to.be(undefined); | ||
}); | ||
}); | ||
@@ -115,4 +119,2 @@ it('should have a jquery API that binds multiple selectors', function () { | ||
afterEach(function () { | ||
window.ParsleyConfig = { i18n: window.ParsleyConfig.i18n, validators: window.ParsleyConfig.validators }; | ||
$('#element').remove(); | ||
@@ -119,0 +121,0 @@ }); |
@@ -5,6 +5,8 @@ define(function () { | ||
it('listen() without context', function (done) { | ||
$.listen('foo', function (arg) { | ||
expect(arg).to.be('bar'); | ||
done(); | ||
}); | ||
expectWarning(function(){ | ||
$.listen('foo', function (instance, arg) { | ||
expect(arg).to.be('bar'); | ||
done(); | ||
}); | ||
}) | ||
$.emit('foo', 'bar'); | ||
@@ -14,3 +16,3 @@ }); | ||
var obj = { foo: function (bar) { return 'foo' + bar; } }; | ||
$.listen('foo', obj, function (arg) { | ||
$.listen('foo', obj, function (instance, arg) { | ||
expect(this.foo(arg)).to.be('foobar'); | ||
@@ -65,17 +67,14 @@ done(); | ||
}); | ||
it('unsubscribeTo()', function () { | ||
it('unsubscribeTo()', function (done) { | ||
$('body').append('<input type="text" id="element" />'); | ||
$.listen('foo', $.noop); | ||
$.listenTo($('#element').psly(), 'foo', $.noop); | ||
expect($.subscribed()).to.have.key('foo'); | ||
expect($.subscribed().foo.length).to.be(2); | ||
$.listen('foo', function() { done(); }); | ||
$.listenTo($('#element').psly(), 'foo', function() { expect(true).to.be(false); }); | ||
$.unsubscribeTo($('#element').psly(), 'foo'); | ||
expect($.subscribed().foo.length).to.be(1); | ||
$.emit('foo', $('#element').psly()) | ||
}); | ||
it('unsubscribe()', function () { | ||
$.listen('foo', $.noop); | ||
expect($.subscribed()).to.have.key('foo'); | ||
expect($.subscribed().foo.length).to.be(1); | ||
$.unsubscribe('foo', $.noop); | ||
expect($.subscribed().foo.length).to.be(0); | ||
var fn = function() { expect(true).to.be(false); }; | ||
$.listen('foo', fn); | ||
$.unsubscribe('foo', fn); | ||
$.emit('foo'); | ||
}); | ||
@@ -82,0 +81,0 @@ afterEach(function () { |
@@ -52,5 +52,5 @@ define('features/remote', [ | ||
'</form>'); | ||
$('#element').psly() | ||
.subscribe('parsley:form:validated', function () { done(); }) | ||
.asyncValidate(); | ||
$('#element').parsley() | ||
.on('form:validated', function () { done(); }) | ||
.asyncValidate(); | ||
}); | ||
@@ -214,2 +214,18 @@ it('should have a force option for asyncValidate and asyncIsValid methods', function (done) { | ||
}); | ||
it('should clear the cache when submitting a form', function () { | ||
var parsleyInstance = | ||
$('<form id="element"><input type="text" required></form>') | ||
.appendTo('body') | ||
.on('submit', function(evt) { evt.preventDefault(); } ) | ||
.parsley(); | ||
parsleyInstance._remoteCache = {dummy: 42}; | ||
$('#element').submit(); | ||
$('#element input').val('hello'); | ||
parsleyInstance.validate(); | ||
expect(parsleyInstance._remoteCache.dummy).to.be(42); | ||
$('#element').submit(); | ||
expect(parsleyInstance._remoteCache.dummy).to.be(undefined); | ||
}); | ||
it.skip('should abort successives querries and do not handle their return'); | ||
@@ -216,0 +232,0 @@ afterEach(function () { |
@@ -11,6 +11,8 @@ define(function () { | ||
}); | ||
it('should create proper errors container', function () { | ||
it('should create proper errors container when needed', function () { | ||
$('body').append('<input type="text" id="element" data-parsley-required />'); | ||
var parsleyField = $('#element').psly(); | ||
expect($('#element').attr('data-parsley-id')).to.be(parsleyField.__id__); | ||
expect($('ul#parsley-id-' + parsleyField.__id__).length).to.be(0); | ||
parsleyField.validate(); | ||
expect($('ul#parsley-id-' + parsleyField.__id__).length).to.be(1); | ||
@@ -26,3 +28,3 @@ expect($('ul#parsley-id-' + parsleyField.__id__).hasClass('parsley-errors-list')).to.be(true); | ||
'</form>'); | ||
$('#element').psly(); | ||
$('#element').psly().validate(); | ||
expect($('#container .parsley-errors-list').length).to.be(1); | ||
@@ -37,6 +39,7 @@ $('#element').psly().destroy(); | ||
it('should handle wrong errors-container option', function () { | ||
$('body').append('<input type="text" id="element" data-parsley-errors-container="#donotexist" />'); | ||
window.console.warn = sinon.spy(); | ||
var parsleyInstance = $('#element').psly(); | ||
expect(window.console.warn.called).to.be(true); | ||
$('body').append('<input type="text" id="element" data-parsley-errors-container="#donotexist" required/>'); | ||
var parsley = $('#element').psly(); | ||
expectWarning(function() { | ||
parsley.validate(); | ||
}); | ||
}); | ||
@@ -53,2 +56,16 @@ it('should add proper parsley class on success or failure (type=text)', function () { | ||
}); | ||
it('should not add success class on a field without constraints', function () { | ||
$('body').append('<input type="text" id="element" />'); | ||
var parsleyField = $('#element').psly(); | ||
parsleyField.validate(); | ||
expect($('#element').hasClass('parsley-error')).to.be(false); | ||
expect($('#element').hasClass('parsley-success')).to.be(false); | ||
}); | ||
it('should not add success class on an empty optional field', function () { | ||
$('body').append('<input type="number" id="element" />'); | ||
var parsleyField = $('#element').psly(); | ||
parsleyField.validate(); | ||
expect($('#element').hasClass('parsley-error')).to.be(false); | ||
expect($('#element').hasClass('parsley-success')).to.be(false); | ||
}); | ||
it('should add proper parsley class on success or failure (type=radio)', function () { | ||
@@ -163,3 +180,3 @@ $('body').append('<input type="radio" id="element" required />'); | ||
}); | ||
it('should auto bind error trigger on selet field error (input=text)', function () { | ||
it('should auto bind error trigger on select field error (input=text)', function () { | ||
$('body').append('<input type="email" id="element" required />'); | ||
@@ -174,3 +191,3 @@ var parsleyField = $('#element').psly(); | ||
}); | ||
it('should auto bind error trigger on selet field error (select)', function () { | ||
it('should auto bind error trigger on select field error (select)', function () { | ||
$('body').append('<select id="element" required>'+ | ||
@@ -222,3 +239,3 @@ '<option value="">Choose</option>' + | ||
'</form>'); | ||
var parsleyForm = new Parsley($('#element')); | ||
var parsleyForm = $('#element').parsley(); | ||
expect($('#element').attr('novalidate')).not.to.be(undefined); | ||
@@ -277,5 +294,6 @@ }); | ||
it('should not have errors ul created for excluded fields', function () { | ||
$('body').append('<input type="hidden" id="element" value="foo" data-parsley-minlength="5" />'); | ||
$('body').append('<div id="hidden"><input type="hidden" id="element" value="foo" data-parsley-minlength="5" /></div>'); | ||
var parsleyInstance = $('#element').parsley(); | ||
expect($('body ul').length).to.be(0); | ||
expect($('#hidden ul').length).to.be(0); | ||
$('#hidden').remove(); | ||
}); | ||
@@ -289,2 +307,46 @@ it('should remove filled class from errors container when reseting', function () { | ||
}); | ||
it('should re-bind error triggers after a reset (input=text)', function () { | ||
$('body').append('<input type="text" id="element" required />'); | ||
var parsleyInstance = $('#element').parsley(); | ||
parsleyInstance.validate(); | ||
parsleyInstance.reset(); | ||
parsleyInstance.validate(); | ||
expect($('ul#parsley-id-' + parsleyInstance.__id__ + ' li').length).to.be(1); | ||
$('#element').val('foo').trigger($.Event('keyup')); | ||
expect($('ul#parsley-id-' + parsleyInstance.__id__ + ' li').length).to.be(0); | ||
}); | ||
it('should re-bind error triggers after a reset (select)', function () { | ||
$('body').append('<select id="element" required>'+ | ||
'<option value="">Choose</option>' + | ||
'<option value="foo">foo</option>' + | ||
'<option value="bar">bar</option>' + | ||
'</select>'); | ||
var parsleyInstance = $('#element').parsley(); | ||
parsleyInstance.validate(); | ||
parsleyInstance.reset(); | ||
parsleyInstance.validate(); | ||
expect($('ul#parsley-id-' + parsleyInstance.__id__ + ' li').length).to.be(1); | ||
$('#element option[value="foo"]').prop('selected', true); | ||
$('#element').trigger($.Event('change')); | ||
expect($('ul#parsley-id-' + parsleyInstance.__id__ + ' li').length).to.be(0); | ||
}); | ||
it('should re-bind custom triggers after a reset', function () { | ||
$('body').append('<input type="text" id="element" required data-parsley-trigger="focusout" />'); | ||
var parsleyInstance = $('#element').parsley(); | ||
parsleyInstance.validate(); | ||
parsleyInstance.reset(); | ||
$('#element').focus().blur(); | ||
expect($('ul#parsley-id-' + parsleyInstance.__id__ + ' li').length).to.be(1); | ||
}); | ||
it('should handle custom error message for validators with compound names', function () { | ||
$('body').append('<input type="text" value="1" id="element" data-parsley-custom-validator="2" data-parsley-custom-validator-message="custom-validator error"/>'); | ||
window.ParsleyValidator.addValidator('customValidator', function (value, requirement) { | ||
return requirement === value; | ||
}, 32); | ||
var parsleyField = $('#element').psly(); | ||
parsleyField.validate(); | ||
expect($('ul#parsley-id-' + parsleyField.__id__ + ' li').text()).to.be('custom-validator error'); | ||
window.ParsleyValidator.removeValidator('customValidator'); | ||
}); | ||
afterEach(function () { | ||
@@ -291,0 +353,0 @@ $('#element, .parsley-errors-list').remove(); |
@@ -51,38 +51,23 @@ define(function () { | ||
expect(attr).to.eql({'foo': 'bar', 'bar': [0, 42]}); | ||
}); | ||
it('should have a proper attr() function that rewrites a given object', function () { | ||
var obj = ParsleyUtils.objectCreate({foo: 'x', fox: 'trot'}); | ||
obj.deleteMe = 'please'; | ||
var $element = $('<b data-parsley-foo="a" data-parsley-bar="[0, 42]" parsley-baz="baz">'); | ||
// test if attr exist | ||
expect(ParsleyUtils.attr(element, 'data-parsley-', 'foo')).to.be(true); | ||
expect(ParsleyUtils.attr(element, 'data-parsley-', 'FoO')).to.be(true); | ||
expect(ParsleyUtils.attr(element, 'data-parsley-', 'baz')).to.be(false); | ||
ParsleyUtils.attr($element, 'data-parsley-', obj); | ||
expect(obj).to.eql({foo: "a", bar: [0, 42]}); | ||
expect(obj.fox).to.eql('trot'); | ||
}); | ||
it('should have a checkAttr feature for attr() method', function () { | ||
var element = [{ | ||
attributes: [ | ||
{ | ||
specified: true, | ||
name: "data-parsley-required-message", | ||
value: "foo" | ||
}, | ||
{ | ||
specified: true, | ||
name: "data-parsley-validate", | ||
value: true | ||
} | ||
] | ||
}]; | ||
expect(ParsleyUtils.attr(element, 'data-parsley-', 'required')).to.be(false); | ||
expect(ParsleyUtils.attr(element, 'data-parsley-', 'required-message')).to.be(true); | ||
expect(ParsleyUtils.attr(element, 'data-parsley-', 'validate')).to.be(true); | ||
it('should have a checkAttr feature', function () { | ||
var $element = $('<span data-parsley-required-message="foo" data-parsley-validate="true">'); | ||
expect(ParsleyUtils.checkAttr($element, 'data-parsley-', 'required')).to.be(false); | ||
expect(ParsleyUtils.checkAttr($element, 'data-parsley-', 'required-message')).to.be(true); | ||
expect(ParsleyUtils.checkAttr($element, 'data-parsley-', 'validate')).to.be(true); | ||
expect(ParsleyUtils.checkAttr($element, 'data-parsley-', 'vaLidate')).to.be(true); | ||
}); | ||
it('should have a proper get() function', function () { | ||
var object = { | ||
foo: {bar: 'baz'}, | ||
bar: 'qux' | ||
}; | ||
expect(ParsleyUtils.get(object, 'bar')).to.be('qux'); | ||
expect(ParsleyUtils.get(object, 'foo.bar')).to.be('baz'); | ||
expect(ParsleyUtils.get(object, 'foo.baz')).to.be(undefined); | ||
}); | ||
}); | ||
} | ||
}); |
@@ -6,2 +6,7 @@ define(function () { | ||
var expectValidation = function(value, name, requirements) { | ||
var validator = parsleyValidator.validators[name](requirements); | ||
return expect(parsleyValidator.validate(value, validator)); | ||
}; | ||
it('should be a function', function () { | ||
@@ -11,12 +16,12 @@ expect(ParsleyValidator).to.be.a('function'); | ||
it('should bind global config validators if given in constructor', function () { | ||
window.ParsleyConfig = { | ||
i18n : window.ParsleyConfig.i18n, | ||
validators: $.extend(window.ParsleyConfig.validators, { | ||
$.extend(true, window.ParsleyConfig, { | ||
validators: { | ||
foo: { fn: function () {}, priority: 42 }, | ||
bar: { fn: function () {}, priority: 12 } | ||
}) | ||
}; | ||
var parsleyValidator = new ParsleyValidator(window.ParsleyConfig.validators); | ||
expect(parsleyValidator.validators).to.have.key('foo'); | ||
expect(parsleyValidator.validators).to.have.key('bar'); | ||
} | ||
}); | ||
var validator = new ParsleyValidator(window.ParsleyConfig.validators); | ||
expect(validator.validators).to.have.key('foo'); | ||
expect(validator.validators).to.have.key('bar'); | ||
expect(parsleyValidator.validators).not.to.have.key('foo'); | ||
delete window.ParsleyConfig.validators.foo; | ||
@@ -26,23 +31,23 @@ delete window.ParsleyConfig.validators.bar; | ||
it('should have a required validator', function () { | ||
expect(parsleyValidator.validate('', parsleyValidator.validators.required())).not.to.be(true); | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.required())).to.be(true); | ||
expectValidation('', 'required').not.to.be(true); | ||
expectValidation('foo', 'required').to.be(true); | ||
}); | ||
it('should have a notblank validator', function () { | ||
expect(parsleyValidator.validate(' ', parsleyValidator.validators.notblank())).not.to.be(true); | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.notblank())).to.be(true); | ||
expectValidation(' ', 'notblank').not.to.be(true); | ||
expectValidation('foo', 'notblank').to.be(true); | ||
}); | ||
it('should have a type="email" validator', function () { | ||
expect(parsleyValidator.validate('', parsleyValidator.validators.type('email'))).not.to.be(true); | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.type('email'))).not.to.be(true); | ||
expect(parsleyValidator.validate('foo@bar.baz', parsleyValidator.validators.type('email'))).to.be(true); | ||
expect(parsleyValidator.validate('foo+bar@bar.baz', parsleyValidator.validators.type('email'))).to.be(true); | ||
expect(parsleyValidator.validate('foo.bar@bar.baz', parsleyValidator.validators.type('email'))).to.be(true); | ||
expect(parsleyValidator.validate('foo.bar@bar.com.ext', parsleyValidator.validators.type('email'))).to.be(true); | ||
expectValidation('', 'type', 'email').not.to.be(true); | ||
expectValidation('foo', 'type', 'email').not.to.be(true); | ||
expectValidation('foo@bar.baz', 'type', 'email').to.be(true); | ||
expectValidation('foo+bar@bar.baz', 'type', 'email').to.be(true); | ||
expectValidation('foo.bar@bar.baz', 'type', 'email').to.be(true); | ||
expectValidation('foo.bar@bar.com.ext', 'type', 'email').to.be(true); | ||
}); | ||
it('should have a min validator', function () { | ||
expect(parsleyValidator.validate('', parsleyValidator.validators.min(6))).not.to.be(true); | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.min(6))).not.to.be(true); | ||
expect(parsleyValidator.validate('1', parsleyValidator.validators.min(6))).not.to.be(true); | ||
expect(parsleyValidator.validate('6', parsleyValidator.validators.min(6))).to.be(true); | ||
expect(parsleyValidator.validate('10', parsleyValidator.validators.min(6))).to.be(true); | ||
expectValidation('', 'min',6).not.to.be(true); | ||
expectValidation('foo', 'min',6).not.to.be(true); | ||
expectValidation('1', 'min',6).not.to.be(true); | ||
expectValidation('6', 'min',6).to.be(true); | ||
expectValidation('10', 'min',6).to.be(true); | ||
$('body').append('<input type="text" id="element" value="7" min="2" />'); | ||
@@ -52,8 +57,8 @@ expect($('#element').parsley().isValid()).to.be(true); | ||
it('should have a max validator', function () { | ||
expect(parsleyValidator.validate('', parsleyValidator.validators.max(10))).not.to.be(true); | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.max(10))).not.to.be(true); | ||
expect(parsleyValidator.validate('1', parsleyValidator.validators.max(10))).to.be(true); | ||
expect(parsleyValidator.validate('1', parsleyValidator.validators.max("10"))).to.be(true); | ||
expect(parsleyValidator.validate('10', parsleyValidator.validators.max(10))).to.be(true); | ||
expect(parsleyValidator.validate('17', parsleyValidator.validators.max(10))).not.to.be(true); | ||
expectValidation('', 'max', 10).not.to.be(true); | ||
expectValidation('foo', 'max', 10).not.to.be(true); | ||
expectValidation('1', 'max', 10).to.be(true); | ||
expectValidation('1', 'max', '10').to.be(true); | ||
expectValidation('10', 'max', 10).to.be(true); | ||
expectValidation('17', 'max', 10).not.to.be(true); | ||
$('body').append('<input type="text" id="element" value="7" max="20" />'); | ||
@@ -63,5 +68,5 @@ expect($('#element').parsley().isValid()).to.be(true); | ||
it('should have a range validator', function () { | ||
expect(parsleyValidator.validate('1', parsleyValidator.validators.range([5, 10]))).not.to.be(true); | ||
expect(parsleyValidator.validate('7', parsleyValidator.validators.range([5, 10]))).to.be(true); | ||
expect(parsleyValidator.validate('17', parsleyValidator.validators.range([5, 10]))).not.to.be(true); | ||
expectValidation('1', 'range', [5, 10]).not.to.be(true); | ||
expectValidation('7', 'range', [5, 10]).to.be(true); | ||
expectValidation('17', 'range', [5, 10]).not.to.be(true); | ||
$('body').append('<input type="text" id="element" value="7" max="20" min="2" />'); | ||
@@ -75,27 +80,27 @@ expect($('#element').parsley().isValid()).to.be(true); | ||
it('should have a type="number" validator', function () { | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.type('number'))).not.to.be(true); | ||
expect(parsleyValidator.validate('1', parsleyValidator.validators.type('number'))).to.be(true); | ||
expect(parsleyValidator.validate('1.5', parsleyValidator.validators.type('number'))).to.be(true); | ||
expect(parsleyValidator.validate('-1.5', parsleyValidator.validators.type('number'))).to.be(true); | ||
expect(parsleyValidator.validate('1,500.642', parsleyValidator.validators.type('number'))).to.be(true); | ||
expectValidation('foo', 'type', 'number').not.to.be(true); | ||
expectValidation('1', 'type', 'number').to.be(true); | ||
expectValidation('1.5', 'type', 'number').to.be(true); | ||
expectValidation('-1.5', 'type', 'number').to.be(true); | ||
expectValidation('1,500.642', 'type', 'number').to.be(true); | ||
}); | ||
it('should have a type="digits" validator', function () { | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.type('digits'))).not.to.be(true); | ||
expect(parsleyValidator.validate('1', parsleyValidator.validators.type('digits'))).to.be(true); | ||
expect(parsleyValidator.validate('-1', parsleyValidator.validators.type('digits'))).not.to.be(true); | ||
expect(parsleyValidator.validate('1.5', parsleyValidator.validators.type('digits'))).not.to.be(true); | ||
expect(parsleyValidator.validate('-1.5', parsleyValidator.validators.type('digits'))).not.to.be(true); | ||
expect(parsleyValidator.validate('1,500.642', parsleyValidator.validators.type('digits'))).not.to.be(true); | ||
expectValidation('foo', 'type', 'digits').not.to.be(true); | ||
expectValidation('1', 'type', 'digits').to.be(true); | ||
expectValidation('-1', 'type', 'digits').not.to.be(true); | ||
expectValidation('1.5', 'type', 'digits').not.to.be(true); | ||
expectValidation('-1.5', 'type', 'digits').not.to.be(true); | ||
expectValidation('1,500.642', 'type', 'digits').not.to.be(true); | ||
}); | ||
it('should have a type="integer" validator', function () { | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.type('integer'))).not.to.be(true); | ||
expect(parsleyValidator.validate('1', parsleyValidator.validators.type('integer'))).to.be(true); | ||
expect(parsleyValidator.validate('-1', parsleyValidator.validators.type('integer'))).to.be(true); | ||
expect(parsleyValidator.validate('1.5', parsleyValidator.validators.type('integer'))).not.to.be(true); | ||
expect(parsleyValidator.validate('-1.5', parsleyValidator.validators.type('integer'))).not.to.be(true); | ||
expectValidation('foo', 'type', 'integer').not.to.be(true); | ||
expectValidation('1', 'type', 'integer').to.be(true); | ||
expectValidation('-1', 'type', 'integer').to.be(true); | ||
expectValidation('1.5', 'type', 'integer').not.to.be(true); | ||
expectValidation('-1.5', 'type', 'integer').not.to.be(true); | ||
}); | ||
it('should have a type="alphanum" validator', function () { | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.type('alphanum'))).to.be(true); | ||
expect(parsleyValidator.validate('foo bar', parsleyValidator.validators.type('alphanum'))).not.to.be(true); | ||
expect(parsleyValidator.validate('foo$', parsleyValidator.validators.type('alphanum'))).not.to.be(true); | ||
expectValidation('foo', 'type', 'alphanum').to.be(true); | ||
expectValidation('foo bar', 'type', 'alphanum').not.to.be(true); | ||
expectValidation('foo$', 'type', 'alphanum').not.to.be(true); | ||
$('body').append('<input data-parsley-type="alphanum" id="element" value="v4kRRyhYvo0P" />'); | ||
@@ -105,26 +110,27 @@ expect($('#element').parsley().isValid()).to.be(true); | ||
it('should have a type="url" validator', function () { | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.type('url'))).not.to.be(true); | ||
expect(parsleyValidator.validate('foo bar', parsleyValidator.validators.type('url'))).not.to.be(true); | ||
expect(parsleyValidator.validate('http://', parsleyValidator.validators.type('url'))).not.to.be(true); | ||
expect(parsleyValidator.validate('foo.bar', parsleyValidator.validators.type('url'))).to.be(true); | ||
expect(parsleyValidator.validate('www.foo.bar', parsleyValidator.validators.type('url'))).to.be(true); | ||
expect(parsleyValidator.validate('http://www.foo.bar', parsleyValidator.validators.type('url'))).to.be(true); | ||
expect(parsleyValidator.validate('https://www.foo.bar', parsleyValidator.validators.type('url'))).to.be(true); | ||
expectValidation('foo', 'type', 'url').not.to.be(true); | ||
expectValidation('foo bar', 'type', 'url').not.to.be(true); | ||
expectValidation('http://', 'type', 'url').not.to.be(true); | ||
expectValidation('foo.bar', 'type', 'url').to.be(true); | ||
expectValidation('www.foo.bar', 'type', 'url').to.be(true); | ||
expectValidation('http://www.foo.bar', 'type', 'url').to.be(true); | ||
expectValidation('https://www.foo.bar', 'type', 'url').to.be(true); | ||
expectValidation('http://192.168.1.1/foo/bar', 'type', 'url').to.be(true); | ||
}); | ||
it('should have a pattern validator', function () { | ||
expect(parsleyValidator.validate('a', parsleyValidator.validators.pattern('[a-z]+'))).to.be(true); | ||
expect(parsleyValidator.validate('A', parsleyValidator.validators.pattern('[a-z]+'))).not.to.be(true); | ||
expect(parsleyValidator.validate('a', parsleyValidator.validators.pattern('/[a-z]+/'))).to.be(true); | ||
expect(parsleyValidator.validate('A', parsleyValidator.validators.pattern('/[a-z]+/'))).not.to.be(true); | ||
expect(parsleyValidator.validate('a', parsleyValidator.validators.pattern('/[a-z]+/i'))).to.be(true); | ||
expect(parsleyValidator.validate('A', parsleyValidator.validators.pattern('/[a-z]+/i'))).to.be(true); | ||
expectValidation('a', 'pattern','[a-z]+' ).to.be(true); | ||
expectValidation('A', 'pattern','[a-z]+' ).not.to.be(true); | ||
expectValidation('a', 'pattern','/[a-z]+/' ).to.be(true); | ||
expectValidation('A', 'pattern','/[a-z]+/' ).not.to.be(true); | ||
expectValidation('a', 'pattern','/[a-z]+/i').to.be(true); | ||
expectValidation('A', 'pattern','/[a-z]+/i').to.be(true); | ||
}); | ||
it('should have a length validator', function () { | ||
expect(parsleyValidator.validate('foobar', parsleyValidator.validators.length([3, 9]))).to.be(true); | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.length([4, 9]))).not.to.be(true); | ||
expect(parsleyValidator.validate('foobarbaz', parsleyValidator.validators.length([3, 8]))).not.to.be(true); | ||
expectValidation('foobar', 'length', [3, 9]).to.be(true); | ||
expectValidation('foo', 'length', [4, 9]).not.to.be(true); | ||
expectValidation('foobarbaz', 'length', [3, 8]).not.to.be(true); | ||
}); | ||
it('should have a minlength validator', function () { | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.minlength(3))).to.be(true); | ||
expect(parsleyValidator.validate('fo', parsleyValidator.validators.minlength(3))).not.to.be(true); | ||
expectValidation('foo', 'minlength', 3).to.be(true); | ||
expectValidation('fo', 'minlength', 3).not.to.be(true); | ||
$('body').append('<input type="text" id="element" value="foo" data-parsley-minlength="2" />'); | ||
@@ -134,4 +140,4 @@ expect($('#element').parsley().isValid()).to.be(true); | ||
it('should have a maxlength validator', function () { | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.maxlength(3))).to.be(true); | ||
expect(parsleyValidator.validate('foobar', parsleyValidator.validators.maxlength(3))).not.to.be(true); | ||
expectValidation('foo', 'maxlength', 3).to.be(true); | ||
expectValidation('foobar', 'maxlength', 3).not.to.be(true); | ||
$('body').append('<input type="text" id="element" value="foo" data-parsley-maxlength="10" />'); | ||
@@ -141,18 +147,18 @@ expect($('#element').parsley().isValid()).to.be(true); | ||
it('should have a check validator', function () { | ||
expect(parsleyValidator.validate(['foo', 'bar', 'baz'], parsleyValidator.validators.check([3, 5]))).to.be(true); | ||
expect(parsleyValidator.validate(['foo', 'bar', 'baz', 'qux', 'bux'], parsleyValidator.validators.check([3, 4]))).not.to.be(true); | ||
expect(parsleyValidator.validate(['foo', 'bar'], parsleyValidator.validators.check([3, 5]))).not.to.be(true); | ||
expectValidation(['foo', 'bar', 'baz'], 'check', [3, 5]).to.be(true); | ||
expectValidation(['foo', 'bar', 'baz', 'qux', 'bux'], 'check', [3, 4]).not.to.be(true); | ||
expectValidation(['foo', 'bar'], 'check', [3, 5]).not.to.be(true); | ||
}); | ||
it('should have a mincheck validator', function () { | ||
expect(parsleyValidator.validate(['foo', 'bar', 'baz'], parsleyValidator.validators.mincheck(3))).to.be(true); | ||
expect(parsleyValidator.validate(['foo', 'bar'], parsleyValidator.validators.mincheck(3))).not.to.be(true); | ||
expectValidation(['foo', 'bar', 'baz'], 'mincheck', 3).to.be(true); | ||
expectValidation(['foo', 'bar'], 'mincheck', 3).not.to.be(true); | ||
}); | ||
it('should have a maxcheck validator', function () { | ||
expect(parsleyValidator.validate(['foo', 'bar', 'baz'], parsleyValidator.validators.maxcheck(3))).to.be(true); | ||
expect(parsleyValidator.validate(['foo', 'bar', 'baz', 'qux'], parsleyValidator.validators.maxcheck(3))).not.to.be(true); | ||
expectValidation(['foo', 'bar', 'baz'], 'maxcheck', 3).to.be(true); | ||
expectValidation(['foo', 'bar', 'baz', 'qux'], 'maxcheck', 3).not.to.be(true); | ||
}); | ||
it('should have an equalto validator', function () { | ||
expect(parsleyValidator.validate('', parsleyValidator.validators.equalto('foo'))).not.to.be(true); | ||
expect(parsleyValidator.validate('bar', parsleyValidator.validators.equalto('foo'))).not.to.be(true); | ||
expect(parsleyValidator.validate('foo', parsleyValidator.validators.equalto('foo'))).to.be(true); | ||
expectValidation('', 'equalto', 'foo').not.to.be(true); | ||
expectValidation('bar', 'equalto', 'foo').not.to.be(true); | ||
expectValidation('foo', 'equalto', 'foo').to.be(true); | ||
$('body').append('<input type="text" id="element" data-parsley-equalto="#equalto" required /><input type="text" id="equalto" value="foo" />'); | ||
@@ -175,2 +181,9 @@ expect($('#element').psly().isValid()).to.be(false); | ||
}); | ||
it('should not break for an incomplete language', function () { | ||
parsleyValidator.addCatalog('klingon', {}, true); | ||
expect(parsleyValidator.getErrorMessage({ name: 'type', requirements: 'email' })).to.be('This value seems to be invalid.'); | ||
expect(parsleyValidator.getErrorMessage({ name: 'length', requirements: [3, 6] })).to.be('This value seems to be invalid.'); | ||
}); | ||
it('should handle parametersTransformer for custom validators', function () { | ||
@@ -191,8 +204,40 @@ parsleyValidator.addValidator('foo', function (requirements) { | ||
afterEach(function () { | ||
window.ParsleyConfig = { i18n: window.ParsleyConfig.i18n, validators: window.ParsleyConfig.validators }; | ||
$('#element').remove(); | ||
}); | ||
it('should warn if a custom validator has a reserved name', function () { | ||
$.extend(true, window.ParsleyConfig, { | ||
validators: { | ||
excluded: { fn: function () {}, priority: 42 }, | ||
} | ||
}); | ||
expectWarning(function() { | ||
var parsleyValidator = new ParsleyValidator(window.ParsleyConfig.validators); | ||
}); | ||
delete window.ParsleyConfig.validators.excluded; | ||
}); | ||
it('should warn when adding an already defined validator', function () { | ||
parsleyValidator.addValidator('foo', $.noop); | ||
expectWarning(function() { | ||
parsleyValidator.addValidator('foo', $.noop); | ||
}); | ||
parsleyValidator.removeValidator('foo'); | ||
}); | ||
it('should warn when updating or deleting a custom validator not already defined', function () { | ||
expectWarning(function() { | ||
parsleyValidator.updateValidator('foo', function () {}); | ||
}); | ||
parsleyValidator.removeValidator('foo'); | ||
}); | ||
it('should warn when updating or deleting a custom validator not already defined', function () { | ||
expectWarning(function() { | ||
parsleyValidator.removeValidator('foo'); | ||
}); | ||
}); | ||
}); | ||
}; | ||
}); |
@@ -8,4 +8,5 @@ require(['config'], function () { | ||
'sinon' | ||
], function (jquery, expect, mocha, sinon) { | ||
], function (jquery, _expect, mocha, _sinon) { | ||
// setup mocha | ||
mocha.globals([ 'jQuery*' ]) | ||
mocha.checkLeaks(); | ||
@@ -18,3 +19,3 @@ mocha.setup('bdd'); | ||
'src/parsley', | ||
'parsley/factory/options', | ||
'parsley/factory', | ||
'parsley/form', | ||
@@ -26,4 +27,22 @@ 'parsley/field', | ||
'i18n/fr' | ||
], function (Parsley, ParsleyOptionsFactory, ParsleyForm, ParsleyField, ParsleyUI, ParsleyUtils, ParsleyValidator) { | ||
], function (Parsley, ParsleyFactory, ParsleyForm, ParsleyField, ParsleyUI, ParsleyUtils, ParsleyValidator) { | ||
// Setup console.warn so we insure it is called when we expect it | ||
beforeEach(function() { | ||
sinon.spy(console, 'warn'); | ||
console.warn.expectedCallCount = 0; | ||
}); | ||
afterEach(function() { | ||
expect(console.warn.callCount).to.be(console.warn.expectedCallCount); | ||
console.warn.restore(); | ||
}); | ||
window.expectWarning = function(fn) { | ||
var w = console.warn; | ||
expect(w.callCount).to.be(w.expectedCallCount); | ||
var result = fn.call(); | ||
w.expectedCallCount++; | ||
expect(w.callCount).to.be(w.expectedCallCount); | ||
return result; | ||
}; | ||
// load full parsley.js + UT | ||
@@ -33,3 +52,2 @@ require([ | ||
'features/parsley', | ||
'features/options', | ||
'features/pubsub', | ||
@@ -42,3 +60,3 @@ 'features/abstract', | ||
'features/ui' | ||
], function (utils, parsleyBase, options, pubsub, abstract, field, multiple, form, validator, ui) { | ||
], function (utils, parsleyBase, pubsub, abstract, field, multiple, form, validator, ui) { | ||
describe('ParsleyStandard', function () { | ||
@@ -53,11 +71,11 @@ // Use a pristine ParsleyExtend for the standard suite: | ||
window.ParsleyExtend = previousExtend; | ||
ParsleyUtils._resetWarnings(); | ||
}); | ||
utils(ParsleyUtils); | ||
parsleyBase(Parsley); | ||
options(ParsleyOptionsFactory); | ||
parsleyBase(Parsley.Factory); | ||
pubsub(); | ||
abstract(Parsley); | ||
field(ParsleyField, Parsley); | ||
multiple(Parsley); | ||
form(ParsleyForm, Parsley); | ||
abstract(); | ||
field(ParsleyField); | ||
multiple(); | ||
form(ParsleyForm); | ||
validator(ParsleyValidator); | ||
@@ -89,5 +107,5 @@ ui(ParsleyUI); | ||
remote(ParsleyExtend); | ||
abstract(Parsley); | ||
field(ParsleyField, Parsley); | ||
form(ParsleyForm, Parsley); | ||
abstract(); | ||
field(ParsleyField); | ||
form(ParsleyForm); | ||
}); | ||
@@ -94,0 +112,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
121
72
10
0
736061
10942
2