From d9a143b493e854fbcbd4917d10f6ce20d4e12c92 Mon Sep 17 00:00:00 2001 From: Paul Jackson Date: Sun, 24 Mar 2013 00:51:51 -0400 Subject: [PATCH 1/7] Updated to jQuery Validation 1.11.1. --- src/js/dependencies/validate.js | 613 +++++++++++----------- src/js/dependencies/validateAdditional.js | 332 +++++++++--- 2 files changed, 554 insertions(+), 391 deletions(-) diff --git a/src/js/dependencies/validate.js b/src/js/dependencies/validate.js index 794e90172af..f5a4e27f01d 100644 --- a/src/js/dependencies/validate.js +++ b/src/js/dependencies/validate.js @@ -1,6 +1,13 @@ -/*! jQuery Validation Plugin - v1.10.0 - 9/7/2012 -* https://github.com/jzaefferer/jquery-validation -* Copyright (c) 2012 Jörn Zaefferer; Licensed MIT, GPL */ +/*! + * jQuery Validation Plugin 1.11.1 + * + * http://bassistance.de/jquery-plugins/jquery-plugin-validation/ + * http://docs.jquery.com/Plugins/Validation + * + * Copyright 2013 Jörn Zaefferer + * Released under the MIT license: + * http://www.opensource.org/licenses/mit-license.php + */ (function($) { @@ -9,33 +16,38 @@ $.extend($.fn, { validate: function( options ) { // if nothing is selected, return nothing; can't chain anyway - if (!this.length) { - if (options && options.debug && window.console) { - console.warn( "nothing selected, can't validate, returning nothing" ); + if ( !this.length ) { + if ( options && options.debug && window.console ) { + console.warn( "Nothing selected, can't validate, returning nothing." ); } return; } // check if a validator for this form was already created - var validator = $.data(this[0], 'validator'); + var validator = $.data( this[0], "validator" ); if ( validator ) { return validator; } // Add novalidate tag if HTML5. - this.attr('novalidate', 'novalidate'); + this.attr( "novalidate", "novalidate" ); validator = new $.validator( options, this[0] ); - $.data(this[0], 'validator', validator); + $.data( this[0], "validator", validator ); if ( validator.settings.onsubmit ) { - this.validateDelegate( ":submit", "click", function(ev) { + this.validateDelegate( ":submit", "click", function( event ) { if ( validator.settings.submitHandler ) { - validator.submitButton = ev.target; + validator.submitButton = event.target; } // allow suppressing validation by adding a cancel class to the submit button - if ( $(ev.target).hasClass('cancel') ) { + if ( $(event.target).hasClass("cancel") ) { + validator.cancelSubmit = true; + } + + // allow suppressing validation by adding the html5 formnovalidate attribute to the submit button + if ( $(event.target).attr("formnovalidate") !== undefined ) { validator.cancelSubmit = true; } }); @@ -49,12 +61,12 @@ $.extend($.fn, { function handle() { var hidden; if ( validator.settings.submitHandler ) { - if (validator.submitButton) { + if ( validator.submitButton ) { // insert a hidden input as a replacement for the missing submit button - hidden = $("").attr("name", validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm); + hidden = $("").attr("name", validator.submitButton.name).val( $(validator.submitButton).val() ).appendTo(validator.currentForm); } validator.settings.submitHandler.call( validator, validator.currentForm, event ); - if (validator.submitButton) { + if ( validator.submitButton ) { // and clean up afterwards; thanks to no-block-scope, hidden can be referenced hidden.remove(); } @@ -85,50 +97,52 @@ $.extend($.fn, { }, // http://docs.jquery.com/Plugins/Validation/valid valid: function() { - if ( $(this[0]).is('form')) { + if ( $(this[0]).is("form")) { return this.validate().form(); } else { var valid = true; var validator = $(this[0].form).validate(); this.each(function() { - valid &= validator.element(this); + valid = valid && validator.element(this); }); return valid; } }, // attributes: space seperated list of attributes to retrieve and remove - removeAttrs: function(attributes) { + removeAttrs: function( attributes ) { var result = {}, $element = this; - $.each(attributes.split(/\s/), function(index, value) { + $.each(attributes.split(/\s/), function( index, value ) { result[value] = $element.attr(value); $element.removeAttr(value); }); return result; }, // http://docs.jquery.com/Plugins/Validation/rules - rules: function(command, argument) { + rules: function( command, argument ) { var element = this[0]; - if (command) { - var settings = $.data(element.form, 'validator').settings; + if ( command ) { + var settings = $.data(element.form, "validator").settings; var staticRules = settings.rules; var existingRules = $.validator.staticRules(element); switch(command) { case "add": $.extend(existingRules, $.validator.normalizeRule(argument)); + // remove messages from rules, but allow them to be set separetely + delete existingRules.messages; staticRules[element.name] = existingRules; - if (argument.messages) { + if ( argument.messages ) { settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages ); } break; case "remove": - if (!argument) { + if ( !argument ) { delete staticRules[element.name]; return existingRules; } var filtered = {}; - $.each(argument.split(/\s/), function(index, method) { + $.each(argument.split(/\s/), function( index, method ) { filtered[method] = existingRules[method]; delete existingRules[method]; }); @@ -139,14 +153,14 @@ $.extend($.fn, { var data = $.validator.normalizeRules( $.extend( {}, - $.validator.metadataRules(element), $.validator.classRules(element), $.validator.attributeRules(element), + $.validator.dataRules(element), $.validator.staticRules(element) ), element); // make sure required is at front - if (data.required) { + if ( data.required ) { var param = data.required; delete data.required; data = $.extend({required: param}, data); @@ -159,11 +173,11 @@ $.extend($.fn, { // Custom selectors $.extend($.expr[":"], { // http://docs.jquery.com/Plugins/Validation/blank - blank: function(a) {return !$.trim("" + a.value);}, + blank: function( a ) { return !$.trim("" + $(a).val()); }, // http://docs.jquery.com/Plugins/Validation/filled - filled: function(a) {return !!$.trim("" + a.value);}, + filled: function( a ) { return !!$.trim("" + $(a).val()); }, // http://docs.jquery.com/Plugins/Validation/unchecked - unchecked: function(a) {return !a.checked;} + unchecked: function( a ) { return !$(a).prop("checked"); } }); // constructor for validator @@ -173,7 +187,7 @@ $.validator = function( options, form ) { this.init(); }; -$.validator.format = function(source, params) { +$.validator.format = function( source, params ) { if ( arguments.length === 1 ) { return function() { var args = $.makeArray(arguments); @@ -187,8 +201,10 @@ $.validator.format = function(source, params) { if ( params.constructor !== Array ) { params = [ params ]; } - $.each(params, function(i, n) { - source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n); + $.each(params, function( i, n ) { + source = source.replace( new RegExp("\\{" + i + "\\}", "g"), function() { + return n; + }); }); return source; }; @@ -203,12 +219,12 @@ $.extend($.validator, { validClass: "valid", errorElement: "label", focusInvalid: true, - errorContainer: $( [] ), - errorLabelContainer: $( [] ), + errorContainer: $([]), + errorLabelContainer: $([]), onsubmit: true, ignore: ":hidden", ignoreTitle: false, - onfocusin: function(element, event) { + onfocusin: function( element, event ) { this.lastActive = element; // hide error label and remove error class on focus if enabled @@ -219,37 +235,37 @@ $.extend($.validator, { this.addWrapper(this.errorsFor(element)).hide(); } }, - onfocusout: function(element, event) { + onfocusout: function( element, event ) { if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) { this.element(element); } }, - onkeyup: function(element, event) { - if ( event.which === 9 && this.elementValue(element) === '' ) { + onkeyup: function( element, event ) { + if ( event.which === 9 && this.elementValue(element) === "" ) { return; - } else if ( element.name in this.submitted || element === this.lastActive ) { + } else if ( element.name in this.submitted || element === this.lastElement ) { this.element(element); } }, - onclick: function(element, event) { + onclick: function( element, event ) { // click on selects, radiobuttons and checkboxes if ( element.name in this.submitted ) { this.element(element); } // or option elements, check parent select in that case - else if (element.parentNode.name in this.submitted) { + else if ( element.parentNode.name in this.submitted ) { this.element(element.parentNode); } }, - highlight: function(element, errorClass, validClass) { - if (element.type === 'radio') { + highlight: function( element, errorClass, validClass ) { + if ( element.type === "radio" ) { this.findByName(element.name).addClass(errorClass).removeClass(validClass); } else { $(element).addClass(errorClass).removeClass(validClass); } }, - unhighlight: function(element, errorClass, validClass) { - if (element.type === 'radio') { + unhighlight: function( element, errorClass, validClass ) { + if ( element.type === "radio" ) { this.findByName(element.name).removeClass(errorClass).addClass(validClass); } else { $(element).removeClass(errorClass).addClass(validClass); @@ -258,7 +274,7 @@ $.extend($.validator, { }, // http://docs.jquery.com/Plugins/Validation/Validator/setDefaults - setDefaults: function(settings) { + setDefaults: function( settings ) { $.extend( $.validator.defaults, settings ); }, @@ -297,20 +313,23 @@ $.extend($.validator, { this.reset(); var groups = (this.groups = {}); - $.each(this.settings.groups, function(key, value) { - $.each(value.split(/\s/), function(index, name) { + $.each(this.settings.groups, function( key, value ) { + if ( typeof value === "string" ) { + value = value.split(/\s/); + } + $.each(value, function( index, name ) { groups[name] = key; }); }); var rules = this.settings.rules; - $.each(rules, function(key, value) { + $.each(rules, function( key, value ) { rules[key] = $.validator.normalizeRule(value); }); function delegate(event) { var validator = $.data(this[0].form, "validator"), eventType = "on" + event.type.replace(/^validate/, ""); - if (validator.settings[eventType]) { + if ( validator.settings[eventType] ) { validator.settings[eventType].call(validator, this[0], event); } } @@ -323,7 +342,7 @@ $.extend($.validator, { "focusin focusout keyup", delegate) .validateDelegate("[type='radio'], [type='checkbox'], select, option", "click", delegate); - if (this.settings.invalidHandler) { + if ( this.settings.invalidHandler ) { $(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler); } }, @@ -333,7 +352,7 @@ $.extend($.validator, { this.checkForm(); $.extend(this.submitted, this.errorMap); this.invalid = $.extend({}, this.errorMap); - if (!this.valid()) { + if ( !this.valid() ) { $(this.currentForm).triggerHandler("invalid-form", [this]); } this.showErrors(); @@ -355,7 +374,7 @@ $.extend($.validator, { this.prepareElement( element ); this.currentElements = $(element); var result = this.check( element ) !== false; - if (result) { + if ( result ) { delete this.invalid[element.name]; } else { this.invalid[element.name] = true; @@ -369,8 +388,8 @@ $.extend($.validator, { }, // http://docs.jquery.com/Plugins/Validation/Validator/showErrors - showErrors: function(errors) { - if(errors) { + showErrors: function( errors ) { + if ( errors ) { // add items to error list and map $.extend( this.errorMap, errors ); this.errorList = []; @@ -381,11 +400,11 @@ $.extend($.validator, { }); } // remove items from success list - this.successList = $.grep( this.successList, function(element) { + this.successList = $.grep( this.successList, function( element ) { return !(element.name in errors); }); } - if (this.settings.showErrors) { + if ( this.settings.showErrors ) { this.settings.showErrors.call( this, this.errorMap, this.errorList ); } else { this.defaultShowErrors(); @@ -395,7 +414,7 @@ $.extend($.validator, { // http://docs.jquery.com/Plugins/Validation/Validator/resetForm resetForm: function() { if ( $.fn.resetForm ) { - $( this.currentForm ).resetForm(); + $(this.currentForm).resetForm(); } this.submitted = {}; this.lastElement = null; @@ -429,7 +448,7 @@ $.extend($.validator, { }, focusInvalid: function() { - if( this.settings.focusInvalid ) { + if ( this.settings.focusInvalid ) { try { $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []) .filter(":visible") @@ -444,7 +463,7 @@ $.extend($.validator, { findLastActive: function() { var lastActive = this.lastActive; - return lastActive && $.grep(this.errorList, function(n) { + return lastActive && $.grep(this.errorList, function( n ) { return n.element.name === lastActive.name; }).length === 1 && lastActive; }, @@ -474,12 +493,12 @@ $.extend($.validator, { }, clean: function( selector ) { - return $( selector )[0]; + return $(selector)[0]; }, errors: function() { - var errorClass = this.settings.errorClass.replace(' ', '.'); - return $( this.settings.errorElement + "." + errorClass, this.errorContext ); + var errorClass = this.settings.errorClass.replace(" ", "."); + return $(this.settings.errorElement + "." + errorClass, this.errorContext); }, reset: function() { @@ -502,14 +521,14 @@ $.extend($.validator, { }, elementValue: function( element ) { - var type = $(element).attr('type'), + var type = $(element).attr("type"), val = $(element).val(); - if ( type === 'radio' || type === 'checkbox' ) { - return $('input[name="' + $(element).attr('name') + '"]:checked').val(); + if ( type === "radio" || type === "checkbox" ) { + return $("input[name='" + $(element).attr("name") + "']:checked").val(); } - if ( typeof val === 'string' ) { + if ( typeof val === "string" ) { return val.replace(/\r/g, ""); } return val; @@ -542,18 +561,18 @@ $.extend($.validator, { return; } - if( !result ) { + if ( !result ) { this.formatAndAdd( element, rule ); return false; } } catch(e) { if ( this.settings.debug && window.console ) { - console.log("exception occured when checking element " + element.id + ", check the '" + rule.method + "' method", e); + console.log( "Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.", e ); } throw e; } } - if (dependencyMismatch) { + if ( dependencyMismatch ) { return; } if ( this.objectLength(rules) ) { @@ -562,20 +581,10 @@ $.extend($.validator, { return true; }, - // return the custom message for the given element and validation method - // specified in the element's "messages" metadata - customMetaMessage: function(element, method) { - if (!$.metadata) { - return; - } - var meta = this.settings.meta ? $(element).metadata()[this.settings.meta] : $(element).metadata(); - return meta && meta.messages && meta.messages[method]; - }, - // return the custom message for the given element and validation method // specified in the element's HTML5 data attribute - customDataMessage: function(element, method) { - return $(element).data('msg-' + method.toLowerCase()) || (element.attributes && $(element).attr('data-msg-' + method.toLowerCase())); + customDataMessage: function( element, method ) { + return $(element).data("msg-" + method.toLowerCase()) || (element.attributes && $(element).attr("data-msg-" + method.toLowerCase())); }, // return the custom message for the given element name and validation method @@ -587,18 +596,17 @@ $.extend($.validator, { // return the first defined argument, allowing empty strings findDefined: function() { for(var i = 0; i < arguments.length; i++) { - if (arguments[i] !== undefined) { + if ( arguments[i] !== undefined ) { return arguments[i]; } } return undefined; }, - defaultMessage: function( element, method) { + defaultMessage: function( element, method ) { return this.findDefined( this.customMessage( element.name, method ), this.customDataMessage( element, method ), - this.customMetaMessage( element, method ), // title is never undefined, so handle empty string as undefined !this.settings.ignoreTitle && element.title || undefined, $.validator.messages[method], @@ -612,7 +620,7 @@ $.extend($.validator, { if ( typeof message === "function" ) { message = message.call(this, rule.parameters, element); } else if (theregex.test(message)) { - message = $.validator.format(message.replace(theregex, '{$1}'), rule.parameters); + message = $.validator.format(message.replace(theregex, "{$1}"), rule.parameters); } this.errorList.push({ message: message, @@ -623,7 +631,7 @@ $.extend($.validator, { this.submitted[element.name] = message; }, - addWrapper: function(toToggle) { + addWrapper: function( toToggle ) { if ( this.settings.wrapper ) { toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) ); } @@ -639,15 +647,15 @@ $.extend($.validator, { } this.showLabel( error.element, error.message ); } - if( this.errorList.length ) { + if ( this.errorList.length ) { this.toShow = this.toShow.add( this.containers ); } - if (this.settings.success) { + if ( this.settings.success ) { for ( i = 0; this.successList[i]; i++ ) { this.showLabel( this.successList[i] ); } } - if (this.settings.unhighlight) { + if ( this.settings.unhighlight ) { for ( i = 0, elements = this.validElements(); elements[i]; i++ ) { this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass ); } @@ -667,20 +675,17 @@ $.extend($.validator, { }); }, - showLabel: function(element, message) { + showLabel: function( element, message ) { var label = this.errorsFor( element ); if ( label.length ) { // refresh error/success class label.removeClass( this.settings.validClass ).addClass( this.settings.errorClass ); - - // check if we have a generated label, replace the message then - if ( label.attr("generated") ) { - label.html(message); - } + // replace message on existing label + label.html(message); } else { // create label - label = $("<" + this.settings.errorElement + "/>") - .attr({"for": this.idOrName(element), generated: true}) + label = $("<" + this.settings.errorElement + ">") + .attr("for", this.idOrName(element)) .addClass(this.settings.errorClass) .html(message || ""); if ( this.settings.wrapper ) { @@ -692,7 +697,7 @@ $.extend($.validator, { if ( this.settings.errorPlacement ) { this.settings.errorPlacement(label, $(element) ); } else { - label.insertAfter(element); + label.insertAfter(element); } } } @@ -707,20 +712,20 @@ $.extend($.validator, { this.toShow = this.toShow.add(label); }, - errorsFor: function(element) { + errorsFor: function( element ) { var name = this.idOrName(element); return this.errors().filter(function() { - return $(this).attr('for') === name; + return $(this).attr("for") === name; }); }, - idOrName: function(element) { + idOrName: function( element ) { return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name); }, - validationTargetFor: function(element) { + validationTargetFor: function( element ) { // if radio/checkbox, validate first element in group instead - if (this.checkable(element)) { + if ( this.checkable(element) ) { element = this.findByName( element.name ).not(this.settings.ignore)[0]; } return element; @@ -731,53 +736,53 @@ $.extend($.validator, { }, findByName: function( name ) { - return $(this.currentForm).find('[name="' + name + '"]'); + return $(this.currentForm).find("[name='" + name + "']"); }, - getLength: function(value, element) { + getLength: function( value, element ) { switch( element.nodeName.toLowerCase() ) { - case 'select': + case "select": return $("option:selected", element).length; - case 'input': - if( this.checkable( element) ) { - return this.findByName(element.name).filter(':checked').length; + case "input": + if ( this.checkable( element) ) { + return this.findByName(element.name).filter(":checked").length; } } return value.length; }, - depend: function(param, element) { + depend: function( param, element ) { return this.dependTypes[typeof param] ? this.dependTypes[typeof param](param, element) : true; }, dependTypes: { - "boolean": function(param, element) { + "boolean": function( param, element ) { return param; }, - "string": function(param, element) { + "string": function( param, element ) { return !!$(param, element.form).length; }, - "function": function(param, element) { + "function": function( param, element ) { return param(element); } }, - optional: function(element) { + optional: function( element ) { var val = this.elementValue(element); return !$.validator.methods.required.call(this, val, element) && "dependency-mismatch"; }, - startRequest: function(element) { - if (!this.pending[element.name]) { + startRequest: function( element ) { + if ( !this.pending[element.name] ) { this.pendingRequest++; this.pending[element.name] = true; } }, - stopRequest: function(element, valid) { + stopRequest: function( element, valid ) { this.pendingRequest--; // sometimes synchronization fails, make sure pendingRequest is never < 0 - if (this.pendingRequest < 0) { + if ( this.pendingRequest < 0 ) { this.pendingRequest = 0; } delete this.pending[element.name]; @@ -790,7 +795,7 @@ $.extend($.validator, { } }, - previousValue: function(element) { + previousValue: function( element ) { return $.data(element, "previousValue") || $.data(element, "previousValue", { old: null, valid: true, @@ -811,7 +816,7 @@ $.extend($.validator, { creditcard: {creditcard: true} }, - addClassRules: function(className, rules) { + addClassRules: function( className, rules ) { if ( className.constructor === String ) { this.classRuleSettings[className] = rules; } else { @@ -819,12 +824,12 @@ $.extend($.validator, { } }, - classRules: function(element) { + classRules: function( element ) { var rules = {}; - var classes = $(element).attr('class'); + var classes = $(element).attr("class"); if ( classes ) { - $.each(classes.split(' '), function() { - if (this in $.validator.classRuleSettings) { + $.each(classes.split(" "), function() { + if ( this in $.validator.classRuleSettings ) { $.extend(rules, $.validator.classRuleSettings[this]); } }); @@ -832,19 +837,20 @@ $.extend($.validator, { return rules; }, - attributeRules: function(element) { + attributeRules: function( element ) { var rules = {}; var $element = $(element); + var type = $element[0].getAttribute("type"); for (var method in $.validator.methods) { var value; // support for in both html5 and older browsers - if (method === 'required') { + if ( method === "required" ) { value = $element.get(0).getAttribute(method); // Some browsers return an empty string for the required attribute // and non-HTML5 browsers might have required="" markup - if (value === "") { + if ( value === "" ) { value = true; } // force non-HTML5 browsers to return bool @@ -853,60 +859,69 @@ $.extend($.validator, { value = $element.attr(method); } - if (value) { + // convert the value to a number for number inputs, and for text for backwards compability + // allows type="date" and others to be compared as strings + if ( /min|max/.test( method ) && ( type === null || /number|range|text/.test( type ) ) ) { + value = Number(value); + } + + if ( value ) { rules[method] = value; - } else if ($element[0].getAttribute("type") === method) { + } else if ( type === method && type !== 'range' ) { + // exception: the jquery validate 'range' method + // does not test for the html5 'range' type rules[method] = true; } } // maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs - if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) { + if ( rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength) ) { delete rules.maxlength; } return rules; }, - metadataRules: function(element) { - if (!$.metadata) { - return {}; + dataRules: function( element ) { + var method, value, + rules = {}, $element = $(element); + for (method in $.validator.methods) { + value = $element.data("rule-" + method.toLowerCase()); + if ( value !== undefined ) { + rules[method] = value; + } } - - var meta = $.data(element.form, 'validator').settings.meta; - return meta ? - $(element).metadata()[meta] : - $(element).metadata(); + return rules; }, - staticRules: function(element) { + staticRules: function( element ) { var rules = {}; - var validator = $.data(element.form, 'validator'); - if (validator.settings.rules) { + var validator = $.data(element.form, "validator"); + if ( validator.settings.rules ) { rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {}; } return rules; }, - normalizeRules: function(rules, element) { + normalizeRules: function( rules, element ) { // handle dependency check - $.each(rules, function(prop, val) { + $.each(rules, function( prop, val ) { // ignore rule when param is explicitly false, eg. required:false - if (val === false) { + if ( val === false ) { delete rules[prop]; return; } - if (val.param || val.depends) { + if ( val.param || val.depends ) { var keepRule = true; switch (typeof val.depends) { - case "string": - keepRule = !!$(val.depends, element.form).length; - break; - case "function": - keepRule = val.depends.call(element, element); - break; + case "string": + keepRule = !!$(val.depends, element.form).length; + break; + case "function": + keepRule = val.depends.call(element, element); + break; } - if (keepRule) { + if ( keepRule ) { rules[prop] = val.param !== undefined ? val.param : true; } else { delete rules[prop]; @@ -915,47 +930,48 @@ $.extend($.validator, { }); // evaluate parameters - $.each(rules, function(rule, parameter) { + $.each(rules, function( rule, parameter ) { rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter; }); // clean number parameters - $.each(['minlength', 'maxlength', 'min', 'max'], function() { - if (rules[this]) { + $.each(['minlength', 'maxlength'], function() { + if ( rules[this] ) { rules[this] = Number(rules[this]); } }); $.each(['rangelength', 'range'], function() { - if (rules[this]) { - rules[this] = [Number(rules[this][0]), Number(rules[this][1])]; + var parts; + if ( rules[this] ) { + if ( $.isArray(rules[this]) ) { + rules[this] = [Number(rules[this][0]), Number(rules[this][1])]; + } else if ( typeof rules[this] === "string" ) { + parts = rules[this].split(/[\s,]+/); + rules[this] = [Number(parts[0]), Number(parts[1])]; + } } }); - if ($.validator.autoCreateRanges) { + if ( $.validator.autoCreateRanges ) { // auto-create ranges - if (rules.min && rules.max) { + if ( rules.min && rules.max ) { rules.range = [rules.min, rules.max]; delete rules.min; delete rules.max; } - if (rules.minlength && rules.maxlength) { + if ( rules.minlength && rules.maxlength ) { rules.rangelength = [rules.minlength, rules.maxlength]; delete rules.minlength; delete rules.maxlength; } } - // To support custom messages in metadata ignore rule methods titled "messages" - if (rules.messages) { - delete rules.messages; - } - return rules; }, // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true} - normalizeRule: function(data) { - if( typeof data === "string" ) { + normalizeRule: function( data ) { + if ( typeof data === "string" ) { var transformed = {}; $.each(data.split(/\s/), function() { transformed[this] = true; @@ -966,10 +982,10 @@ $.extend($.validator, { }, // http://docs.jquery.com/Plugins/Validation/Validator/addMethod - addMethod: function(name, method, message) { + addMethod: function( name, method, message ) { $.validator.methods[name] = method; $.validator.messages[name] = message !== undefined ? message : $.validator.messages[name]; - if (method.length < 3) { + if ( method.length < 3 ) { $.validator.addClassRules(name, $.validator.normalizeRule(name)); } }, @@ -977,7 +993,7 @@ $.extend($.validator, { methods: { // http://docs.jquery.com/Plugins/Validation/Methods/required - required: function(value, element, param) { + required: function( value, element, param ) { // check if dependency is met if ( !this.depend(param, element) ) { return "dependency-mismatch"; @@ -993,136 +1009,46 @@ $.extend($.validator, { return $.trim(value).length > 0; }, - // http://docs.jquery.com/Plugins/Validation/Methods/remote - remote: function(value, element, param) { - if ( this.optional(element) ) { - return "dependency-mismatch"; - } - - var previous = this.previousValue(element); - if (!this.settings.messages[element.name] ) { - this.settings.messages[element.name] = {}; - } - previous.originalMessage = this.settings.messages[element.name].remote; - this.settings.messages[element.name].remote = previous.message; - - param = typeof param === "string" && {url:param} || param; - - if ( this.pending[element.name] ) { - return "pending"; - } - if ( previous.old === value ) { - return previous.valid; - } - - previous.old = value; - var validator = this; - this.startRequest(element); - var data = {}; - data[element.name] = value; - $.ajax($.extend(true, { - url: param, - mode: "abort", - port: "validate" + element.name, - dataType: "json", - data: data, - success: function(response) { - validator.settings.messages[element.name].remote = previous.originalMessage; - var valid = response === true || response === "true"; - if ( valid ) { - var submitted = validator.formSubmitted; - validator.prepareElement(element); - validator.formSubmitted = submitted; - validator.successList.push(element); - delete validator.invalid[element.name]; - validator.showErrors(); - } else { - var errors = {}; - var message = response || validator.defaultMessage( element, "remote" ); - errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message; - validator.invalid[element.name] = true; - validator.showErrors(errors); - } - previous.valid = valid; - validator.stopRequest(element, valid); - } - }, param)); - return "pending"; - }, - - // http://docs.jquery.com/Plugins/Validation/Methods/minlength - minlength: function(value, element, param) { - var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element); - return this.optional(element) || length >= param; - }, - - // http://docs.jquery.com/Plugins/Validation/Methods/maxlength - maxlength: function(value, element, param) { - var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element); - return this.optional(element) || length <= param; - }, - - // http://docs.jquery.com/Plugins/Validation/Methods/rangelength - rangelength: function(value, element, param) { - var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element); - return this.optional(element) || ( length >= param[0] && length <= param[1] ); - }, - - // http://docs.jquery.com/Plugins/Validation/Methods/min - min: function( value, element, param ) { - return this.optional(element) || value >= param; - }, - - // http://docs.jquery.com/Plugins/Validation/Methods/max - max: function( value, element, param ) { - return this.optional(element) || value <= param; - }, - - // http://docs.jquery.com/Plugins/Validation/Methods/range - range: function( value, element, param ) { - return this.optional(element) || ( value >= param[0] && value <= param[1] ); - }, - // http://docs.jquery.com/Plugins/Validation/Methods/email - email: function(value, element) { + email: function( value, element ) { // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/ return this.optional(element) || /^((([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.test(value); }, // http://docs.jquery.com/Plugins/Validation/Methods/url - url: function(value, element) { + url: function( value, element ) { // contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/ - return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value); + return this.optional(element) || /^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value); }, // http://docs.jquery.com/Plugins/Validation/Methods/date - date: function(value, element) { - return this.optional(element) || !/Invalid|NaN/.test(new Date(value)); + date: function( value, element ) { + return this.optional(element) || !/Invalid|NaN/.test(new Date(value).toString()); }, // http://docs.jquery.com/Plugins/Validation/Methods/dateISO - dateISO: function(value, element) { + dateISO: function( value, element ) { return this.optional(element) || /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/.test(value); }, // http://docs.jquery.com/Plugins/Validation/Methods/number - number: function(value, element) { + number: function( value, element ) { return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value); }, // http://docs.jquery.com/Plugins/Validation/Methods/digits - digits: function(value, element) { + digits: function( value, element ) { return this.optional(element) || /^\d+$/.test(value); }, // http://docs.jquery.com/Plugins/Validation/Methods/creditcard // based on http://en.wikipedia.org/wiki/Luhn - creditcard: function(value, element) { + creditcard: function( value, element ) { if ( this.optional(element) ) { return "dependency-mismatch"; } // accept only spaces, digits and dashes - if (/[^0-9 \-]+/.test(value)) { + if ( /[^0-9 \-]+/.test(value) ) { return false; } var nCheck = 0, @@ -1134,8 +1060,8 @@ $.extend($.validator, { for (var n = value.length - 1; n >= 0; n--) { var cDigit = value.charAt(n); nDigit = parseInt(cDigit, 10); - if (bEven) { - if ((nDigit *= 2) > 9) { + if ( bEven ) { + if ( (nDigit *= 2) > 9 ) { nDigit -= 9; } } @@ -1146,17 +1072,104 @@ $.extend($.validator, { return (nCheck % 10) === 0; }, + // http://docs.jquery.com/Plugins/Validation/Methods/minlength + minlength: function( value, element, param ) { + var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element); + return this.optional(element) || length >= param; + }, + + // http://docs.jquery.com/Plugins/Validation/Methods/maxlength + maxlength: function( value, element, param ) { + var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element); + return this.optional(element) || length <= param; + }, + + // http://docs.jquery.com/Plugins/Validation/Methods/rangelength + rangelength: function( value, element, param ) { + var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element); + return this.optional(element) || ( length >= param[0] && length <= param[1] ); + }, + + // http://docs.jquery.com/Plugins/Validation/Methods/min + min: function( value, element, param ) { + return this.optional(element) || value >= param; + }, + + // http://docs.jquery.com/Plugins/Validation/Methods/max + max: function( value, element, param ) { + return this.optional(element) || value <= param; + }, + + // http://docs.jquery.com/Plugins/Validation/Methods/range + range: function( value, element, param ) { + return this.optional(element) || ( value >= param[0] && value <= param[1] ); + }, + // http://docs.jquery.com/Plugins/Validation/Methods/equalTo - equalTo: function(value, element, param) { + equalTo: function( value, element, param ) { // bind to the blur event of the target in order to revalidate whenever the target field is updated // TODO find a way to bind the event just once, avoiding the unbind-rebind overhead var target = $(param); - if (this.settings.onfocusout) { + if ( this.settings.onfocusout ) { target.unbind(".validate-equalTo").bind("blur.validate-equalTo", function() { $(element).valid(); }); } return value === target.val(); + }, + + // http://docs.jquery.com/Plugins/Validation/Methods/remote + remote: function( value, element, param ) { + if ( this.optional(element) ) { + return "dependency-mismatch"; + } + + var previous = this.previousValue(element); + if (!this.settings.messages[element.name] ) { + this.settings.messages[element.name] = {}; + } + previous.originalMessage = this.settings.messages[element.name].remote; + this.settings.messages[element.name].remote = previous.message; + + param = typeof param === "string" && {url:param} || param; + + if ( previous.old === value ) { + return previous.valid; + } + + previous.old = value; + var validator = this; + this.startRequest(element); + var data = {}; + data[element.name] = value; + $.ajax($.extend(true, { + url: param, + mode: "abort", + port: "validate" + element.name, + dataType: "json", + data: data, + success: function( response ) { + validator.settings.messages[element.name].remote = previous.originalMessage; + var valid = response === true || response === "true"; + if ( valid ) { + var submitted = validator.formSubmitted; + validator.prepareElement(element); + validator.formSubmitted = submitted; + validator.successList.push(element); + delete validator.invalid[element.name]; + validator.showErrors(); + } else { + var errors = {}; + var message = response || validator.defaultMessage( element, "remote" ); + errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message; + validator.invalid[element.name] = true; + validator.showErrors(errors); + } + previous.valid = valid; + validator.stopRequest(element, valid); + } + }, param)); + return "pending"; } } @@ -1175,9 +1188,9 @@ $.format = $.validator.format; var pendingRequests = {}; // Use a prefilter if available (1.5+) if ( $.ajaxPrefilter ) { - $.ajaxPrefilter(function(settings, _, xhr) { + $.ajaxPrefilter(function( settings, _, xhr ) { var port = settings.port; - if (settings.mode === "abort") { + if ( settings.mode === "abort" ) { if ( pendingRequests[port] ) { pendingRequests[port].abort(); } @@ -1187,59 +1200,29 @@ $.format = $.validator.format; } else { // Proxy ajax var ajax = $.ajax; - $.ajax = function(settings) { + $.ajax = function( settings ) { var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode, port = ( "port" in settings ? settings : $.ajaxSettings ).port; - if (mode === "abort") { + if ( mode === "abort" ) { if ( pendingRequests[port] ) { pendingRequests[port].abort(); } - return (pendingRequests[port] = ajax.apply(this, arguments)); + pendingRequests[port] = ajax.apply(this, arguments); + return pendingRequests[port]; } return ajax.apply(this, arguments); }; } }(jQuery)); -// provides cross-browser focusin and focusout events -// IE has native support, in other browsers, use event caputuring (neither bubbles) - // provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation // handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target (function($) { - // only implement if not provided by jQuery core (since 1.4) - // TODO verify if jQuery 1.4's implementation is compatible with older jQuery special-event APIs - if (!jQuery.event.special.focusin && !jQuery.event.special.focusout && document.addEventListener) { - $.each({ - focus: 'focusin', - blur: 'focusout' - }, function( original, fix ){ - $.event.special[fix] = { - setup:function() { - this.addEventListener( original, handler, true ); - }, - teardown:function() { - this.removeEventListener( original, handler, true ); - }, - handler: function(e) { - var args = arguments; - args[0] = $.event.fix(e); - args[0].type = fix; - return $.event.handle.apply(this, args); - } - }; - function handler(e) { - e = $.event.fix(e); - e.type = fix; - return $.event.handle.call(this, e); - } - }); - } $.extend($.fn, { - validateDelegate: function(delegate, type, handler) { - return this.bind(type, function(event) { + validateDelegate: function( delegate, type, handler ) { + return this.bind(type, function( event ) { var target = $(event.target); - if (target.is(delegate)) { + if ( target.is(delegate) ) { return handler.apply(target, arguments); } }); diff --git a/src/js/dependencies/validateAdditional.js b/src/js/dependencies/validateAdditional.js index f8111e59c37..e8e6903cae3 100644 --- a/src/js/dependencies/validateAdditional.js +++ b/src/js/dependencies/validateAdditional.js @@ -1,18 +1,12 @@ -/*! jQuery Validation Plugin - v1.10.0 - 9/7/2012 -* https://github.com/jzaefferer/jquery-validation -* Copyright (c) 2012 Jörn Zaefferer; Licensed MIT, GPL */ - -/* - * jQuery Validation Plugin 1.10.0 +/*! + * jQuery Validation Plugin 1.11.1 * * http://bassistance.de/jquery-plugins/jquery-plugin-validation/ * http://docs.jquery.com/Plugins/Validation * - * Copyright (c) 2006 - 2011 Jörn Zaefferer - * - * Dual licensed under the MIT and GPL licenses: + * Copyright 2013 Jörn Zaefferer + * Released under the MIT license: * http://www.opensource.org/licenses/mit-license.php - * http://www.gnu.org/licenses/gpl.html */ (function() { @@ -21,7 +15,7 @@ // remove html tags and space chars return value.replace(/<.[^<>]*?>/g, ' ').replace(/ | /gi, ' ') // remove punctuation - .replace(/[.(),;:!?%#$'"_+=\/-]*/g,''); + .replace(/[.(),;:!?%#$'"_+=\/\-]*/g,''); } jQuery.validator.addMethod("maxWords", function(value, element, params) { return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length <= params; @@ -37,10 +31,10 @@ return this.optional(element) || valueStripped.match(regex).length >= params[0] && valueStripped.match(regex).length <= params[1]; }, jQuery.validator.format("Please enter between {0} and {1} words.")); -})(); +}()); jQuery.validator.addMethod("letterswithbasicpunc", function(value, element) { - return this.optional(element) || /^[a-z\-.,()'\"\s]+$/i.test(value); + return this.optional(element) || /^[a-z\-.,()'"\s]+$/i.test(value); }, "Letters or punctuation only please"); jQuery.validator.addMethod("alphanumeric", function(value, element) { @@ -60,7 +54,7 @@ jQuery.validator.addMethod("ziprange", function(value, element) { }, "Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx"); jQuery.validator.addMethod("zipcodeUS", function(value, element) { - return this.optional(element) || /\d{5}-\d{4}$|^\d{5}$/.test(value) + return this.optional(element) || /\d{5}-\d{4}$|^\d{5}$/.test(value); }, "The specified US ZIP Code is invalid"); jQuery.validator.addMethod("integer", function(value, element) { @@ -80,7 +74,7 @@ jQuery.validator.addMethod("integer", function(value, element) { * @cat Plugins/Validate/Methods */ jQuery.validator.addMethod("vinUS", function(v) { - if (v.length != 17) { + if (v.length !== 17) { return false; } var i, n, d, f, cd, cdv; @@ -91,7 +85,7 @@ jQuery.validator.addMethod("vinUS", function(v) { for(i = 0; i < 17; i++){ f = FL[i]; d = v.slice(i,i+1); - if (i == 8) { + if (i === 8) { cdv = d; } if (!isNaN(d)) { @@ -101,7 +95,7 @@ jQuery.validator.addMethod("vinUS", function(v) { if (d.toUpperCase() === LL[n]) { d = VL[n]; d *= f; - if (isNaN(cdv) && n == 8) { + if (isNaN(cdv) && n === 8) { cdv = LL[n]; } break; @@ -111,10 +105,10 @@ jQuery.validator.addMethod("vinUS", function(v) { rs += d; } cd = rs % 11; - if (cd == 10) { + if (cd === 10) { cd = "X"; } - if (cd == cdv) { + if (cd === cdv) { return true; } return false; @@ -142,31 +136,210 @@ jQuery.validator.addMethod("vinUS", function(v) { jQuery.validator.addMethod("dateITA", function(value, element) { var check = false; var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/; - if( re.test(value)){ + if( re.test(value)) { var adata = value.split('/'); var gg = parseInt(adata[0],10); var mm = parseInt(adata[1],10); var aaaa = parseInt(adata[2],10); var xdata = new Date(aaaa,mm-1,gg); - if ( ( xdata.getFullYear() == aaaa ) && ( xdata.getMonth () == mm - 1 ) && ( xdata.getDate() == gg ) ) + if ( ( xdata.getFullYear() === aaaa ) && ( xdata.getMonth() === mm - 1 ) && ( xdata.getDate() === gg ) ){ check = true; - else + } else { check = false; - } else + } + } else { check = false; + } return this.optional(element) || check; }, "Please enter a correct date"); +/** + * IBAN is the international bank account number. + * It has a country - specific format, that is checked here too + */ +jQuery.validator.addMethod("iban", function(value, element) { + // some quick simple tests to prevent needless work + if (this.optional(element)) { + return true; + } + if (!(/^([a-zA-Z0-9]{4} ){2,8}[a-zA-Z0-9]{1,4}|[a-zA-Z0-9]{12,34}$/.test(value))) { + return false; + } + + // check the country code and find the country specific format + var iban = value.replace(/ /g,'').toUpperCase(); // remove spaces and to upper case + var countrycode = iban.substring(0,2); + var bbancountrypatterns = { + 'AL': "\\d{8}[\\dA-Z]{16}", + 'AD': "\\d{8}[\\dA-Z]{12}", + 'AT': "\\d{16}", + 'AZ': "[\\dA-Z]{4}\\d{20}", + 'BE': "\\d{12}", + 'BH': "[A-Z]{4}[\\dA-Z]{14}", + 'BA': "\\d{16}", + 'BR': "\\d{23}[A-Z][\\dA-Z]", + 'BG': "[A-Z]{4}\\d{6}[\\dA-Z]{8}", + 'CR': "\\d{17}", + 'HR': "\\d{17}", + 'CY': "\\d{8}[\\dA-Z]{16}", + 'CZ': "\\d{20}", + 'DK': "\\d{14}", + 'DO': "[A-Z]{4}\\d{20}", + 'EE': "\\d{16}", + 'FO': "\\d{14}", + 'FI': "\\d{14}", + 'FR': "\\d{10}[\\dA-Z]{11}\\d{2}", + 'GE': "[\\dA-Z]{2}\\d{16}", + 'DE': "\\d{18}", + 'GI': "[A-Z]{4}[\\dA-Z]{15}", + 'GR': "\\d{7}[\\dA-Z]{16}", + 'GL': "\\d{14}", + 'GT': "[\\dA-Z]{4}[\\dA-Z]{20}", + 'HU': "\\d{24}", + 'IS': "\\d{22}", + 'IE': "[\\dA-Z]{4}\\d{14}", + 'IL': "\\d{19}", + 'IT': "[A-Z]\\d{10}[\\dA-Z]{12}", + 'KZ': "\\d{3}[\\dA-Z]{13}", + 'KW': "[A-Z]{4}[\\dA-Z]{22}", + 'LV': "[A-Z]{4}[\\dA-Z]{13}", + 'LB': "\\d{4}[\\dA-Z]{20}", + 'LI': "\\d{5}[\\dA-Z]{12}", + 'LT': "\\d{16}", + 'LU': "\\d{3}[\\dA-Z]{13}", + 'MK': "\\d{3}[\\dA-Z]{10}\\d{2}", + 'MT': "[A-Z]{4}\\d{5}[\\dA-Z]{18}", + 'MR': "\\d{23}", + 'MU': "[A-Z]{4}\\d{19}[A-Z]{3}", + 'MC': "\\d{10}[\\dA-Z]{11}\\d{2}", + 'MD': "[\\dA-Z]{2}\\d{18}", + 'ME': "\\d{18}", + 'NL': "[A-Z]{4}\\d{10}", + 'NO': "\\d{11}", + 'PK': "[\\dA-Z]{4}\\d{16}", + 'PS': "[\\dA-Z]{4}\\d{21}", + 'PL': "\\d{24}", + 'PT': "\\d{21}", + 'RO': "[A-Z]{4}[\\dA-Z]{16}", + 'SM': "[A-Z]\\d{10}[\\dA-Z]{12}", + 'SA': "\\d{2}[\\dA-Z]{18}", + 'RS': "\\d{18}", + 'SK': "\\d{20}", + 'SI': "\\d{15}", + 'ES': "\\d{20}", + 'SE': "\\d{20}", + 'CH': "\\d{5}[\\dA-Z]{12}", + 'TN': "\\d{20}", + 'TR': "\\d{5}[\\dA-Z]{17}", + 'AE': "\\d{3}\\d{16}", + 'GB': "[A-Z]{4}\\d{14}", + 'VG': "[\\dA-Z]{4}\\d{16}" + }; + var bbanpattern = bbancountrypatterns[countrycode]; + // As new countries will start using IBAN in the + // future, we only check if the countrycode is known. + // This prevents false negatives, while almost all + // false positives introduced by this, will be caught + // by the checksum validation below anyway. + // Strict checking should return FALSE for unknown + // countries. + if (typeof bbanpattern !== 'undefined') { + var ibanregexp = new RegExp("^[A-Z]{2}\\d{2}" + bbanpattern + "$", ""); + if (!(ibanregexp.test(iban))) { + return false; // invalid country specific format + } + } + + // now check the checksum, first convert to digits + var ibancheck = iban.substring(4,iban.length) + iban.substring(0,4); + var ibancheckdigits = ""; + var leadingZeroes = true; + var charAt; + for (var i =0; i 9 && - phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:(?:\d{5}\)?\s?\d{4,5})|(?:\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3}))|(?:\d{3}\)?\s?\d{3}\s?\d{3,4})|(?:\d{2}\)?\s?\d{4}\s?\d{4}))$/); + phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:\d{2}\)?\s?\d{4}\s?\d{4}|\d{3}\)?\s?\d{3}\s?\d{3,4}|\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3})|\d{5}\)?\s?\d{4,5})$/); }, 'Please specify a valid phone number'); jQuery.validator.addMethod('mobileUK', function(phone_number, element) { - phone_number = phone_number.replace(/\s+|-/g,''); + phone_number = phone_number.replace(/\(|\)|\s+|-/g,''); return this.optional(element) || phone_number.length > 9 && phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[45789]\d{2}|624)\s?\d{3}\s?\d{3})$/); }, 'Please specify a valid mobile number'); //Matches UK landline + mobile, accepting only 01-3 for landline or 07 for mobile to exclude many premium numbers jQuery.validator.addMethod('phonesUK', function(phone_number, element) { - phone_number = phone_number.replace(/\s+|-/g,''); + phone_number = phone_number.replace(/\(|\)|\s+|-/g,''); return this.optional(element) || phone_number.length > 9 && phone_number.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[45789]\d{8}|624\d{6})))$/); }, 'Please specify a valid uk phone number'); // On the above three UK functions, do the following server side processing: -// Compare with ^((?:00\s?|\+)(44)\s?)?\(?0?(?:\)\s?)?([1-9]\d{1,4}\)?[\d\s]+) -// Extract $2 and set $prefix to '+44' if $2 is '44' otherwise set $prefix to '0' -// Extract $3 and remove spaces and parentheses. Phone number is combined $2 and $3. +// Compare original input with this RegEx pattern: +// ^\(?(?:(?:00\)?[\s\-]?\(?|\+)(44)\)?[\s\-]?\(?(?:0\)?[\s\-]?\(?)?|0)([1-9]\d{1,4}\)?[\s\d\-]+)$ +// Extract $1 and set $prefix to '+44' if $1 is '44', otherwise set $prefix to '0' +// Extract $2 and remove hyphens, spaces and parentheses. Phone number is combined $prefix and $2. // A number of very detailed GB telephone number RegEx patterns can also be found at: -// http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_UK_Telephone_Numbers +// http://www.aa-asterisk.org.uk/index.php/Regular_Expressions_for_Validating_and_Formatting_GB_Telephone_Numbers -//Matches UK postcode. based on http://snipplr.com/view/3152/postcode-validation/ -jQuery.validator.addMethod('postcodeUK', function(postcode, element) { - postcode = (postcode.toUpperCase()).replace(/\s+/g,''); - return this.optional(element) || postcode.match(/^([^QZ][^IJZ]{0,1}\d{1,2})(\d[^CIKMOV]{2})$/) || postcode.match(/^([^QV]\d[ABCDEFGHJKSTUW])(\d[^CIKMOV]{2})$/) || postcode.match(/^([^QV][^IJZ]\d[ABEHMNPRVWXY])(\d[^CIKMOV]{2})$/) || postcode.match(/^(GIR)(0AA)$/) || postcode.match(/^(BFPO)(\d{1,4})$/) || postcode.match(/^(BFPO)(C\/O\d{1,3})$/); -}, 'Please specify a valid postcode'); +// Matches UK postcode. Does not match to UK Channel Islands that have their own postcodes (non standard UK) +jQuery.validator.addMethod('postcodeUK', function(value, element) { + return this.optional(element) || /^((([A-PR-UWYZ][0-9])|([A-PR-UWYZ][0-9][0-9])|([A-PR-UWYZ][A-HK-Y][0-9])|([A-PR-UWYZ][A-HK-Y][0-9][0-9])|([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))\s?([0-9][ABD-HJLNP-UW-Z]{2})|(GIR)\s?(0AA))$/i.test(value); +}, 'Please specify a valid UK postcode'); // TODO check if value starts with <, otherwise don't try stripping anything jQuery.validator.addMethod("strippedminlength", function(value, element, param) { @@ -233,14 +406,14 @@ jQuery.validator.addMethod("email2", function(value, element, param) { // same as url, but TLD is optional jQuery.validator.addMethod("url2", function(value, element, param) { - return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value); + return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value); }, jQuery.validator.messages.url); // NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator // Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0 // Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings) jQuery.validator.addMethod("creditcardtypes", function(value, element, param) { - if (/[^0-9-]+/.test(value)) { + if (/[^0-9\-]+/.test(value)) { return false; } @@ -248,48 +421,56 @@ jQuery.validator.addMethod("creditcardtypes", function(value, element, param) { var validTypes = 0x0000; - if (param.mastercard) + if (param.mastercard) { validTypes |= 0x0001; - if (param.visa) + } + if (param.visa) { validTypes |= 0x0002; - if (param.amex) + } + if (param.amex) { validTypes |= 0x0004; - if (param.dinersclub) + } + if (param.dinersclub) { validTypes |= 0x0008; - if (param.enroute) + } + if (param.enroute) { validTypes |= 0x0010; - if (param.discover) + } + if (param.discover) { validTypes |= 0x0020; - if (param.jcb) + } + if (param.jcb) { validTypes |= 0x0040; - if (param.unknown) + } + if (param.unknown) { validTypes |= 0x0080; - if (param.all) + } + if (param.all) { validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080; - + } if (validTypes & 0x0001 && /^(5[12345])/.test(value)) { //mastercard - return value.length == 16; + return value.length === 16; } if (validTypes & 0x0002 && /^(4)/.test(value)) { //visa - return value.length == 16; + return value.length === 16; } if (validTypes & 0x0004 && /^(3[47])/.test(value)) { //amex - return value.length == 15; + return value.length === 15; } if (validTypes & 0x0008 && /^(3(0[012345]|[68]))/.test(value)) { //dinersclub - return value.length == 14; + return value.length === 14; } if (validTypes & 0x0010 && /^(2(014|149))/.test(value)) { //enroute - return value.length == 15; + return value.length === 15; } if (validTypes & 0x0020 && /^(6011)/.test(value)) { //discover - return value.length == 16; + return value.length === 16; } if (validTypes & 0x0040 && /^(3)/.test(value)) { //jcb - return value.length == 16; + return value.length === 16; } if (validTypes & 0x0040 && /^(2131|1800)/.test(value)) { //jcb - return value.length == 15; + return value.length === 15; } if (validTypes & 0x0080) { //unknown return true; @@ -298,11 +479,11 @@ jQuery.validator.addMethod("creditcardtypes", function(value, element, param) { }, "Please enter a valid credit card number."); jQuery.validator.addMethod("ipv4", function(value, element, param) { - return this.optional(element) || /^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/i.test(value); + return this.optional(element) || /^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/i.test(value); }, "Please enter a valid IP v4 address."); jQuery.validator.addMethod("ipv6", function(value, element, param) { - return this.optional(element) || /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i.test(value); + return this.optional(element) || /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i.test(value); }, "Please enter a valid IP v6 address."); /** @@ -378,10 +559,9 @@ jQuery.validator.addMethod("require_from_group", function(value, element, option * */ jQuery.validator.addMethod("skip_or_fill_minimum", function(value, element, options) { - var validator = this; - - numberRequired = options[0]; - selector = options[1]; + var validator = this, + numberRequired = options[0], + selector = options[1]; var numberFilled = $(selector, element.form).filter(function() { return validator.elementValue(this); }).length; @@ -398,27 +578,27 @@ jQuery.validator.addMethod("skip_or_fill_minimum", function(value, element, opti // Accept a value from a file input based on a required mimetype jQuery.validator.addMethod("accept", function(value, element, param) { - // Split mime on commas incase we have multiple types we can accept - var typeParam = typeof param === "string" ? param.replace(/,/g, '|') : "image/*", + // Split mime on commas in case we have multiple types we can accept + var typeParam = typeof param === "string" ? param.replace(/\s/g, '').replace(/,/g, '|') : "image/*", optionalValue = this.optional(element), i, file; // Element is optional - if(optionalValue) { + if (optionalValue) { return optionalValue; } - if($(element).attr("type") === "file") { + if ($(element).attr("type") === "file") { // If we are using a wildcard, make it regex friendly - typeParam = typeParam.replace("*", ".*"); + typeParam = typeParam.replace(/\*/g, ".*"); // Check if the element has a FileList before checking each file - if(element.files && element.files.length) { - for(i = 0; i < element.files.length; i++) { + if (element.files && element.files.length) { + for (i = 0; i < element.files.length; i++) { file = element.files[i]; - // Grab the mimtype from the loaded file, verify it matches - if(!file.type.match(new RegExp( ".?(" + typeParam + ")$", "i"))) { + // Grab the mimetype from the loaded file, verify it matches + if (!file.type.match(new RegExp( ".?(" + typeParam + ")$", "i"))) { return false; } } @@ -434,4 +614,4 @@ jQuery.validator.addMethod("accept", function(value, element, param) { jQuery.validator.addMethod("extension", function(value, element, param) { param = typeof param === "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif"; return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i")); -}, jQuery.format("Please enter a value with a valid extension.")); \ No newline at end of file +}, jQuery.format("Please enter a value with a valid extension.")); From 508742a76331b67a9458b1d70797302ad094dfaf Mon Sep 17 00:00:00 2001 From: Paul Jackson Date: Sun, 24 Mar 2013 00:55:36 -0400 Subject: [PATCH 2/7] Fixed jQuery Validation 1.11.1 compatibility issues. Added bridge for supporting the old class={validate:{}} method. --- src/js/pe-ap.js | 30 ++++--- src/js/workers/formvalid.js | 155 +++++++++++++----------------------- 2 files changed, 77 insertions(+), 108 deletions(-) diff --git a/src/js/pe-ap.js b/src/js/pe-ap.js index 352564c2323..dcd81ba81af 100644 --- a/src/js/pe-ap.js +++ b/src/js/pe-ap.js @@ -843,18 +843,30 @@ dataAttr = $elm.attr('data-' + data_name), dataObj = null; if (dataAttr) { - try { - dataObj = $.parseJSON(dataAttr); - } catch (e) { - // Fallback if data- contains a malformed JSON string (less secure than with a JSON string) - if (dataAttr.indexOf('{') === -1) { - dataAttr = '{' + dataAttr + '}'; - } - dataObj = eval('(' + dataAttr + ')'); - } + dataObj = this.toObject(dataAttr); } $.data(elm, data_name, dataObj); return dataObj; + }, + /** + * Converts a string to an object + * @memberof pe.data + * @function + * @param {string} data_string String to convert to an object (recommend JSON) + * @return {data} Object created by converting the string + */ + toObject: function (data_string) { + var obj = null; + try { + obj = $.parseJSON(data_string); + } catch (e) { + // Fallback if data_string is a malformed JSON string (less secure than with a JSON string) + if (data_string.indexOf('{') === -1) { + data_string = '{' + data_string + '}'; + } + obj = eval('(' + data_string + ')'); + } + return obj; } }, /** diff --git a/src/js/workers/formvalid.js b/src/js/workers/formvalid.js index 6f380572ba1..286aa6805ee 100644 --- a/src/js/workers/formvalid.js +++ b/src/js/workers/formvalid.js @@ -5,8 +5,8 @@ /* * Form validation plugin */ -/*global jQuery: false, pe: false*/ -(function ($) { +/*global jQuery: false*/ +(function($) { "use strict"; var _pe = window.pe || { fn: {} @@ -17,38 +17,37 @@ depends: ['validate', 'validateAdditional', 'metadata'], languages: ['@wet-boew-build.validlanguagelist@'], methods: ['@wet-boew-build.validlanguagemethod@'], - _exec: function (elm) { + _exec: function(elm) { var form = elm.find('form'), formDOM = form.get(0), labels = formDOM.getElementsByTagName('label'), labels_len = labels.length, formElms = form.find('input, select, textarea'), - formElmsDOM = formElms.get(), formElm, $inputs = formElms.filter('input'), - inputs = $inputs.get(), - inputs_len = inputs.length, - input, + pattern = $inputs.filter('[pattern]'), i, len, index, + valItems, string, - nativeAttribute, submitted = false, required = form.find('[required]').attr('aria-required', 'true'), $errorFormId = 'errors-' + (form.attr('id') === undefined ? 'default' : form.attr('id')), validator, - vlang = pe.language.replace('-', '_'), - lang = pe.get_language(vlang, _pe.fn.formvalid.languages, '_'), - mthdlang = pe.get_language(vlang, _pe.fn.formvalid.methods, '_'); + vlang = _pe.language.replace('-', '_'), + lang = _pe.get_language(vlang, _pe.fn.formvalid.languages, '_'), + mthdlang = _pe.get_language(vlang, _pe.fn.formvalid.methods, '_'), + liblocation = _pe.add.liblocation, + suffixExt = _pe.suffix + '.js'; // Load different language strings if page is not in English if (lang !== null) { - pe.add._load(pe.add.liblocation + 'i18n/formvalid/messages_' + lang + pe.suffix + '.js'); + _pe.add._load(liblocation + 'i18n/formvalid/messages_' + lang + suffixExt); } if (mthdlang !== null) { - pe.add._load(pe.add.liblocation + 'i18n/formvalid/methods_' + mthdlang + pe.suffix + '.js'); + _pe.add._load(liblocation + 'i18n/formvalid/methods_' + mthdlang + suffixExt); } // Add space to the end of the labels (so separation between label and error when CSS turned off) @@ -56,82 +55,41 @@ while (len--) { labels[len].innerHTML += ' '; } - - // Move class="{validate:{...}}" to data-rule="{...} - for (i = 0, len = formElmsDOM.length; i !== len; i += 1) { - formElm = formElmsDOM[i]; - string = formElm.className; - index = string.indexOf('{validate'); - if (index !== -1) { - formElm.setAttribute('data-rule', string.substring(string.indexOf('{', index + 1), string.indexOf('}', index + 1) + 1)); - } - } - + // Remove the pattern attribute until it is safe to use with jQuery Validation - len = inputs_len; - if (len !== 0 && inputs[0].hasAttribute !== undefined) { - while (len--) { - input = inputs[len]; - if (nativeAttribute) { - if (input.hasAttribute('pattern')) { - input.removeAttribute('pattern'); - } - } else { - $(input).removeAttr('pattern'); - } - } + len = pattern.length; + while (len--) { + pattern.eq(len).removeAttr('pattern'); } - // TODO: Remove class part when updated to jQuery Validation 1.11.0 or later - function addValidation(target, key, value) { - var targetclass = target.attr('class'), // Remove in jQuery Validation 1.11.0 - pair = key + ':' + value, - datarule = target.attr('data-rule'), - index1 = (targetclass !== undefined ? targetclass.search(/validate\s?:\s?\{/) : -1), // Remove value in jQuery Validation 1.11.0 (keep variable) - len, - valstring; - /**** Remove in jQuery Validation 1.11.0 ****/ - if (index1 !== -1) { // validate:{ already exists - if (targetclass.search("/" + key + "\\s?:/") === -1) { - valstring = targetclass.substring(index1, targetclass.indexOf('{', index1) + 1); - target.attr('class', targetclass.replace(valstring, valstring + pair + ', ')); - } - } else { // validate:{ doesn't exist - target.addClass('{validate:{' + pair + '}}'); - } - /**********/ - if (datarule !== undefined) { // data-rule already exists - len = datarule.length; - index1 = datarule.indexOf('{'); - if (len === 0) { - datarule = '{' + pair + '}'; - } else { - datarule = '{' + pair + ',' + datarule.substring(1) + (index !== -1 ? '}' : ''); - } - } else { - datarule = '{' + pair + '}'; - } - target.attr('data-rule', datarule); - return; + // Special handling for mobile + if (_pe.mobile) { + formDOM.setAttribute('data-ajax', 'false'); + $inputs.filter('[type="checkbox"]').closest('fieldset').attr('data-role', 'controlgroup'); } + // Clear the form and remove error messages on reset + $inputs.filter('[type="reset"]').on('click vclick touchstart', function() { + validator.resetForm(); + var summaryContainer = form.find('#' + $errorFormId); + if (summaryContainer.length > 0) { + summaryContainer.empty(); + } + form.find('[aria-invalid="true"]').removeAttr('aria-invalid'); + }); + // Change form attributes and values that intefere with validation in IE7/8 - if (pe.ie > 0 && pe.ie < 9) { - required.removeAttr('required').each(function () { - addValidation($(this), 'required', 'true'); // Adds required:true to validation:{} + if (_pe.ie > 0 && _pe.ie < 9) { + required.removeAttr('required').each(function() { + this.setAttribute('data-rule-required', 'true'); }); - $inputs.filter('[type="date"]').each(function () { + $inputs.filter('[type="date"]').each(function() { var $this = $(this), parent = $this.wrap('
').parent(), - newelm = $(parent.html().replace('type=' + $this.attr('type'), 'type=text')); + newelm = $(parent.html().replace('type=date', 'type=text')); parent.replaceWith(newelm); }); - } - - // Special handling for mobile - if (pe.mobile) { - formDOM.setAttribute('data-ajax', 'false'); - $inputs.filter('[type="checkbox"]').closest('fieldset').attr('data-role', 'controlgroup'); + formElms = form.find('input, select, textarea'); } // The jQuery validation plug-in in action @@ -144,18 +102,18 @@ // Location for the inline error messages // In this case we will place them in the associated label element - errorPlacement: function (error, element) { + errorPlacement: function(error, element) { error.appendTo(form.find('label[for="' + element.attr('id') + '"]')); }, // Create our error summary that will appear before the form - showErrors: function (errorMap, errorList) { + showErrors: function() { this.defaultShowErrors(); var errors = form.find('strong.error').filter(':not(:hidden)'), errorfields = form.find('input.error, select.error, textarea.error'), summaryContainer = form.find('#' + $errorFormId), - prefixStart = '' + pe.dic.get("%error") + ' ', - prefixEnd = pe.dic.get("%colon") + ' ', + prefixStart = '' + _pe.dic.get("%error") + ' ', + prefixEnd = _pe.dic.get("%colon") + ' ', summary; form.find('[aria-invalid="true"]').removeAttr("aria-invalid"); @@ -168,9 +126,9 @@ } // Post process - summary = '

' + pe.dic.get('%form-not-submitted') + errors.length + (errors.length !== 1 ? pe.dic.get('%errors-found') : pe.dic.get('%error-found')) + '

    '; + summary = '

    ' + _pe.dic.get('%form-not-submitted') + errors.length + (errors.length !== 1 ? _pe.dic.get('%errors-found') : _pe.dic.get('%error-found')) + '

      '; errorfields.attr('aria-invalid', 'true'); - errors.each(function (index) { + errors.each(function(index) { var $this = $(this), prefix = prefixStart + (index + 1) + prefixEnd, label = $this.closest('label'); @@ -185,15 +143,15 @@ // Put focus on the error if the errors are generated by an attempted form submission if (submitted) { - pe.focus(summaryContainer); + _pe.focus(summaryContainer); } // Move the focus to the associated input when error message link is triggered // a simple href anchor link doesnt seem to place focus inside the input - if (pe.ie === 0 || pe.ie > 7) { - form.find('.errorContainer a').on('click vclick', function () { - var label_top = pe.focus($($(this).attr('href'))).prev().offset().top; - if (pe.mobile) { + if (_pe.ie === 0 || _pe.ie > 7) { + form.find('.errorContainer a').on('click vclick', function() { + var label_top = _pe.focus($($(this).attr('href'))).prev().offset().top; + if (_pe.mobile) { $.mobile.silentScroll(label_top); } else { _pe.document.scrollTop(label_top); @@ -207,20 +165,19 @@ summaryContainer.detach(); } }, //end of showErrors() - invalidHandler: function (form, validator) { + invalidHandler: function() { submitted = true; } }); //end of validate() - // Clear the form and remove error messages on reset - $inputs.filter('[type="reset"]').on('click vclick touchstart', function () { - validator.resetForm(); - var summaryContainer = form.find('#' + $errorFormId); - if (summaryContainer.length > 0) { - summaryContainer.empty(); - } - form.find('[aria-invalid="true"]').removeAttr('aria-invalid'); - }); + // Add class="{validate:{...}}" as jQuery Validation rules + valItems = formElms.filter('[class*="{validate"]'); + for (i = 0, len = valItems.length; i !== len; i += 1) { + formElm = valItems.eq(i); + string = formElm.attr('class'); + index = string.indexOf('{validate'); + formElm.rules('add', _pe.data.toObject(string.substring(string.indexOf('{', index + 1), string.indexOf('}', index + 1) + 1))); + } return elm; } // end of exec From a6b050d2e072acd667fc4be0a39df9c0c15cd811 Mon Sep 17 00:00:00 2001 From: Paul Jackson Date: Sun, 24 Mar 2013 01:04:11 -0400 Subject: [PATCH 3/7] Updated form validation working exampes to the new data-rule-* approach. --- demos/formvalid/formvalid-eng.html | 16 ++++++++-------- demos/formvalid/formvalid-fra.html | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/demos/formvalid/formvalid-eng.html b/demos/formvalid/formvalid-eng.html index 79b4fcc652f..ac417bf3bc5 100644 --- a/demos/formvalid/formvalid-eng.html +++ b/demos/formvalid/formvalid-eng.html @@ -115,22 +115,22 @@

      Form validation

      - - - + + +
      Other examples - + - + - - - + + +
      diff --git a/demos/formvalid/formvalid-fra.html b/demos/formvalid/formvalid-fra.html index 681eab63ab0..3c3cff8e5b7 100644 --- a/demos/formvalid/formvalid-fra.html +++ b/demos/formvalid/formvalid-fra.html @@ -115,22 +115,22 @@

      Validation des formulaires

      - - - + + + - +
      Autres exemples - + - + - - - + + +
      From 86ac2e9ad27365081198a551467ab043adc19d2e Mon Sep 17 00:00:00 2001 From: Paul Jackson Date: Sun, 24 Mar 2013 01:06:54 -0400 Subject: [PATCH 4/7] Updated jQuery Validation localization files. --- src/js/i18n/formvalid/messages_ar.js | 2 +- src/js/i18n/formvalid/messages_bg.js | 2 +- src/js/i18n/formvalid/messages_ca.js | 2 +- src/js/i18n/formvalid/messages_cs.js | 2 +- src/js/i18n/formvalid/messages_da.js | 2 +- src/js/i18n/formvalid/messages_de.js | 2 +- src/js/i18n/formvalid/messages_el.js | 2 +- src/js/i18n/formvalid/messages_es.js | 2 +- src/js/i18n/formvalid/messages_et.js | 2 +- src/js/i18n/formvalid/messages_eu.js | 2 +- src/js/i18n/formvalid/messages_fa.js | 4 +-- src/js/i18n/formvalid/messages_fi.js | 14 +++++----- src/js/i18n/formvalid/messages_fr.js | 2 +- src/js/i18n/formvalid/messages_he.js | 30 ++++++++++----------- src/js/i18n/formvalid/messages_hr.js | 36 ++++++++++++------------- src/js/i18n/formvalid/messages_hu.js | 6 +++-- src/js/i18n/formvalid/messages_it.js | 2 +- src/js/i18n/formvalid/messages_ja.js | 2 +- src/js/i18n/formvalid/messages_ka.js | 6 ++--- src/js/i18n/formvalid/messages_kk.js | 4 +-- src/js/i18n/formvalid/messages_ko.js | 25 +++++++++++++++++ src/js/i18n/formvalid/messages_lt.js | 2 +- src/js/i18n/formvalid/messages_lv.js | 2 +- src/js/i18n/formvalid/messages_my.js | 25 +++++++++++++++++ src/js/i18n/formvalid/messages_nl.js | 14 ++++++++-- src/js/i18n/formvalid/messages_no.js | 2 +- src/js/i18n/formvalid/messages_pl.js | 2 +- src/js/i18n/formvalid/messages_pt_BR.js | 2 +- src/js/i18n/formvalid/messages_pt_PT.js | 2 +- src/js/i18n/formvalid/messages_ro.js | 2 +- src/js/i18n/formvalid/messages_ru.js | 4 +-- src/js/i18n/formvalid/messages_si.js | 2 +- src/js/i18n/formvalid/messages_sk.js | 2 +- src/js/i18n/formvalid/messages_sl.js | 2 +- src/js/i18n/formvalid/messages_sr.js | 2 +- src/js/i18n/formvalid/messages_sv.js | 6 ++--- src/js/i18n/formvalid/messages_th.js | 2 +- src/js/i18n/formvalid/messages_tr.js | 2 +- src/js/i18n/formvalid/messages_uk.js | 2 +- src/js/i18n/formvalid/messages_vi.js | 2 +- src/js/i18n/formvalid/messages_zh.js | 2 +- src/js/i18n/formvalid/messages_zh_TW.js | 4 +-- src/js/i18n/formvalid/methods_de.js | 2 +- src/js/i18n/formvalid/methods_nl.js | 2 +- src/js/i18n/formvalid/methods_pt.js | 2 +- 45 files changed, 152 insertions(+), 90 deletions(-) create mode 100644 src/js/i18n/formvalid/messages_ko.js create mode 100644 src/js/i18n/formvalid/messages_my.js diff --git a/src/js/i18n/formvalid/messages_ar.js b/src/js/i18n/formvalid/messages_ar.js index b6557cac068..6df9495f53e 100644 --- a/src/js/i18n/formvalid/messages_ar.js +++ b/src/js/i18n/formvalid/messages_ar.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: AR (Arabic; العربية) */ diff --git a/src/js/i18n/formvalid/messages_bg.js b/src/js/i18n/formvalid/messages_bg.js index be6dbb9880d..10ba1d32295 100644 --- a/src/js/i18n/formvalid/messages_bg.js +++ b/src/js/i18n/formvalid/messages_bg.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: BG (Bulgarian; български език) */ diff --git a/src/js/i18n/formvalid/messages_ca.js b/src/js/i18n/formvalid/messages_ca.js index 12ebdc66d9d..940c37f5475 100644 --- a/src/js/i18n/formvalid/messages_ca.js +++ b/src/js/i18n/formvalid/messages_ca.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: CA (Catalan; català) */ diff --git a/src/js/i18n/formvalid/messages_cs.js b/src/js/i18n/formvalid/messages_cs.js index 7e851ecb818..43cc3ad1b04 100644 --- a/src/js/i18n/formvalid/messages_cs.js +++ b/src/js/i18n/formvalid/messages_cs.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: CS (Czech; čeština, český jazyk) */ diff --git a/src/js/i18n/formvalid/messages_da.js b/src/js/i18n/formvalid/messages_da.js index 823c9c257ca..bcceb202e19 100644 --- a/src/js/i18n/formvalid/messages_da.js +++ b/src/js/i18n/formvalid/messages_da.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: DA (Danish; dansk) */ diff --git a/src/js/i18n/formvalid/messages_de.js b/src/js/i18n/formvalid/messages_de.js index 724e16a938b..073853e97b3 100644 --- a/src/js/i18n/formvalid/messages_de.js +++ b/src/js/i18n/formvalid/messages_de.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: DE (German, Deutsch) */ diff --git a/src/js/i18n/formvalid/messages_el.js b/src/js/i18n/formvalid/messages_el.js index 0ebc6de9051..6cd5a1de4ef 100644 --- a/src/js/i18n/formvalid/messages_el.js +++ b/src/js/i18n/formvalid/messages_el.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: EL (Greek; ελληνικά) */ diff --git a/src/js/i18n/formvalid/messages_es.js b/src/js/i18n/formvalid/messages_es.js index 158b0e5d192..3a30eee8f35 100644 --- a/src/js/i18n/formvalid/messages_es.js +++ b/src/js/i18n/formvalid/messages_es.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: ES (Spanish; Español) */ diff --git a/src/js/i18n/formvalid/messages_et.js b/src/js/i18n/formvalid/messages_et.js index 558b29fcc32..aaa26777f57 100644 --- a/src/js/i18n/formvalid/messages_et.js +++ b/src/js/i18n/formvalid/messages_et.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: ET (Estonian; eesti, eesti keel) */ diff --git a/src/js/i18n/formvalid/messages_eu.js b/src/js/i18n/formvalid/messages_eu.js index f9a7b71210e..8f02f1b229e 100644 --- a/src/js/i18n/formvalid/messages_eu.js +++ b/src/js/i18n/formvalid/messages_eu.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: EU (Basque; euskara, euskera) */ diff --git a/src/js/i18n/formvalid/messages_fa.js b/src/js/i18n/formvalid/messages_fa.js index e9b40bf7658..38163525cb9 100644 --- a/src/js/i18n/formvalid/messages_fa.js +++ b/src/js/i18n/formvalid/messages_fa.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: FA (Persian; فارسی) */ @@ -21,5 +21,5 @@ range: $.validator.format("لطفا مقداری بین {0} تا {1} حرف وارد کنید."), max: $.validator.format("لطفا مقداری کمتر از {0} حرف وارد کنید."), min: $.validator.format("لطفا مقداری بیشتر از {0} حرف وارد کنید.") - }); + }); }(jQuery)); \ No newline at end of file diff --git a/src/js/i18n/formvalid/messages_fi.js b/src/js/i18n/formvalid/messages_fi.js index f3b35255f4c..a1fc03c5b98 100644 --- a/src/js/i18n/formvalid/messages_fi.js +++ b/src/js/i18n/formvalid/messages_fi.js @@ -1,23 +1,23 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: FI (Finnish; suomi, suomen kieli) */ (function ($) { $.extend($.validator.messages, { required: "Tämä kenttä on pakollinen.", - maxlength: $.validator.format("Voit syöttää enintään {0} merkkiä."), - minlength: $.validator.format("Vähintään {0} merkkiä."), - rangelength: $.validator.format("Syötä vähintään {0} ja enintään {1} merkkiä."), email: "Syötä oikea sähköpostiosoite.", url: "Syötä oikea URL osoite.", date: "Syötä oike päivämäärä.", dateISO: "Syötä oike päivämäärä (VVVV-MM-DD).", number: "Syötä numero.", + creditcard: "Syötä voimassa oleva luottokorttinumero.", digits: "Syötä pelkästään numeroita.", equalTo: "Syötä sama arvo uudestaan.", + maxlength: $.validator.format("Voit syöttää enintään {0} merkkiä."), + minlength: $.validator.format("Vähintään {0} merkkiä."), + rangelength: $.validator.format("Syötä vähintään {0} ja enintään {1} merkkiä."), range: $.validator.format("Syötä arvo {0} ja {1} väliltä."), max: $.validator.format("Syötä arvo joka on pienempi tai yhtä suuri kuin {0}."), - min: $.validator.format("Syötä arvo joka on yhtä suuri tai suurempi kuin {0}."), - creditcard: "Syötä voimassa oleva luottokorttinumero." + min: $.validator.format("Syötä arvo joka on yhtä suuri tai suurempi kuin {0}.") }); -}(jQuery)); \ No newline at end of file +}(jQuery)); diff --git a/src/js/i18n/formvalid/messages_fr.js b/src/js/i18n/formvalid/messages_fr.js index 3adb36f6b74..c976ff460e6 100644 --- a/src/js/i18n/formvalid/messages_fr.js +++ b/src/js/i18n/formvalid/messages_fr.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: FR (French; français) */ diff --git a/src/js/i18n/formvalid/messages_he.js b/src/js/i18n/formvalid/messages_he.js index b2350df0ab0..373feee7fcc 100644 --- a/src/js/i18n/formvalid/messages_he.js +++ b/src/js/i18n/formvalid/messages_he.js @@ -1,25 +1,25 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: HE (Hebrew; עברית) */ (function ($) { $.extend($.validator.messages, { - required: ".השדה הזה הינו שדה חובה", - remote: "נא לתקן שדה זה.", + required: "השדה הזה הינו שדה חובה", + remote: "נא לתקן שדה זה", email: "נא למלא כתובת דוא\"ל חוקית", - url: "נא למלא כתובת אינטרנט חוקית.", + url: "נא למלא כתובת אינטרנט חוקית", date: "נא למלא תאריך חוקי", - dateISO: "נא למלא תאריך חוקי (ISO).", - number: "נא למלא מספר.", - digits: ".נא למלא רק מספרים", - creditcard: "נא למלא מספר כרטיס אשראי חוקי.", - equalTo: "נא למלא את אותו ערך שוב.", - accept: "נא למלא ערך עם סיומת חוקית.", + dateISO: "נא למלא תאריך חוקי (ISO)", + number: "נא למלא מספר", + digits: "נא למלא רק מספרים", + creditcard: "נא למלא מספר כרטיס אשראי חוקי", + equalTo: "נא למלא את אותו ערך שוב", + accept: "נא למלא ערך עם סיומת חוקית", maxlength: $.validator.format(".נא לא למלא יותר מ- {0} תווים"), - minlength: $.validator.format("נא למלא לפחות {0} תווים."), - rangelength: $.validator.format("נא למלא ערך בין {0} ל- {1} תווים."), - range: $.validator.format("נא למלא ערך בין {0} ל- {1}."), - max: $.validator.format("נא למלא ערך קטן או שווה ל- {0}."), - min: $.validator.format("נא למלא ערך גדול או שווה ל- {0}.") + minlength: $.validator.format("נא למלא לפחות {0} תווים"), + rangelength: $.validator.format("נא למלא ערך בין {0} ל- {1} תווים"), + range: $.validator.format("נא למלא ערך בין {0} ל- {1}"), + max: $.validator.format("נא למלא ערך קטן או שווה ל- {0}"), + min: $.validator.format("נא למלא ערך גדול או שווה ל- {0}") }); }(jQuery)); \ No newline at end of file diff --git a/src/js/i18n/formvalid/messages_hr.js b/src/js/i18n/formvalid/messages_hr.js index e08aac064a5..895ae2dca97 100644 --- a/src/js/i18n/formvalid/messages_hr.js +++ b/src/js/i18n/formvalid/messages_hr.js @@ -1,25 +1,25 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: HR (Croatia; hrvatski jezik) */ (function ($) { $.extend($.validator.messages, { - required: "Ovo polje je obavezno.", - remote: "Ovo polje treba popraviti.", - email: "Unesite ispravnu e-mail adresu.", - url: "Unesite ispravan URL.", - date: "Unesite ispravan datum.", - dateISO: "Unesite ispravan datum (ISO).", - number: "Unesite ispravan broj.", - digits: "Unesite samo brojeve.", - creditcard: "Unesite ispravan broj kreditne kartice.", - equalTo: "Unesite ponovo istu vrijednost.", - accept: "Unesite vrijednost sa ispravnom ekstenzijom.", - maxlength: $.validator.format("Maksimalni broj znakova je {0} ."), - minlength: $.validator.format("Minimalni broj znakova je {0} ."), - rangelength: $.validator.format("Unesite vrijednost između {0} i {1} znakova."), - range: $.validator.format("Unesite vrijednost između {0} i {1}."), - max: $.validator.format("Unesite vrijednost manju ili jednaku {0}."), - min: $.validator.format("Unesite vrijednost veću ili jednaku {0}.") + required: "Ovo polje je obavezno.", + remote: "Ovo polje treba popraviti.", + email: "Unesite ispravnu e-mail adresu.", + url: "Unesite ispravan URL.", + date: "Unesite ispravan datum.", + dateISO: "Unesite ispravan datum (ISO).", + number: "Unesite ispravan broj.", + digits: "Unesite samo brojeve.", + creditcard: "Unesite ispravan broj kreditne kartice.", + equalTo: "Unesite ponovo istu vrijednost.", + accept: "Unesite vrijednost sa ispravnom ekstenzijom.", + maxlength: $.validator.format("Maksimalni broj znakova je {0} ."), + minlength: $.validator.format("Minimalni broj znakova je {0} ."), + rangelength: $.validator.format("Unesite vrijednost između {0} i {1} znakova."), + range: $.validator.format("Unesite vrijednost između {0} i {1}."), + max: $.validator.format("Unesite vrijednost manju ili jednaku {0}."), + min: $.validator.format("Unesite vrijednost veću ili jednaku {0}.") }); }(jQuery)); \ No newline at end of file diff --git a/src/js/i18n/formvalid/messages_hu.js b/src/js/i18n/formvalid/messages_hu.js index f699af4e4e6..cd73fc3eefe 100644 --- a/src/js/i18n/formvalid/messages_hu.js +++ b/src/js/i18n/formvalid/messages_hu.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: HU (Hungarian; Magyar) */ @@ -17,6 +17,8 @@ range: $.validator.format("{0} és {1} közé kell esnie."), max: $.validator.format("Nem lehet nagyobb, mint {0}."), min: $.validator.format("Nem lehet kisebb, mint {0}."), - creditcard: "Érvényes hitelkártyaszámnak kell lennie." + creditcard: "Érvényes hitelkártyaszámnak kell lennie.", + remote: "Kérem javítsa ki ezt a mezőt.", + dateISO: "Kérem írjon be egy érvényes dátumot (ISO)." }); }(jQuery)); \ No newline at end of file diff --git a/src/js/i18n/formvalid/messages_it.js b/src/js/i18n/formvalid/messages_it.js index 3930e0fd184..19323b0f560 100644 --- a/src/js/i18n/formvalid/messages_it.js +++ b/src/js/i18n/formvalid/messages_it.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: IT (Italian; Italiano) */ diff --git a/src/js/i18n/formvalid/messages_ja.js b/src/js/i18n/formvalid/messages_ja.js index 03fa43aa8a7..cb060c9c129 100644 --- a/src/js/i18n/formvalid/messages_ja.js +++ b/src/js/i18n/formvalid/messages_ja.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: JA (Japanese; 日本語) */ diff --git a/src/js/i18n/formvalid/messages_ka.js b/src/js/i18n/formvalid/messages_ka.js index e9417d2ffda..319363e4df3 100644 --- a/src/js/i18n/formvalid/messages_ka.js +++ b/src/js/i18n/formvalid/messages_ka.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: KA (Georgian; ქართული) */ @@ -19,7 +19,7 @@ minlength: $.validator.format("აუცილებელია შეიყვანოთ მინიმუმ {0} სიმბოლო."), rangelength: $.validator.format("ტექსტში სიმბოლოების რაოდენობა უნდა იყოს {0}-დან {1}-მდე."), range: $.validator.format("გთხოვთ შეიყვანოთ ციფრი {0}-დან {1}-მდე."), - max: $.validator.format("გთხოვთ შეიყვანოთ ციფრი რომელიც ნაკლებია ან უდრის {0}-ს."), - min: $.validator.format("გთხოვთ შეიყვანოთ ციფრი რომელიც მეტია ან უდრის {0}-ს.") + max: $.validator.format("გთხოვთ შეიყვანოთ ციფრი რომელიც ნაკლებია ან უდრის {0}-ს."), + min: $.validator.format("გთხოვთ შეიყვანოთ ციფრი რომელიც მეტია ან უდრის {0}-ს.") }); }(jQuery)); \ No newline at end of file diff --git a/src/js/i18n/formvalid/messages_kk.js b/src/js/i18n/formvalid/messages_kk.js index 43fe82d8aa6..dd9276fb5c1 100644 --- a/src/js/i18n/formvalid/messages_kk.js +++ b/src/js/i18n/formvalid/messages_kk.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: KK (Kazakh; қазақ тілі) */ @@ -15,7 +15,7 @@ creditcard: "Несие картасының нөмірін дұрыс енгізуіңізді сұраймыз.", equalTo: "Осы мәнді қайта енгізуіңізді сұраймыз.", accept: "Файлдың кеңейтуін дұрыс таңдаңыз.", - maxlength: $.format("Ұзындығы {0} символдан көр болмасын."), + maxlength: $.format("Ұзындығы {0} символдан көр болмасын."), minlength: $.format("Ұзындығы {0} символдан аз болмасын."), rangelength: $.format("Ұзындығы {0}-{1} дейін мән енгізуіңізді сұраймыз."), range: $.format("Пожалуйста, введите число от {0} до {1}. - {0} - {1} санын енгізуіңізді сұраймыз."), diff --git a/src/js/i18n/formvalid/messages_ko.js b/src/js/i18n/formvalid/messages_ko.js new file mode 100644 index 00000000000..1e6bba91669 --- /dev/null +++ b/src/js/i18n/formvalid/messages_ko.js @@ -0,0 +1,25 @@ +/* + * Translated default messages for the jQuery validation plugin. + * Locale: KO (Korean; 한국어) + */ +(function ($) { + $.extend($.validator.messages, { + required: "필수 항목입니다.", + remote: "항목을 수정하세요.", + email: "유효하지 않은 E-Mail주소입니다.", + url: "유효하지 않은 주소입니다.", + date: "옳바른 날짜를 입력하세요.", + dateISO: "옳바른 날짜(ISO)를 입력하세요.", + number: "유효한 숫자가 아닙니다.", + digits: "숫자만 입력 가능합니다.", + creditcard: "신용카드번호가 바르지 않습니다.", + equalTo: "같은값을 다시 입력하세요.", + accept: "옳바른 확장자가 아닙니다.", + maxlength: $.format("{0}자를 넘을 수 없습니다. "), + minlength: $.format("{0}자 이하로 입력하세요."), + rangelength: $.format("문자 길이를 {0} 에서 {1} 사이의로 입력하세요."), + range: $.format("{0} 에서 {1} 값을 입력하세요."), + max: $.format("{0} 이하의 값을 입력하세요."), + min: $.format("{0} 이상의 값을 입력하세요.") + }); +}(jQuery)); diff --git a/src/js/i18n/formvalid/messages_lt.js b/src/js/i18n/formvalid/messages_lt.js index 9eef88bf340..856aaeb8b1a 100644 --- a/src/js/i18n/formvalid/messages_lt.js +++ b/src/js/i18n/formvalid/messages_lt.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: LT (Lithuanian; lietuvių kalba) */ diff --git a/src/js/i18n/formvalid/messages_lv.js b/src/js/i18n/formvalid/messages_lv.js index 94f01380154..959a9759c2e 100644 --- a/src/js/i18n/formvalid/messages_lv.js +++ b/src/js/i18n/formvalid/messages_lv.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: LV (Latvian; latviešu valoda) */ diff --git a/src/js/i18n/formvalid/messages_my.js b/src/js/i18n/formvalid/messages_my.js new file mode 100644 index 00000000000..95fe7270f73 --- /dev/null +++ b/src/js/i18n/formvalid/messages_my.js @@ -0,0 +1,25 @@ +/* + * Translated default messages for the jQuery validation plugin. + * Locale: MY (Malay; Melayu) + */ +(function ($) { + $.extend($.validator.messages, { + required: "Medan ini diperlukan.", + remote: "Sila betulkan medan ini.", + email: "Sila masukkan alamat emel yang betul.", + url: "Sila masukkan URL yang betul.", + date: "Sila masukkan tarikh yang betul.", + dateISO: "Sila masukkan tarikh(ISO) yang betul.", + number: "Sila masukkan nombor yang betul.", + digits: "Sila masukkan nilai digit sahaja.", + creditcard: "Sila masukkan nombor kredit kad yang betul.", + equalTo: "Sila masukkan nilai yang sama semula.", + accept: "Sila masukkan nilai yang telah diterima.", + maxlength: $.validator.format("Sila masukkan nilai tidak lebih dari {0} aksara."), + minlength: $.validator.format("Sila masukkan nilai sekurang-kurangnya {0} aksara."), + rangelength: $.validator.format("Sila masukkan panjang nilai antara {0} dan {1} aksara."), + range: $.validator.format("Sila masukkan nilai antara {0} dan {1} aksara."), + max: $.validator.format("Sila masukkan nilai yang kurang atau sama dengan {0}."), + min: $.validator.format("Sila masukkan nilai yang lebih atau sama dengan {0}.") + }); +}(jQuery)); \ No newline at end of file diff --git a/src/js/i18n/formvalid/messages_nl.js b/src/js/i18n/formvalid/messages_nl.js index 55f1783536f..39f335d7a4d 100644 --- a/src/js/i18n/formvalid/messages_nl.js +++ b/src/js/i18n/formvalid/messages_nl.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: NL (Dutch; Nederlands, Vlaams) */ @@ -20,6 +20,16 @@ rangelength: $.validator.format("Vul hier een waarde in van minimaal {0} en maximaal {1} tekens."), range: $.validator.format("Vul hier een waarde in van minimaal {0} en maximaal {1}."), max: $.validator.format("Vul hier een waarde in kleiner dan of gelijk aan {0}."), - min: $.validator.format("Vul hier een waarde in groter dan of gelijk aan {0}.") + min: $.validator.format("Vul hier een waarde in groter dan of gelijk aan {0}."), + + // for validations in additional-methods.js + iban: "Vul hier een geldig IBAN in.", + dateNL: "Vul hier een geldige datum in.", + phoneNL: "Vul hier een geldig Nederlands telefoonnummer in.", + mobileNL: "Vul hier een geldig Nederlands mobiel telefoonnummer in.", + postalcodeNL: "Vul hier een geldige postcode in.", + bankaccountNL: "Vul hier een geldig bankrekeningnummer in.", + giroaccountNL: "Vul hier een geldig gironummer in.", + bankorgiroaccountNL: "Vul hier een geldig bank- of gironummer in." }); }(jQuery)); \ No newline at end of file diff --git a/src/js/i18n/formvalid/messages_no.js b/src/js/i18n/formvalid/messages_no.js index 435fa6c1e38..9ba6d2f5b5d 100644 --- a/src/js/i18n/formvalid/messages_no.js +++ b/src/js/i18n/formvalid/messages_no.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: NO (Norwegian; Norsk) */ diff --git a/src/js/i18n/formvalid/messages_pl.js b/src/js/i18n/formvalid/messages_pl.js index d651565f8a4..fcf2f6df867 100644 --- a/src/js/i18n/formvalid/messages_pl.js +++ b/src/js/i18n/formvalid/messages_pl.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: PL (Polish; język polski, polszczyzna) */ diff --git a/src/js/i18n/formvalid/messages_pt_BR.js b/src/js/i18n/formvalid/messages_pt_BR.js index 8e1e8ba4246..dd9434802c3 100644 --- a/src/js/i18n/formvalid/messages_pt_BR.js +++ b/src/js/i18n/formvalid/messages_pt_BR.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: PT (Portuguese; português) * Region: BR (Brazil) diff --git a/src/js/i18n/formvalid/messages_pt_PT.js b/src/js/i18n/formvalid/messages_pt_PT.js index 988fcc99aa5..41b239e3345 100644 --- a/src/js/i18n/formvalid/messages_pt_PT.js +++ b/src/js/i18n/formvalid/messages_pt_PT.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: PT (Portuguese; português) * Region: PT (Portugal) diff --git a/src/js/i18n/formvalid/messages_ro.js b/src/js/i18n/formvalid/messages_ro.js index bc7bdb6c70d..6286f80f767 100644 --- a/src/js/i18n/formvalid/messages_ro.js +++ b/src/js/i18n/formvalid/messages_ro.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: RO (Romanian, limba română) */ diff --git a/src/js/i18n/formvalid/messages_ru.js b/src/js/i18n/formvalid/messages_ru.js index 5b864f06d0a..46dc78168e3 100644 --- a/src/js/i18n/formvalid/messages_ru.js +++ b/src/js/i18n/formvalid/messages_ru.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: RU (Russian; русский язык) */ @@ -19,7 +19,7 @@ minlength: $.validator.format("Пожалуйста, введите не меньше {0} символов."), rangelength: $.validator.format("Пожалуйста, введите значение длиной от {0} до {1} символов."), range: $.validator.format("Пожалуйста, введите число от {0} до {1}."), - max: $.validator.format("Пожалуйста, введите число, меньшее или равное {0}."), + max: $.validator.format("Пожалуйста, введите число, меньшее или равное {0}."), min: $.validator.format("Пожалуйста, введите число, большее или равное {0}.") }); }(jQuery)); \ No newline at end of file diff --git a/src/js/i18n/formvalid/messages_si.js b/src/js/i18n/formvalid/messages_si.js index 0a962470b85..0c280e80db9 100644 --- a/src/js/i18n/formvalid/messages_si.js +++ b/src/js/i18n/formvalid/messages_si.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: SI (Slovenian) */ diff --git a/src/js/i18n/formvalid/messages_sk.js b/src/js/i18n/formvalid/messages_sk.js index 6faebfc3e1b..bc6340abfcd 100644 --- a/src/js/i18n/formvalid/messages_sk.js +++ b/src/js/i18n/formvalid/messages_sk.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: SK (Slovak; slovenčina, slovenský jazyk) */ diff --git a/src/js/i18n/formvalid/messages_sl.js b/src/js/i18n/formvalid/messages_sl.js index 30a8a42c37d..fa53d6d721c 100644 --- a/src/js/i18n/formvalid/messages_sl.js +++ b/src/js/i18n/formvalid/messages_sl.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Language: SL (Slovenian; slovenski jezik) */ diff --git a/src/js/i18n/formvalid/messages_sr.js b/src/js/i18n/formvalid/messages_sr.js index 76979cf4890..73b5ec7ae1a 100644 --- a/src/js/i18n/formvalid/messages_sr.js +++ b/src/js/i18n/formvalid/messages_sr.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: SR (Serbian; српски језик) */ diff --git a/src/js/i18n/formvalid/messages_sv.js b/src/js/i18n/formvalid/messages_sv.js index 58b485d3a27..26db0913a3e 100644 --- a/src/js/i18n/formvalid/messages_sv.js +++ b/src/js/i18n/formvalid/messages_sv.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: SV (Swedish; Svenska) */ @@ -11,7 +11,7 @@ email: "Ange en korrekt e-postadress.", url: "Ange en korrekt URL.", date: "Ange ett korrekt datum.", - dateISO: "Ange ett korrekt datum (&ARING;&ARING;&ARING;&ARING;-MM-DD).", + dateISO: "Ange ett korrekt datum (ÅÅÅÅ-MM-DD).", number: "Ange ett korrekt nummer.", digits: "Ange endast siffror.", equalTo: "Ange samma värde igen.", @@ -20,4 +20,4 @@ min: $.validator.format("Ange ett värde som är större eller lika med {0}."), creditcard: "Ange ett korrekt kreditkortsnummer." }); -}(jQuery)); \ No newline at end of file +}(jQuery)); diff --git a/src/js/i18n/formvalid/messages_th.js b/src/js/i18n/formvalid/messages_th.js index ab2132cc815..f3b02355674 100644 --- a/src/js/i18n/formvalid/messages_th.js +++ b/src/js/i18n/formvalid/messages_th.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: TH (Thai; ไทย) */ diff --git a/src/js/i18n/formvalid/messages_tr.js b/src/js/i18n/formvalid/messages_tr.js index 0ba825e108c..1c412180a21 100644 --- a/src/js/i18n/formvalid/messages_tr.js +++ b/src/js/i18n/formvalid/messages_tr.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: TR (Turkish; Türkçe) */ diff --git a/src/js/i18n/formvalid/messages_uk.js b/src/js/i18n/formvalid/messages_uk.js index 425fc8423b6..cdea494b1d7 100644 --- a/src/js/i18n/formvalid/messages_uk.js +++ b/src/js/i18n/formvalid/messages_uk.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: UK (Ukrainian; українська мова) */ diff --git a/src/js/i18n/formvalid/messages_vi.js b/src/js/i18n/formvalid/messages_vi.js index d09e6c670d6..fd5f2b5d5e1 100644 --- a/src/js/i18n/formvalid/messages_vi.js +++ b/src/js/i18n/formvalid/messages_vi.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: VI (Vietnamese; Tiếng Việt) */ diff --git a/src/js/i18n/formvalid/messages_zh.js b/src/js/i18n/formvalid/messages_zh.js index f458831bbf3..2c4d5c30843 100644 --- a/src/js/i18n/formvalid/messages_zh.js +++ b/src/js/i18n/formvalid/messages_zh.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: ZH (Chinese, 中文 (Zhōngwén), 汉语, 漢語) */ diff --git a/src/js/i18n/formvalid/messages_zh_TW.js b/src/js/i18n/formvalid/messages_zh_TW.js index 6a1f45e63f4..ec0a2ffbc55 100644 --- a/src/js/i18n/formvalid/messages_zh_TW.js +++ b/src/js/i18n/formvalid/messages_zh_TW.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: ZH (Chinese; 中文 (Zhōngwén), 汉语, 漢語) * Region: TW (Taiwan) @@ -23,4 +23,4 @@ max: $.validator.format("請輸入不大於 {0} 的數值"), min: $.validator.format("請輸入不小於 {0} 的數值") }); -}(jQuery)); +}(jQuery)); \ No newline at end of file diff --git a/src/js/i18n/formvalid/methods_de.js b/src/js/i18n/formvalid/methods_de.js index b645ccfda1b..3e8ac8437e0 100644 --- a/src/js/i18n/formvalid/methods_de.js +++ b/src/js/i18n/formvalid/methods_de.js @@ -1,4 +1,4 @@ -/*! +/* * Localized default methods for the jQuery validation plugin. * Locale: DE */ diff --git a/src/js/i18n/formvalid/methods_nl.js b/src/js/i18n/formvalid/methods_nl.js index bd3c168ce33..450041b14e9 100644 --- a/src/js/i18n/formvalid/methods_nl.js +++ b/src/js/i18n/formvalid/methods_nl.js @@ -1,4 +1,4 @@ -/*! +/* * Localized default methods for the jQuery validation plugin. * Locale: NL */ diff --git a/src/js/i18n/formvalid/methods_pt.js b/src/js/i18n/formvalid/methods_pt.js index c13b12fae1a..21879d3bb66 100644 --- a/src/js/i18n/formvalid/methods_pt.js +++ b/src/js/i18n/formvalid/methods_pt.js @@ -1,4 +1,4 @@ -/*! +/* * Localized default methods for the jQuery validation plugin. * Locale: PT_BR */ From 26a6d0e38be083402cdba18bda2a23be4d06e1ee Mon Sep 17 00:00:00 2001 From: Paul Jackson Date: Sun, 24 Mar 2013 01:09:00 -0400 Subject: [PATCH 5/7] Updated jQuery Validation localization files. --- src/js/i18n/formvalid/messages_pt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/i18n/formvalid/messages_pt.js b/src/js/i18n/formvalid/messages_pt.js index 988fcc99aa5..41b239e3345 100644 --- a/src/js/i18n/formvalid/messages_pt.js +++ b/src/js/i18n/formvalid/messages_pt.js @@ -1,4 +1,4 @@ -/*! +/* * Translated default messages for the jQuery validation plugin. * Locale: PT (Portuguese; português) * Region: PT (Portugal) From b3dddec960f441fc4d02bc96867767edd61e76e6 Mon Sep 17 00:00:00 2001 From: Paul Jackson Date: Sun, 24 Mar 2013 03:14:00 -0400 Subject: [PATCH 6/7] Added aria-live region to report any changes in inline error messages. --- src/js/workers/formvalid.js | 42 ++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/js/workers/formvalid.js b/src/js/workers/formvalid.js index 286aa6805ee..95e88df871b 100644 --- a/src/js/workers/formvalid.js +++ b/src/js/workers/formvalid.js @@ -39,8 +39,12 @@ lang = _pe.get_language(vlang, _pe.fn.formvalid.languages, '_'), mthdlang = _pe.get_language(vlang, _pe.fn.formvalid.methods, '_'), liblocation = _pe.add.liblocation, - suffixExt = _pe.suffix + '.js'; + suffixExt = _pe.suffix + '.js', + ariaLive = $('
      '); + // Append the aria-live region (for provide message updates to screen readers) + elm.append(ariaLive); + // Load different language strings if page is not in English if (lang !== null) { _pe.add._load(liblocation + 'i18n/formvalid/messages_' + lang + suffixExt); @@ -107,17 +111,18 @@ }, // Create our error summary that will appear before the form - showErrors: function() { + showErrors: function(errorMap) { this.defaultShowErrors(); var errors = form.find('strong.error').filter(':not(:hidden)'), errorfields = form.find('input.error, select.error, textarea.error'), summaryContainer = form.find('#' + $errorFormId), - prefixStart = '' + _pe.dic.get("%error") + ' ', - prefixEnd = _pe.dic.get("%colon") + ' ', - summary; + prefixStart = '' + _pe.dic.get('%error') + ' ', + prefixEnd = _pe.dic.get('%colon') + ' ', + summary, + key; - form.find('[aria-invalid="true"]').removeAttr("aria-invalid"); - if (errors.length > 0) { + form.find('[aria-invalid="true"]').removeAttr('aria-invalid'); + if (errors.length !== 0) { // Create our container if one doesn't already exist if (summaryContainer.length === 0) { summaryContainer = $('
      ').prependTo(form); @@ -144,6 +149,23 @@ // Put focus on the error if the errors are generated by an attempted form submission if (submitted) { _pe.focus(summaryContainer); + } else { + // Update the aria-live region as necessary + i = 0; + for (key in errorMap) { + if (errorMap.hasOwnProperty(key)) { + i += 1; + break; + } + } + if (i !== 0) { + string = errors.filter('[for=' + key + ']')[0].innerHTML; + if (string !== ariaLive.html()) { + ariaLive.html(string); + } + } else if (ariaLive.html().length !== 0) { + ariaLive.empty() + } } // Move the focus to the associated input when error message link is triggered @@ -159,9 +181,13 @@ return false; }); } - + submitted = false; } else { + // Update the aria-live region as necessary + if (ariaLive.html().length !== 0) { + ariaLive.empty(); + } summaryContainer.detach(); } }, //end of showErrors() From a2add2ed4d5b28a16402e277068517aefded3ceb Mon Sep 17 00:00:00 2001 From: Paul Jackson Date: Sun, 24 Mar 2013 03:14:39 -0400 Subject: [PATCH 7/7] Added missing semi-colon. --- src/js/workers/formvalid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/workers/formvalid.js b/src/js/workers/formvalid.js index 95e88df871b..d19789250ed 100644 --- a/src/js/workers/formvalid.js +++ b/src/js/workers/formvalid.js @@ -164,7 +164,7 @@ ariaLive.html(string); } } else if (ariaLive.html().length !== 0) { - ariaLive.empty() + ariaLive.empty(); } }