jquery-form-validator-rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +30 -2
- data/app/assets/javascripts/date.dev.js +81 -0
- data/app/assets/javascripts/file.dev.js +195 -0
- data/app/assets/javascripts/file.js +1 -1
- data/app/assets/javascripts/form-test.html +422 -0
- data/app/assets/javascripts/html5.dev.js +144 -0
- data/app/assets/javascripts/html5.js +1 -1
- data/app/assets/javascripts/jquery.form-validator.js +229 -251
- data/app/assets/javascripts/jquery.form-validator.min.js +10 -0
- data/app/assets/javascripts/location.dev.js +78 -0
- data/app/assets/javascripts/qunit.html +635 -0
- data/app/assets/javascripts/security.dev.js +51 -24
- data/app/assets/javascripts/security.js +1 -1
- data/app/assets/javascripts/sweden.dev.js +1 -1
- data/app/assets/javascripts/uk.dev.js +1 -1
- data/lib/jquery/form/validator/rails/version.rb +1 -1
- metadata +21 -14
@@ -0,0 +1,10 @@
|
|
1
|
+
/**
|
2
|
+
* jQuery Form Validator
|
3
|
+
* ------------------------------------------
|
4
|
+
* Created by Victor Jonsson <http://www.victorjonsson.se>
|
5
|
+
*
|
6
|
+
* @website http://formvalidator.net/
|
7
|
+
* @license Dual licensed under the MIT or GPL Version 2 licenses
|
8
|
+
* @version 2.2.beta.50
|
9
|
+
*/
|
10
|
+
(function($){"use strict";var $window=$(window),_applyErrorStyle=function($elem,conf){$elem.addClass(conf.errorElementClass).removeClass("valid");var $parent=$elem.parent();if($parent.hasClass("input-group"))$parent=$parent.parent();$parent.addClass(conf.inputParentClassOnError).removeClass(conf.inputParentClassOnSuccess);if(conf.borderColorOnError!==""){$elem.css("border-color",conf.borderColorOnError)}},_removeErrorStyle=function($elem,conf){$elem.each(function(){var $this=$(this),$parent=$this.parent();if($parent.hasClass("input-group"))$parent=$parent.parent();_setInlineErrorMessage($this,"",conf,conf.errorMessagePosition);$this.removeClass("valid").removeClass(conf.errorElementClass).css("border-color","");$parent.removeClass(conf.inputParentClassOnError).removeClass(conf.inputParentClassOnSuccess).find("."+conf.errorMessageClass).remove()})},_setInlineErrorMessage=function($input,mess,conf,$messageContainer){var custom=_getInlineErrorElement($input);if(custom){custom.innerHTML=mess}else if(typeof $messageContainer=="object"){var $found=false;$messageContainer.find("."+conf.errorMessageClass).each(function(){if(this.inputReferer==$input[0]){$found=$(this);return false}});if($found){if(!mess){$found.remove()}else{$found.html(mess)}}else{var $mess=$('<div class="'+conf.errorMessageClass+'">'+mess+"</div>");$mess[0].inputReferer=$input[0];$messageContainer.prepend($mess)}}else{var $parent=$input.parent();if($parent.hasClass("input-group"))$parent=$parent.parent();var $mess=$parent.find("."+conf.errorMessageClass+".help-block");if($mess.length==0){$mess=$("<span></span>").addClass("help-block").addClass(conf.errorMessageClass);$mess.appendTo($parent)}$mess.html(mess)}},_getInlineErrorElement=function($input,conf){return document.getElementById($input.attr("name")+"_err_msg")},_templateMessage=function($form,title,errorMessages,conf){var messages=conf.errorMessageTemplate.messages.replace(/\{errorTitle\}/g,title);var fields=[];$.each(errorMessages,function(i,msg){fields.push(conf.errorMessageTemplate.field.replace(/\{msg\}/g,msg))});messages=messages.replace(/\{fields\}/g,fields.join(""));var container=conf.errorMessageTemplate.container.replace(/\{errorMessageClass\}/g,conf.errorMessageClass);container=container.replace(/\{messages\}/g,messages);$form.children().eq(0).before(container)};$.fn.validateOnBlur=function(language,settings){this.find("input[data-validation],textarea[data-validation],select[data-validation]").bind("blur.validation",function(){$(this).validateInputOnBlur(language,settings,true,"blur")});if(settings.validateCheckboxRadioOnClick){this.find("input[type=checkbox][data-validation],input[type=radio][data-validation]").bind("click.validation",function(){$(this).validateInputOnBlur(language,settings,true,"click")})}return this};$.fn.validateOnEvent=function(language,settings){this.find("input[data-validation][data-validation-event],textarea[data-validation][data-validation-event],select[data-validation][data-validation-event]").each(function(){var $el=$(this),etype=$el.valAttr("event");if(etype){$el.bind(etype+".validation",function(){$(this).validateInputOnBlur(language,settings,true,etype)})}});return this};$.fn.showHelpOnFocus=function(attrName){if(!attrName){attrName="data-validation-help"}this.find(".has-help-txt").valAttr("has-keyup-event",false).removeClass("has-help-txt");this.find("textarea,input").each(function(){var $elem=$(this),className="jquery_form_help_"+($elem.attr("name")||"").replace(/(:|\.|\[|\])/g,""),help=$elem.attr(attrName);if(help){$elem.addClass("has-help-txt").unbind("focus.help").bind("focus.help",function(){var $help=$elem.parent().find("."+className);if($help.length==0){$help=$("<span />").addClass(className).addClass("help").addClass("help-block").text(help).hide();$elem.after($help)}$help.fadeIn()}).unbind("blur.help").bind("blur.help",function(){$(this).parent().find("."+className).fadeOut("slow")})}});return this};$.fn.validateInputOnBlur=function(language,conf,attachKeyupEvent,eventType){$.formUtils.eventType=eventType;if((this.valAttr("suggestion-nr")||this.valAttr("postpone")||this.hasClass("hasDatepicker"))&&!window.postponedValidation){var _self=this,postponeTime=this.valAttr("postpone")||200;window.postponedValidation=function(){_self.validateInputOnBlur(language,conf,attachKeyupEvent,eventType);window.postponedValidation=false};setTimeout(function(){if(window.postponedValidation){window.postponedValidation()}},postponeTime);return this}language=$.extend({},$.formUtils.LANG,language||{});_removeErrorStyle(this,conf);var $elem=this,$form=$elem.closest("form"),validationRule=$elem.attr(conf.validationRuleAttribute),validation=$.formUtils.validateInput($elem,language,$.extend({},conf,{errorMessagePosition:"element"}),$form,eventType);if(validation===true){$elem.addClass("valid").parent().addClass(conf.inputParentClassOnSuccess)}else if(validation!==null){_applyErrorStyle($elem,conf);_setInlineErrorMessage($elem,validation,conf,conf.errorMessagePosition);if(attachKeyupEvent){$elem.unbind("keyup.validation").bind("keyup.validation",function(){$(this).validateInputOnBlur(language,conf,false,"keyup")})}}return this};$.fn.valAttr=function(name,val){if(val===undefined){return this.attr("data-validation-"+name)}else if(val===false||val===null){return this.removeAttr("data-validation-"+name)}else{if(name.length>0)name="-"+name;return this.attr("data-validation"+name,val)}};$.fn.isValid=function(language,conf,displayError){if($.formUtils.isLoadingModules){var $self=this;setTimeout(function(){$self.isValid(language,conf,displayError)},200);return null}conf=$.extend({},$.formUtils.defaultConfig(),conf||{});language=$.extend({},$.formUtils.LANG,language||{});displayError=displayError!==false;if($.formUtils.errorDisplayPreventedWhenHalted){delete $.formUtils.errorDisplayPreventedWhenHalted;displayError=false}$.formUtils.isValidatingEntireForm=true;$.formUtils.haltValidation=false;var addErrorMessage=function(mess,$elem){if($.inArray(mess,errorMessages)<0){errorMessages.push(mess)}errorInputs.push($elem);$elem.attr("current-error",mess);if(displayError)_applyErrorStyle($elem,conf)},checkedInputs=[],errorMessages=[],errorInputs=[],$form=this,ignoreInput=function(name,type){if(type==="submit"||type==="button"||type=="reset"){return true}return $.inArray(name,conf.ignore||[])>-1};if(displayError){$form.find("."+conf.errorMessageClass+".alert").remove();_removeErrorStyle($form.find("."+conf.errorElementClass+",.valid"),conf)}$form.find("input,textarea,select").filter(':not([type="submit"],[type="button"])').each(function(){var $elem=$(this),elementType=$elem.attr("type"),isCheckboxOrRadioBtn=elementType=="radio"||elementType=="checkbox",elementName=$elem.attr("name");if(!ignoreInput(elementName,elementType)&&(!isCheckboxOrRadioBtn||$.inArray(elementName,checkedInputs)<0)){if(isCheckboxOrRadioBtn)checkedInputs.push(elementName);var validation=$.formUtils.validateInput($elem,language,conf,$form,"submit");if(validation!=null){if(validation!==true){addErrorMessage(validation,$elem)}else{$elem.valAttr("current-error",false).addClass("valid").parent().addClass("has-success")}}}});if(typeof conf.onValidate=="function"){var errors=conf.onValidate($form);if($.isArray(errors)){$.each(errors,function(i,err){addErrorMessage(err.message,err.element)})}else if(errors&&errors.element&&errors.message){addErrorMessage(errors.message,errors.element)}}$.formUtils.isValidatingEntireForm=false;if(!$.formUtils.haltValidation&&errorInputs.length>0){if(displayError){if(conf.errorMessagePosition==="top"){_templateMessage($form,language.errorTitle,errorMessages,conf)}else if(conf.errorMessagePosition==="custom"){if(typeof conf.errorMessageCustom==="function"){conf.errorMessageCustom($form,language.errorTitle,errorMessages,conf)}}else{$.each(errorInputs,function(i,$input){_setInlineErrorMessage($input,$input.attr("current-error"),conf,conf.errorMessagePosition)})}if(conf.scrollToTopOnError){$window.scrollTop($form.offset().top-20)}}return false}if(!displayError&&$.formUtils.haltValidation){$.formUtils.errorDisplayPreventedWhenHalted=true}return!$.formUtils.haltValidation};$.fn.validateForm=function(language,conf){if(window.console&&typeof window.console.warn=="function"){window.console.warn("Use of deprecated function $.validateForm, use $.isValid instead")}return this.isValid(language,conf,true)};$.fn.restrictLength=function(maxLengthElement){new $.formUtils.lengthRestriction(this,maxLengthElement);return this};$.fn.addSuggestions=function(settings){var sugs=false;this.find("input").each(function(){var $field=$(this);sugs=$.split($field.attr("data-suggestions"));if(sugs.length>0&&!$field.hasClass("has-suggestions")){$.formUtils.suggest($field,sugs,settings);$field.addClass("has-suggestions")}});return this};$.split=function(val,func){if(typeof func!="function"){if(!val)return[];var values=[];$.each(val.split(func?func:/[,|-\s]\s*/g),function(i,str){str=$.trim(str);if(str.length)values.push(str)});return values}else if(val){$.each(val.split(/[,|-\s]\s*/g),function(i,str){str=$.trim(str);if(str.length)return func(str,i)})}};$.validate=function(conf){var defaultConf=$.extend($.formUtils.defaultConfig(),{form:"form",validateOnEvent:true,validateOnBlur:true,validateCheckboxRadioOnClick:true,showHelpOnFocus:true,addSuggestions:true,modules:"",onModulesLoaded:null,language:false,onSuccess:false,onError:false,onElementValidate:false});conf=$.extend(defaultConf,conf||{});$(conf.form).each(function(i,form){var $form=$(form);$window.trigger("formValidationSetup",[$form]);$form.find(".has-help-txt").unbind("focus.validation").unbind("blur.validation");$form.removeClass("has-validation-callback").unbind("submit.validation").unbind("reset.validation").find("input[data-validation],textarea[data-validation]").unbind("blur.validation");$form.bind("submit.validation",function(){var $form=$(this);if($.formUtils.haltValidation){return false}if($.formUtils.isLoadingModules){setTimeout(function(){$form.trigger("submit.validation")},200);return false}var valid=$form.isValid(conf.language,conf);if($.formUtils.haltValidation){return false}else{if(valid&&typeof conf.onSuccess=="function"){var callbackResponse=conf.onSuccess($form);if(callbackResponse===false)return false}else if(!valid&&typeof conf.onError=="function"){conf.onError($form);return false}else{return valid}}}).bind("reset.validation",function(){$(this).find("."+conf.errorMessageClass+".alert").remove();_removeErrorStyle($(this).find("."+conf.errorElementClass+",.valid"),conf)}).addClass("has-validation-callback");if(conf.showHelpOnFocus){$form.showHelpOnFocus()}if(conf.addSuggestions){$form.addSuggestions()}if(conf.validateOnBlur){$form.validateOnBlur(conf.language,conf);$form.bind("html5ValidationAttrsFound",function(){$form.validateOnBlur(conf.language,conf)})}if(conf.validateOnEvent){$form.validateOnEvent(conf.language,conf)}});if(conf.modules!=""){if(typeof conf.onModulesLoaded=="function"){$window.one("validatorsLoaded",conf.onModulesLoaded)}$.formUtils.loadModules(conf.modules)}};$.formUtils={defaultConfig:function(){return{ignore:[],errorElementClass:"error",borderColorOnError:"red",errorMessageClass:"form-error",validationRuleAttribute:"data-validation",validationErrorMsgAttribute:"data-validation-error-msg",errorMessagePosition:"element",errorMessageTemplate:{container:'<div class="{errorMessageClass} alert alert-danger">{messages}</div>',messages:"<strong>{errorTitle}</strong><ul>{fields}</ul>",field:"<li>{msg}</li>"},errorMessageCustom:_templateMessage,scrollToTopOnError:true,dateFormat:"yyyy-mm-dd",addValidClassOnAll:false,decimalSeparator:".",inputParentClassOnError:"has-error",inputParentClassOnSuccess:"has-success"}},validators:{},_events:{load:[],valid:[],invalid:[]},haltValidation:false,isValidatingEntireForm:false,addValidator:function(validator){var name=validator.name.indexOf("validate_")===0?validator.name:"validate_"+validator.name;if(validator.validateOnKeyUp===undefined)validator.validateOnKeyUp=true;this.validators[name]=validator},isLoadingModules:false,loadedModules:{},loadModules:function(modules,path,fireEvent){if(fireEvent===undefined)fireEvent=true;if($.formUtils.isLoadingModules){setTimeout(function(){$.formUtils.loadModules(modules,path,fireEvent)});return}var hasLoadedAnyModule=false,loadModuleScripts=function(modules,path){var moduleList=$.split(modules),numModules=moduleList.length,moduleLoadedCallback=function(){numModules--;if(numModules==0){$.formUtils.isLoadingModules=false;if(fireEvent&&hasLoadedAnyModule){$window.trigger("validatorsLoaded")}}};if(numModules>0){$.formUtils.isLoadingModules=true}var cacheSuffix="?__="+(new Date).getTime(),appendToElement=document.getElementsByTagName("head")[0]||document.getElementsByTagName("body")[0];$.each(moduleList,function(i,modName){modName=$.trim(modName);if(modName.length==0){moduleLoadedCallback()}else{var scriptUrl=path+modName+(modName.substr(-3)==".js"?"":".js"),script=document.createElement("SCRIPT");if(scriptUrl in $.formUtils.loadedModules){moduleLoadedCallback()}else{$.formUtils.loadedModules[scriptUrl]=1;hasLoadedAnyModule=true;script.type="text/javascript";script.onload=moduleLoadedCallback;script.src=scriptUrl+(scriptUrl.substr(-7)==".dev.js"?cacheSuffix:"");script.onreadystatechange=function(){if(this.readyState=="complete"||this.readyState=="loaded"){moduleLoadedCallback();this.onload=null;this.onreadystatechange=null}};appendToElement.appendChild(script)}}})};if(path){loadModuleScripts(modules,path)}else{var findScriptPathAndLoadModules=function(){var foundPath=false;$('script[src*="form-validator"]').each(function(){foundPath=this.src.substr(0,this.src.lastIndexOf("/"))+"/";if(foundPath=="/")foundPath="";return false});if(foundPath!==false){loadModuleScripts(modules,foundPath);return true}return false};if(!findScriptPathAndLoadModules()){$(findScriptPathAndLoadModules)}}},validateInput:function($elem,language,conf,$form,eventContext){if($elem.attr("disabled"))return null;$elem.trigger("beforeValidation");var value=$elem.val()||"",optional=$elem.valAttr("optional"),validationDependsOnCheckedInput=false,validationDependentInputIsChecked=false,validateIfCheckedElement=false,validateIfCheckedElementName=$elem.valAttr("if-checked");if(validateIfCheckedElementName!=null){validationDependsOnCheckedInput=true;validateIfCheckedElement=$form.find('input[name="'+validateIfCheckedElementName+'"]');if(validateIfCheckedElement.prop("checked")){validationDependentInputIsChecked=true}}if(!value&&optional==="true"||validationDependsOnCheckedInput&&!validationDependentInputIsChecked){return conf.addValidClassOnAll?true:null}var validationRules=$elem.attr(conf.validationRuleAttribute),validationErrorMsg=true;if(!validationRules){return conf.addValidClassOnAll?true:null}$.split(validationRules,function(rule){if(rule.indexOf("validate_")!==0){rule="validate_"+rule}var validator=$.formUtils.validators[rule];if(validator&&typeof validator["validatorFunction"]=="function"){if(rule=="validate_checkbox_group"){$elem=$("[name='"+$elem.attr("name")+"']:eq(0)")}var isValid=null;if(eventContext!="keyup"||validator.validateOnKeyUp){isValid=validator.validatorFunction(value,$elem,conf,language,$form)}if(!isValid){validationErrorMsg=null;if(isValid!==null){validationErrorMsg=$elem.attr(conf.validationErrorMsgAttribute+"-"+rule.replace("validate_",""));if(!validationErrorMsg){validationErrorMsg=$elem.attr(conf.validationErrorMsgAttribute);if(!validationErrorMsg){validationErrorMsg=language[validator.errorMessageKey];if(!validationErrorMsg)validationErrorMsg=validator.errorMessage}}}return false}}else{throw new Error('Using undefined validator "'+rule+'"')}}," ");var result;if(typeof validationErrorMsg=="string"){$elem.trigger("validation",false);result=validationErrorMsg}else if(validationErrorMsg===null&&!conf.addValidClassOnAll){result=null}else{$elem.trigger("validation",true);result=true}if(typeof conf.onElementValidate=="function"&&result!==null){conf.onElementValidate(result===true,$elem,$form,validationErrorMsg)}return result},parseDate:function(val,dateFormat){var divider=dateFormat.replace(/[a-zA-Z]/gi,"").substring(0,1),regexp="^",formatParts=dateFormat.split(divider||null),matches,day,month,year;$.each(formatParts,function(i,part){regexp+=(i>0?"\\"+divider:"")+"(\\d{"+part.length+"})"});regexp+="$";matches=val.match(new RegExp(regexp));if(matches===null){return false}var findDateUnit=function(unit,formatParts,matches){for(var i=0;i<formatParts.length;i++){if(formatParts[i].substring(0,1)===unit){return $.formUtils.parseDateInt(matches[i+1])}}return-1};month=findDateUnit("m",formatParts,matches);day=findDateUnit("d",formatParts,matches);year=findDateUnit("y",formatParts,matches);if(month===2&&day>28&&(year%4!==0||year%100===0&&year%400!==0)||month===2&&day>29&&(year%4===0||year%100!==0&&year%400===0)||month>12||month===0){return false}if(this.isShortMonth(month)&&day>30||!this.isShortMonth(month)&&day>31||day===0){return false}return[year,month,day]},parseDateInt:function(val){if(val.indexOf("0")===0){val=val.replace("0","")}return parseInt(val,10)},isShortMonth:function(m){return m%2===0&&m<7||m%2!==0&&m>7},lengthRestriction:function($inputElement,$maxLengthElement){var maxChars=parseInt($maxLengthElement.text(),10),charsLeft=0,countCharacters=function(){var numChars=$inputElement.val().length;if(numChars>maxChars){var currScrollTopPos=$inputElement.scrollTop();$inputElement.val($inputElement.val().substring(0,maxChars));$inputElement.scrollTop(currScrollTopPos)}charsLeft=maxChars-numChars;if(charsLeft<0)charsLeft=0;$maxLengthElement.text(charsLeft)};$($inputElement).bind("keydown keyup keypress focus blur",countCharacters).bind("cut paste",function(){setTimeout(countCharacters,100)});$(document).bind("ready",countCharacters)},numericRangeCheck:function(value,rangeAllowed){var range=$.split(rangeAllowed);var minmax=parseInt(rangeAllowed.substr(3),10);if(range.length==2&&(value<parseInt(range[0],10)||value>parseInt(range[1],10))){return["out",range[0],range[1]]}else if(rangeAllowed.indexOf("min")===0&&value<minmax){return["min",minmax]}else if(rangeAllowed.indexOf("max")===0&&value>minmax){return["max",minmax]}return["ok"]},_numSuggestionElements:0,_selectedSuggestion:null,_previousTypedVal:null,suggest:function($elem,suggestions,settings){var conf={css:{maxHeight:"150px",background:"#FFF",lineHeight:"150%",textDecoration:"underline",overflowX:"hidden",overflowY:"auto",border:"#CCC solid 1px",borderTop:"none",cursor:"pointer"},activeSuggestionCSS:{background:"#E9E9E9"}},setSuggsetionPosition=function($suggestionContainer,$input){var offset=$input.offset();$suggestionContainer.css({width:$input.outerWidth(),left:offset.left+"px",top:offset.top+$input.outerHeight()+"px"})};if(settings)$.extend(conf,settings);conf.css["position"]="absolute";conf.css["z-index"]=9999;$elem.attr("autocomplete","off");if(this._numSuggestionElements===0){$window.bind("resize",function(){$(".jquery-form-suggestions").each(function(){var $container=$(this),suggestID=$container.attr("data-suggest-container");setSuggsetionPosition($container,$(".suggestions-"+suggestID).eq(0))})})}this._numSuggestionElements++;var onSelectSuggestion=function($el){var suggestionId=$el.valAttr("suggestion-nr");$.formUtils._selectedSuggestion=null;$.formUtils._previousTypedVal=null;$(".jquery-form-suggestion-"+suggestionId).fadeOut("fast")};$elem.data("suggestions",suggestions).valAttr("suggestion-nr",this._numSuggestionElements).unbind("focus.suggest").bind("focus.suggest",function(){$(this).trigger("keyup");$.formUtils._selectedSuggestion=null}).unbind("keyup.suggest").bind("keyup.suggest",function(){var $input=$(this),foundSuggestions=[],val=$.trim($input.val()).toLocaleLowerCase();if(val==$.formUtils._previousTypedVal){return}else{$.formUtils._previousTypedVal=val}var hasTypedSuggestion=false,suggestionId=$input.valAttr("suggestion-nr"),$suggestionContainer=$(".jquery-form-suggestion-"+suggestionId);$suggestionContainer.scrollTop(0);if(val!=""){var findPartial=val.length>2;$.each($input.data("suggestions"),function(i,suggestion){var lowerCaseVal=suggestion.toLocaleLowerCase();if(lowerCaseVal==val){foundSuggestions.push("<strong>"+suggestion+"</strong>");hasTypedSuggestion=true;return false}else if(lowerCaseVal.indexOf(val)===0||findPartial&&lowerCaseVal.indexOf(val)>-1){foundSuggestions.push(suggestion.replace(new RegExp(val,"gi"),"<strong>$&</strong>"))}})}if(hasTypedSuggestion||foundSuggestions.length==0&&$suggestionContainer.length>0){$suggestionContainer.hide()}else if(foundSuggestions.length>0&&$suggestionContainer.length==0){$suggestionContainer=$("<div></div>").css(conf.css).appendTo("body");$elem.addClass("suggestions-"+suggestionId);$suggestionContainer.attr("data-suggest-container",suggestionId).addClass("jquery-form-suggestions").addClass("jquery-form-suggestion-"+suggestionId)}else if(foundSuggestions.length>0&&!$suggestionContainer.is(":visible")){$suggestionContainer.show()}if(foundSuggestions.length>0&&val.length!=foundSuggestions[0].length){setSuggsetionPosition($suggestionContainer,$input);$suggestionContainer.html("");$.each(foundSuggestions,function(i,text){$("<div></div>").append(text).css({overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",padding:"5px"}).addClass("form-suggest-element").appendTo($suggestionContainer).click(function(){$input.focus();$input.val($(this).text());onSelectSuggestion($input)})})}}).unbind("keydown.validation").bind("keydown.validation",function(e){var code=e.keyCode?e.keyCode:e.which,suggestionId,$suggestionContainer,$input=$(this);if(code==13&&$.formUtils._selectedSuggestion!==null){suggestionId=$input.valAttr("suggestion-nr");$suggestionContainer=$(".jquery-form-suggestion-"+suggestionId);if($suggestionContainer.length>0){var newText=$suggestionContainer.find("div").eq($.formUtils._selectedSuggestion).text();$input.val(newText);onSelectSuggestion($input);e.preventDefault()}}else{suggestionId=$input.valAttr("suggestion-nr");$suggestionContainer=$(".jquery-form-suggestion-"+suggestionId);var $suggestions=$suggestionContainer.children();if($suggestions.length>0&&$.inArray(code,[38,40])>-1){if(code==38){if($.formUtils._selectedSuggestion===null)$.formUtils._selectedSuggestion=$suggestions.length-1;else $.formUtils._selectedSuggestion--;if($.formUtils._selectedSuggestion<0)$.formUtils._selectedSuggestion=$suggestions.length-1}else if(code==40){if($.formUtils._selectedSuggestion===null)$.formUtils._selectedSuggestion=0;else $.formUtils._selectedSuggestion++;if($.formUtils._selectedSuggestion>$suggestions.length-1)$.formUtils._selectedSuggestion=0}var containerInnerHeight=$suggestionContainer.innerHeight(),containerScrollTop=$suggestionContainer.scrollTop(),suggestionHeight=$suggestionContainer.children().eq(0).outerHeight(),activeSuggestionPosY=suggestionHeight*$.formUtils._selectedSuggestion;if(activeSuggestionPosY<containerScrollTop||activeSuggestionPosY>containerScrollTop+containerInnerHeight){$suggestionContainer.scrollTop(activeSuggestionPosY)}$suggestions.removeClass("active-suggestion").css("background","none").eq($.formUtils._selectedSuggestion).addClass("active-suggestion").css(conf.activeSuggestionCSS);e.preventDefault();return false}}}).unbind("blur.suggest").bind("blur.suggest",function(){onSelectSuggestion($(this))});return $elem},LANG:{errorTitle:"Form submission failed!",requiredFields:"You have not answered all required fields",badTime:"You have not given a correct time",badEmail:"You have not given a correct e-mail address",badTelephone:"You have not given a correct phone number",badSecurityAnswer:"You have not given a correct answer to the security question",badDate:"You have not given a correct date",lengthBadStart:"The input value must be between ",lengthBadEnd:" characters",lengthTooLongStart:"The input value is longer than ",lengthTooShortStart:"The input value is shorter than ",notConfirmed:"Input values could not be confirmed",badDomain:"Incorrect domain value",badUrl:"The input value is not a correct URL",badCustomVal:"The input value is incorrect",badInt:"The input value was not a correct number",badSecurityNumber:"Your social security number was incorrect",badUKVatAnswer:"Incorrect UK VAT Number",badStrength:"The password isn't strong enough",badNumberOfSelectedOptionsStart:"You have to choose at least ",badNumberOfSelectedOptionsEnd:" answers",badAlphaNumeric:"The input value can only contain alphanumeric characters ",badAlphaNumericExtra:" and ",wrongFileSize:"The file you are trying to upload is too large (max %s)",wrongFileType:"Only files of type %s is allowed",groupCheckedRangeStart:"Please choose between ",groupCheckedTooFewStart:"Please choose at least ",groupCheckedTooManyStart:"Please choose a maximum of ",groupCheckedEnd:" item(s)",badCreditCard:"The credit card number is not correct",badCVV:"The CVV number was not correct"}};$.formUtils.addValidator({name:"email",validatorFunction:function(email){var emailParts=email.toLowerCase().split("@");if(emailParts.length==2){return $.formUtils.validators.validate_domain.validatorFunction(emailParts[1])&&!/[^\w\+\.\-]/.test(emailParts[0])&&emailParts[0].length>0}return false},errorMessage:"",errorMessageKey:"badEmail"});$.formUtils.addValidator({name:"domain",validatorFunction:function(val){return val.length>0&&val.length<=253&&!/[^a-zA-Z0-9]/.test(val.substr(-2))&&!/[^a-zA-Z]/.test(val.substr(0,1))&&!/[^a-zA-Z0-9\.\-]/.test(val)&&val.split("..").length==1&&val.split(".").length>1},errorMessage:"",errorMessageKey:"badDomain"});$.formUtils.addValidator({name:"required",validatorFunction:function(val,$el,config,language,$form){switch($el.attr("type")){case"checkbox":return $el.is(":checked");case"radio":return $form.find('input[name="'+$el.attr("name")+'"]').filter(":checked").length>0;default:return $.trim(val)!==""}},errorMessage:"",errorMessageKey:"requiredFields"});$.formUtils.addValidator({name:"length",validatorFunction:function(val,$el,conf,lang){var lengthAllowed=$el.valAttr("length"),type=$el.attr("type");if(lengthAllowed==undefined){alert('Please add attribute "data-validation-length" to '+$el[0].nodeName+" named "+$el.attr("name"));return true}var len=type=="file"&&$el.get(0).files!==undefined?$el.get(0).files.length:val.length,lengthCheckResults=$.formUtils.numericRangeCheck(len,lengthAllowed),checkResult;switch(lengthCheckResults[0]){case"out":this.errorMessage=lang.lengthBadStart+lengthAllowed+lang.lengthBadEnd;checkResult=false;break;case"min":this.errorMessage=lang.lengthTooShortStart+lengthCheckResults[1]+lang.lengthBadEnd;checkResult=false;break;case"max":this.errorMessage=lang.lengthTooLongStart+lengthCheckResults[1]+lang.lengthBadEnd;checkResult=false;break;default:checkResult=true}return checkResult},errorMessage:"",errorMessageKey:""});$.formUtils.addValidator({name:"url",validatorFunction:function(url){var urlFilter=/^(https?|ftp):\/\/((((\w|-|\.|~|[\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])(\w|-|\.|~|[\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])(\w|-|\.|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/(((\w|-|\.|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/((\w|-|\.|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|\[|\]|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#(((\w|-|\.|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;if(urlFilter.test(url)){var domain=url.split("://")[1],domainSlashPos=domain.indexOf("/");if(domainSlashPos>-1)domain=domain.substr(0,domainSlashPos);return $.formUtils.validators.validate_domain.validatorFunction(domain)}return false},errorMessage:"",errorMessageKey:"badUrl"});$.formUtils.addValidator({name:"number",validatorFunction:function(val,$el,conf){if(val!==""){var allowing=$el.valAttr("allowing")||"",decimalSeparator=$el.valAttr("decimal-separator")||conf.decimalSeparator,allowsRange=false,begin,end,steps=$el.valAttr("step")||"",allowsSteps=false;if(allowing.indexOf("number")==-1)allowing+=",number";if(allowing.indexOf("negative")>-1&&val.indexOf("-")===0){val=val.substr(1)}if(allowing.indexOf("range")>-1){begin=parseFloat(allowing.substring(allowing.indexOf("[")+1,allowing.indexOf(";")));end=parseFloat(allowing.substring(allowing.indexOf(";")+1,allowing.indexOf("]")));allowsRange=true}if(steps!="")allowsSteps=true;if(decimalSeparator==","){if(val.indexOf(".")>-1){return false}val=val.replace(",",".")}if(allowing.indexOf("number")>-1&&val.replace(/[0-9]/g,"")===""&&(!allowsRange||val>=begin&&val<=end)&&(!allowsSteps||val%steps==0)){return true}if(allowing.indexOf("float")>-1&&val.match(new RegExp("^([0-9]+)\\.([0-9]+)$"))!==null&&(!allowsRange||val>=begin&&val<=end)&&(!allowsSteps||val%steps==0)){return true}}return false},errorMessage:"",errorMessageKey:"badInt"});$.formUtils.addValidator({name:"alphanumeric",validatorFunction:function(val,$el,conf,language){var patternStart="^([a-zA-Z0-9",patternEnd="]+)$",additionalChars=$el.valAttr("allowing"),pattern="";if(additionalChars){pattern=patternStart+additionalChars+patternEnd;var extra=additionalChars.replace(/\\/g,"");if(extra.indexOf(" ")>-1){extra=extra.replace(" ","");extra+=" and spaces "}this.errorMessage=language.badAlphaNumeric+language.badAlphaNumericExtra+extra}else{pattern=patternStart+patternEnd;this.errorMessage=language.badAlphaNumeric}return new RegExp(pattern).test(val)},errorMessage:"",errorMessageKey:""});$.formUtils.addValidator({name:"custom",validatorFunction:function(val,$el,conf){var regexp=new RegExp($el.valAttr("regexp"));return regexp.test(val)},errorMessage:"",errorMessageKey:"badCustomVal"});$.formUtils.addValidator({name:"date",validatorFunction:function(date,$el,conf){var dateFormat=$el.valAttr("format")||conf.dateFormat||"yyyy-mm-dd";return $.formUtils.parseDate(date,dateFormat)!==false},errorMessage:"",errorMessageKey:"badDate"});$.formUtils.addValidator({name:"checkbox_group",validatorFunction:function(val,$el,conf,lang,$form){var checkResult=true,elname=$el.attr("name"),checkedCount=$("input[type=checkbox][name^='"+elname+"']:checked",$form).length,qtyAllowed=$el.valAttr("qty");if(qtyAllowed==undefined){var elementType=$el.get(0).nodeName;alert('Attribute "data-validation-qty" is missing from '+elementType+" named "+$el.attr("name"))}var qtyCheckResults=$.formUtils.numericRangeCheck(checkedCount,qtyAllowed);switch(qtyCheckResults[0]){case"out":this.errorMessage=lang.groupCheckedRangeStart+qtyAllowed+lang.groupCheckedEnd;checkResult=false;break;case"min":this.errorMessage=lang.groupCheckedTooFewStart+qtyCheckResults[1]+lang.groupCheckedEnd;checkResult=false;break;case"max":this.errorMessage=lang.groupCheckedTooManyStart+qtyCheckResults[1]+lang.groupCheckedEnd;checkResult=false;break;default:checkResult=true}return checkResult}})})(jQuery);
|
@@ -0,0 +1,78 @@
|
|
1
|
+
/**
|
2
|
+
* jQuery Form Validator Module: Date
|
3
|
+
* ------------------------------------------
|
4
|
+
* Created by Victor Jonsson <http://www.victorjonsson.se>
|
5
|
+
*
|
6
|
+
* The following validators will be added by this module:
|
7
|
+
* - Country
|
8
|
+
* - US state
|
9
|
+
* - longitude and latitude
|
10
|
+
*
|
11
|
+
* @website http://formvalidator.net/#location-validators
|
12
|
+
* @license Dual licensed under the MIT or GPL Version 2 licenses
|
13
|
+
* @version 2.2.beta.50
|
14
|
+
*/
|
15
|
+
(function($) {
|
16
|
+
|
17
|
+
/*
|
18
|
+
* Validate that country exists
|
19
|
+
*/
|
20
|
+
$.formUtils.addValidator({
|
21
|
+
name : 'country',
|
22
|
+
validatorFunction : function(str) {
|
23
|
+
return $.inArray(str.toLowerCase(), this.countries) > -1;
|
24
|
+
},
|
25
|
+
countries : ['afghanistan','albania','algeria','american samoa','andorra','angola','anguilla','antarctica','antigua and barbuda','arctic ocean','argentina','armenia','aruba','ashmore and cartier islands','atlantic ocean','australia','austria','azerbaijan','bahamas','bahrain','baltic sea','baker island','bangladesh','barbados','bassas da india','belarus','belgium','belize','benin','bermuda','bhutan','bolivia','borneo','bosnia and herzegovina','botswana','bouvet island','brazil','british virgin islands','brunei','bulgaria','burkina faso','burundi','cambodia','cameroon','canada','cape verde','cayman islands','central african republic','chad','chile','china','christmas island','clipperton island','cocos islands','colombia','comoros','cook islands','coral sea islands','costa rica','croatia','cuba','cyprus','czech republic','democratic republic of the congo','denmark','djibouti','dominica','dominican republic','east timor','ecuador','egypt','el salvador','equatorial guinea','eritrea','estonia','ethiopia','europa island','falkland islands','faroe islands','fiji','finland','france','french guiana','french polynesia','french southern and antarctic lands','gabon','gambia','gaza strip','georgia','germany','ghana','gibraltar','glorioso islands','greece','greenland','grenada','guadeloupe','guam','guatemala','guernsey','guinea','guinea-bissau','guyana','haiti','heard island and mcdonald islands','honduras','hong kong','howland island','hungary','iceland','india','indian ocean','indonesia','iran','iraq','ireland','isle of man','israel','italy','jamaica','jan mayen','japan','jarvis island','jersey','johnston atoll','jordan','juan de nova island','kazakhstan','kenya','kerguelen archipelago','kingman reef','kiribati','kosovo','kuwait','kyrgyzstan','laos','latvia','lebanon','lesotho','liberia','libya','liechtenstein','lithuania','luxembourg','macau','macedonia','madagascar','malawi','malaysia','maldives','mali','malta','marshall islands','martinique','mauritania','mauritius','mayotte','mediterranean sea','mexico','micronesia','midway islands','moldova','monaco','mongolia','montenegro','montserrat','morocco','mozambique','myanmar','namibia','nauru','navassa island','nepal','netherlands','netherlands antilles','new caledonia','new zealand','nicaragua','niger','nigeria','niue','norfolk island','north korea','north sea','northern mariana islands','norway','oman','pacific ocean','pakistan','palau','palmyra atoll','panama','papua new guinea','paracel islands','paraguay','peru','philippines','pitcairn islands','poland','portugal','puerto rico','qatar','republic of the congo','reunion','romania','ross sea','russia','rwanda','saint helena','saint kitts and nevis','saint lucia','saint pierre and miquelon','saint vincent and the grenadines','samoa','san marino','sao tome and principe','saudi arabia','senegal','serbia','seychelles','sierra leone','singapore','slovakia','slovenia','solomon islands','somalia','south africa','south georgia and the south sandwich islands','south korea','southern ocean','spain','spratly islands','sri lanka','sudan','suriname','svalbard','swaziland','sweden','switzerland','syria','taiwan','tajikistan','tanzania','tasman sea','thailand','togo','tokelau','tonga','trinidad and tobago','tromelin island','tunisia','turkey','turkmenistan','turks and caicos islands','tuvalu','uganda','ukraine','united arab emirates','united kingdom','uruguay','usa','uzbekistan','vanuatu','venezuela','viet nam','virgin islands','wake island','wallis and futuna','west bank','western sahara','yemen','zambia','zimbabwe'],
|
26
|
+
errorMessage : '',
|
27
|
+
errorMessageKey: 'badCustomVal'
|
28
|
+
});
|
29
|
+
|
30
|
+
/*
|
31
|
+
* Is this a valid federate state in the US
|
32
|
+
*/
|
33
|
+
$.formUtils.addValidator({
|
34
|
+
name : 'federatestate',
|
35
|
+
validatorFunction : function(str) {
|
36
|
+
return $.inArray(str.toLowerCase(), this.states) > -1;
|
37
|
+
},
|
38
|
+
states : ['alabama','alaska', 'arizona', 'arkansas','california','colorado','connecticut','delaware','florida','georgia','hawaii','idaho','illinois','indiana','iowa','kansas','kentucky','louisiana','maine','maryland', 'district of columbia', 'massachusetts','michigan','minnesota','mississippi','missouri','montana','nebraska','nevada','new hampshire','new jersey','new mexico','new york','north carolina','north dakota','ohio','oklahoma','oregon','pennsylvania','rhode island','south carolina','south dakota','tennessee','texas','utah','vermont','virginia','washington','west virginia','wisconsin','wyoming'],
|
39
|
+
errorMessage : '',
|
40
|
+
errorMessageKey: 'badCustomVal'
|
41
|
+
});
|
42
|
+
|
43
|
+
|
44
|
+
$.formUtils.addValidator({
|
45
|
+
name : 'longlat',
|
46
|
+
validatorFunction : function(str) {
|
47
|
+
var regexp = /^[+-]?\d+\.\d+, ?[+-]?\d+\.\d+$/;
|
48
|
+
return regexp.test(str);
|
49
|
+
},
|
50
|
+
errorMessage:'',
|
51
|
+
errorMessageKey:'badCustomVal'
|
52
|
+
});
|
53
|
+
|
54
|
+
/**
|
55
|
+
* @private
|
56
|
+
* @param {Array} listItems
|
57
|
+
* @return {Array}
|
58
|
+
*/
|
59
|
+
var _makeSortedList = function(listItems) {
|
60
|
+
var newList = [];
|
61
|
+
$.each(listItems, function(i, v) {
|
62
|
+
newList.push(v.substr(0,1).toUpperCase() + v.substr(1, v.length));
|
63
|
+
});
|
64
|
+
newList.sort();
|
65
|
+
return newList;
|
66
|
+
};
|
67
|
+
|
68
|
+
$.fn.suggestCountry = function(settings) {
|
69
|
+
var country = _makeSortedList($.formUtils.validators.validate_country.countries);
|
70
|
+
return $.formUtils.suggest(this, country, settings);
|
71
|
+
};
|
72
|
+
|
73
|
+
$.fn.suggestState = function(settings) {
|
74
|
+
var states = _makeSortedList($.formUtils.validators.validate_federatestate.states);
|
75
|
+
return $.formUtils.suggest(this, states, settings);
|
76
|
+
};
|
77
|
+
|
78
|
+
})(jQuery);
|
@@ -0,0 +1,635 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<title>QUnit Tests</title>
|
6
|
+
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css">
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
|
10
|
+
<div id="qunit"></div>
|
11
|
+
<div id="qunit-fixture"></div>
|
12
|
+
<form id="dummy-form" style="visibility: hidden"></form>
|
13
|
+
|
14
|
+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
|
15
|
+
<script src="jquery.form-validator.js"></script>
|
16
|
+
<script src="//code.jquery.com/qunit/qunit-1.12.0.js"></script>
|
17
|
+
<script>
|
18
|
+
(function($) {
|
19
|
+
|
20
|
+
var $form = $('#dummy-form'), $in=null;
|
21
|
+
window.$form = $form;
|
22
|
+
window.$in = $in;
|
23
|
+
|
24
|
+
function input(val, dataValidationAttr, elAttr) {
|
25
|
+
if(!elAttr)
|
26
|
+
elAttr = {};
|
27
|
+
if( typeof dataValidationAttr == 'string') {
|
28
|
+
elAttr['data-validation'] = dataValidationAttr;
|
29
|
+
} else if(dataValidationAttr) {
|
30
|
+
$.each(dataValidationAttr, function(x, val) {
|
31
|
+
if( x == '' ) {
|
32
|
+
elAttr['data-validation'] = val;
|
33
|
+
} else {
|
34
|
+
elAttr['data-validation-'+x] = val;
|
35
|
+
}
|
36
|
+
});
|
37
|
+
}
|
38
|
+
|
39
|
+
elAttr['value'] = val;
|
40
|
+
$in = $('<input />', elAttr);
|
41
|
+
$in.appendTo($form);
|
42
|
+
return $in;
|
43
|
+
}
|
44
|
+
|
45
|
+
function clearForm() {
|
46
|
+
$form.children().remove();
|
47
|
+
}
|
48
|
+
|
49
|
+
function runTest(obj, validation) {
|
50
|
+
var $el = typeof obj.val == 'string' ? input(obj.val, validation) : obj.val;
|
51
|
+
var result = $.formUtils.validateInput($el, $.formUtils.LANG, $.formUtils.defaultConfig(), $form);
|
52
|
+
|
53
|
+
var message;
|
54
|
+
if( typeof obj.val == 'string' ) {
|
55
|
+
message = 'Check that "'+obj.val+'" is '+(obj.isValid ? 'valid':'invalid');
|
56
|
+
} else {
|
57
|
+
message = 'Check that input[value="'+obj.val.attr('value')+'"] is '+(obj.isValid ? 'valid':'invalid');
|
58
|
+
}
|
59
|
+
|
60
|
+
if( result === null && obj.isValid ) {
|
61
|
+
equal(
|
62
|
+
result,
|
63
|
+
null,
|
64
|
+
message
|
65
|
+
);
|
66
|
+
}
|
67
|
+
else if( $el.attr('data-validation-optional') && !$el.val() ) {
|
68
|
+
equal(
|
69
|
+
result,
|
70
|
+
null,
|
71
|
+
message
|
72
|
+
);
|
73
|
+
} else {
|
74
|
+
equal(
|
75
|
+
typeof(result),
|
76
|
+
obj.isValid ? 'boolean':'string', // returns true if valid, error message otherwise
|
77
|
+
message
|
78
|
+
);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
function runAllTests() {
|
83
|
+
|
84
|
+
/*
|
85
|
+
* Test error message
|
86
|
+
*/
|
87
|
+
test('Error messages', function() {
|
88
|
+
var $input = input('', {'':'required'}),
|
89
|
+
mess = $.formUtils.validateInput($input, $.formUtils.LANG, $.formUtils.defaultConfig(), $form);
|
90
|
+
|
91
|
+
equal('You have not answered all required fields', mess, 'Incorrect message');
|
92
|
+
|
93
|
+
$input = input('--', {'':'required alphanumeric', 'error-msg-alphanumeric':'custom for alphanum'}),
|
94
|
+
mess = $.formUtils.validateInput($input, $.formUtils.LANG, $.formUtils.defaultConfig(), $form);
|
95
|
+
equal('custom for alphanum', mess, 'Incorrect message');
|
96
|
+
|
97
|
+
$input = input('sam', {'':'required alphanumeric length', length:'min10', 'error-msg-alphanumeric':'custom for alphanum'}),
|
98
|
+
mess = $.formUtils.validateInput($input, $.formUtils.LANG, $.formUtils.defaultConfig(), $form);
|
99
|
+
equal('The input value is shorter than 10 characters', mess, 'Incorrect message');
|
100
|
+
|
101
|
+
});
|
102
|
+
|
103
|
+
/*
|
104
|
+
* E-MAIL VALIDATION
|
105
|
+
*/
|
106
|
+
test("E-mail validation", function() {
|
107
|
+
|
108
|
+
clearForm();
|
109
|
+
|
110
|
+
var values = [
|
111
|
+
{val: 'sasas@sdssds.se', isValid : true},
|
112
|
+
{val: 'sasás@sdssds.se', isValid : false},
|
113
|
+
{val: 'sas+as@sdssds.se', isValid : true},
|
114
|
+
{val: '', isValid : false},
|
115
|
+
{val: 'asdsd@sdsds.se', isValid : true},
|
116
|
+
{val: 'valid-domain@website.COM', isValid : true},
|
117
|
+
{val: 'asdsdsd@sdsd.co.uk', isValid : true},
|
118
|
+
{val: 'sasas@sdsd.xxx', isValid : true},
|
119
|
+
{val: 'sasas@sdsd.xxz', isValid : true},
|
120
|
+
{val: '@sdsd.xxz', isValid : false},
|
121
|
+
{val: 'sasas@', isValid : false},
|
122
|
+
{val: 'sasas.se', isValid : false},
|
123
|
+
{val: 'sasas-sdsd.com', isValid : false}
|
124
|
+
];
|
125
|
+
|
126
|
+
$.each(values, function(i, obj) {
|
127
|
+
runTest(obj, 'email');
|
128
|
+
});
|
129
|
+
});
|
130
|
+
|
131
|
+
/*
|
132
|
+
* URL VALIDATION
|
133
|
+
*/
|
134
|
+
test("URL validation", function() {
|
135
|
+
|
136
|
+
clearForm();
|
137
|
+
|
138
|
+
var links = [
|
139
|
+
{val: 'klsdmfklsmdf', isValid: false},
|
140
|
+
{val: 'http://google.se', isValid: true},
|
141
|
+
{val: 'https://google.se/test/?arge=hej_&arg[]=123', isValid: true},
|
142
|
+
{val: 'http://google.test.de', isValid: true},
|
143
|
+
{val: 'http://test.xn--fiqz9s', isValid: true},
|
144
|
+
{val: 'http://test.youtube', isValid: true},
|
145
|
+
{val: 'http://google.test.co.uk/', isValid: true}
|
146
|
+
];
|
147
|
+
|
148
|
+
$.each(links, function(i, obj) {
|
149
|
+
runTest(obj, 'url');
|
150
|
+
});
|
151
|
+
});
|
152
|
+
|
153
|
+
|
154
|
+
/*
|
155
|
+
* DOMAIN VALIDATION
|
156
|
+
*/
|
157
|
+
test("Domain validation", function() {
|
158
|
+
|
159
|
+
clearForm();
|
160
|
+
|
161
|
+
var links = [
|
162
|
+
{val:'domain.xxx', isValid:true},
|
163
|
+
{val:'domain.com', isValid:true},
|
164
|
+
{val:'www.domain.com', isValid:true},
|
165
|
+
{val:'test.xn--fiqz9s', isValid:true},
|
166
|
+
{val:'test..xn--fiqz9s', isValid:false},
|
167
|
+
{val:'q.com', isValid:true},
|
168
|
+
{val:'amazone.website.tippit.de', isValid:true},
|
169
|
+
{val:'amazone.website.co.uk', isValid:true},
|
170
|
+
{val:'http://domain.se', isValid:false},
|
171
|
+
{val:'http://www.domain.se', isValid:false},
|
172
|
+
{val:'http://www.domain.se/', isValid:false},
|
173
|
+
{val:'domain.com/', isValid:false},
|
174
|
+
{val:'', isValid:false},
|
175
|
+
{val:'asdfasdf', isValid:false}
|
176
|
+
];
|
177
|
+
|
178
|
+
$.each(links, function(i, obj) {
|
179
|
+
runTest(obj, 'domain');
|
180
|
+
});
|
181
|
+
});
|
182
|
+
|
183
|
+
/*
|
184
|
+
* REQUIRED VALIDATION
|
185
|
+
*/
|
186
|
+
test("Require validation", function() {
|
187
|
+
|
188
|
+
clearForm();
|
189
|
+
|
190
|
+
var links = [
|
191
|
+
{val:'a', isValid:true},
|
192
|
+
{val:'asdf askldfmlksamdf', isValid:true},
|
193
|
+
{val:' ', isValid:false},
|
194
|
+
{val:"\n", isValid:false},
|
195
|
+
{val:'', isValid:false}
|
196
|
+
];
|
197
|
+
|
198
|
+
$.each(links, function(i, obj) {
|
199
|
+
runTest(obj, 'required');
|
200
|
+
});
|
201
|
+
});
|
202
|
+
|
203
|
+
/*
|
204
|
+
* ALPHANUMERIC VALIDATION
|
205
|
+
*/
|
206
|
+
test("Alphanumeric validation", function() {
|
207
|
+
|
208
|
+
clearForm();
|
209
|
+
|
210
|
+
var links = [
|
211
|
+
{val:'a', isValid:true},
|
212
|
+
{val:'asdXAvs1', isValid:true},
|
213
|
+
{val:'a b', isValid:false},
|
214
|
+
{val:'a-_ bäöåA', isValid:false},
|
215
|
+
{val:'abbb', isValid:true},
|
216
|
+
{val:'a,bbb', isValid:false},
|
217
|
+
{val:input('a,bbb', {'allowing':',', '':'alphanumeric'}), isValid:true},
|
218
|
+
{val:input('a b', {'allowing':' ', '':'alphanumeric'}), isValid:true},
|
219
|
+
{val:input('', {'allowing':' ', length:'3-12', '':'length alphanumeric'}), isValid:false},
|
220
|
+
{val:input('a-_ bäöåÖA', {'allowing':' -_öäåÄÖÅ', '':'alphanumeric'}), isValid:true}
|
221
|
+
];
|
222
|
+
|
223
|
+
$.each(links, function(i, obj) {
|
224
|
+
runTest(obj, 'alphanumeric');
|
225
|
+
});
|
226
|
+
});
|
227
|
+
|
228
|
+
/*
|
229
|
+
* CREDIT CARD VALIDATION
|
230
|
+
*/
|
231
|
+
test("Credit card validation", function() {
|
232
|
+
|
233
|
+
clearForm();
|
234
|
+
|
235
|
+
var links = [
|
236
|
+
{val:'4000000000000002', isValid:true},
|
237
|
+
{val:input('4000000000000002', {'allowing':'visa', '':'creditcard'}), isValid:true},
|
238
|
+
{val:input('4000000000000002', {'allowing':'mastercard, discover, visa', '':'creditcard'}), isValid:true},
|
239
|
+
{val:input('501800000009', {'allowing':'maestro', '':'creditcard'}), isValid:true},
|
240
|
+
{val:input('501800000009', {'allowing':'visa', '':'creditcard'}), isValid:false},
|
241
|
+
{val:input('501800000009', {'allowing':'jadajada,maestro,mastercard', '':'creditcard'}), isValid:true},
|
242
|
+
{val:input('5100000000000008', {'allowing':'mastercard', '':'creditcard'}), isValid:true},
|
243
|
+
{val:input('6011000000000004', {'allowing':'discover', '':'creditcard'}), isValid:true},
|
244
|
+
{val:input('6011000000000005', {'allowing':'discover', '':'creditcard'}), isValid:false}
|
245
|
+
];
|
246
|
+
|
247
|
+
$.each(links, function(i, obj) {
|
248
|
+
runTest(obj, 'creditcard');
|
249
|
+
});
|
250
|
+
});
|
251
|
+
|
252
|
+
test('isValid()', function() {
|
253
|
+
|
254
|
+
$form.empty();
|
255
|
+
$form.append(input('4000000000000002', {'allowing':'visa', '':'creditcard'}));
|
256
|
+
$form.append(input('', {'optional':'true', '':'alphanumeric'}));
|
257
|
+
$form.append(input('', 'alphanumeric'));
|
258
|
+
$form.append(input('4000000000000002', 'alphanumeric'));
|
259
|
+
|
260
|
+
equal(
|
261
|
+
$form.isValid(false, false, false),
|
262
|
+
false
|
263
|
+
);
|
264
|
+
|
265
|
+
$form.empty();
|
266
|
+
$form.append(input('4000000000000002', {'allowing':'visa', '':'creditcard'}));
|
267
|
+
$form.append(input('', {'optional':'true', '':'alphanumeric'}));
|
268
|
+
$form.append(input('fff', 'alphanumeric'));
|
269
|
+
$form.append(input('4000000000000002', 'alphanumeric'));
|
270
|
+
|
271
|
+
equal(
|
272
|
+
$form.isValid(false, false, false),
|
273
|
+
true
|
274
|
+
);
|
275
|
+
|
276
|
+
});
|
277
|
+
|
278
|
+
/*
|
279
|
+
* CVV VALIDATION
|
280
|
+
*/
|
281
|
+
test("CVV validation", function() {
|
282
|
+
|
283
|
+
clearForm();
|
284
|
+
|
285
|
+
var links = [
|
286
|
+
{val:'012', isValid:true},
|
287
|
+
{val:'0124', isValid:false},
|
288
|
+
{val:'000', isValid:true},
|
289
|
+
{val:'01', isValid:false},
|
290
|
+
{val:'a12', isValid:false}
|
291
|
+
];
|
292
|
+
|
293
|
+
$.each(links, function(i, obj) {
|
294
|
+
runTest(obj, 'cvv');
|
295
|
+
});
|
296
|
+
|
297
|
+
// check with amex only
|
298
|
+
var $cCard = input('', {'allowing':'amex', '':'creditcard'}),
|
299
|
+
$cvv = input('1234', 'cvv'),
|
300
|
+
result;
|
301
|
+
|
302
|
+
// let the validator know which type of card we're validating
|
303
|
+
$.formUtils.validateInput($cCard, $.formUtils.LANG, $.formUtils.defaultConfig(), $form)
|
304
|
+
|
305
|
+
result = $.formUtils.validateInput($cvv, $.formUtils.LANG, $.formUtils.defaultConfig(), $form);
|
306
|
+
equal(
|
307
|
+
true,
|
308
|
+
result
|
309
|
+
);
|
310
|
+
|
311
|
+
$cvv.val('123');
|
312
|
+
result = $.formUtils.validateInput($cvv, $.formUtils.LANG, $.formUtils.defaultConfig(), $form);
|
313
|
+
equal(
|
314
|
+
'string',
|
315
|
+
typeof result
|
316
|
+
);
|
317
|
+
|
318
|
+
});
|
319
|
+
|
320
|
+
|
321
|
+
/*
|
322
|
+
* DISABLED VALIDATION
|
323
|
+
*/
|
324
|
+
test("Do not validate disabled", function() {
|
325
|
+
clearForm();
|
326
|
+
var $input = input('a--b', {'allowing':'', '':'alphanumeric'});
|
327
|
+
$input.attr('disabled', 'disabled');
|
328
|
+
runTest({val:$input, isValid: true});
|
329
|
+
});
|
330
|
+
|
331
|
+
/*
|
332
|
+
* NUMBER VALIDATION
|
333
|
+
*/
|
334
|
+
test("Number validation", function() {
|
335
|
+
|
336
|
+
clearForm();
|
337
|
+
|
338
|
+
var links = [
|
339
|
+
{val:'123', isValid:true},
|
340
|
+
{val:'', isValid:false},
|
341
|
+
{val:'asdfsd', isValid:false},
|
342
|
+
{val:'-123', isValid:false},
|
343
|
+
{val:input('-123', {'allowing':'negative', '':'number'}), isValid:true},
|
344
|
+
{val:'1.032', isValid:false},
|
345
|
+
{val:input('1.023', {'allowing':'float', '':'number'}), isValid:true},
|
346
|
+
{val:'-1.032', isValid:false},
|
347
|
+
{val:input('-1.023', {'allowing':'float,negative', '':'number'}), isValid:true},
|
348
|
+
{val:input('1.0234', {'allowing':'float,negative', '':'number'}), isValid:true},
|
349
|
+
{val:input('1.0235', {'allowing':'float,negative,number', '':'number'}), isValid:true},
|
350
|
+
{val:input('1.0236', {'allowing':'float,negative,number', 'decimal-separator':',', '':'number'}), isValid:false},
|
351
|
+
{val:input('1,023', {'allowing':'float,negative,number', 'decimal-separator':',', '':'number'}), isValid:true},
|
352
|
+
{val:'123', isValid:true},
|
353
|
+
{val:input('12', {'allowing':'range[1;10]', '':'number'}), isValid:false},
|
354
|
+
{val:input('-1', {'allowing':'range[1;10]', '':'number'}), isValid:false},
|
355
|
+
{val:input('1', {'allowing':'range[1;10]', '':'number'}), isValid:true},
|
356
|
+
{val:input('10', {'allowing':'range[1;10]', '':'number'}), isValid:true},
|
357
|
+
{val:input('5', {'allowing':'range[1;10]', '':'number'}), isValid:true},
|
358
|
+
{val:input('-1', {'allowing':'range[-10;10],negative', '':'number'}), isValid:true},
|
359
|
+
{val:input('0.0001', {'allowing':'range[0.05;0.9]', '':'number'}), isValid:false},
|
360
|
+
{val:input('0.06', {'allowing':'range[0.05;0.9],float', '':'number'}), isValid:true}
|
361
|
+
];
|
362
|
+
|
363
|
+
$.each(links, function(i, obj) {
|
364
|
+
runTest(obj, 'number');
|
365
|
+
});
|
366
|
+
});
|
367
|
+
|
368
|
+
/*
|
369
|
+
* DATE VALIDATION
|
370
|
+
*/
|
371
|
+
test("Date validation", function() {
|
372
|
+
|
373
|
+
clearForm();
|
374
|
+
|
375
|
+
var dates = [
|
376
|
+
{val:'2000-01-01', isValid:true},
|
377
|
+
{val:'2000-01-1', isValid:false},
|
378
|
+
{val:'2000-01-32', isValid:false},
|
379
|
+
{val:'2000-02-29', isValid:true}, // leap year
|
380
|
+
{val:'2013-02-29', isValid:false},
|
381
|
+
{val:'2000-04-31', isValid:false},
|
382
|
+
{val:'2000-13-1', isValid:false},
|
383
|
+
{val:'2000-1-1', isValid:false},
|
384
|
+
{val:'-01-01', isValid:false},
|
385
|
+
{val:input('01/01/2000', {'format':'dd/mm/yyyy', '':'date'}), isValid:true},
|
386
|
+
{val:input('29/02/2000', {'format':'dd/mm/yyyy', '':'date'}), isValid:true},
|
387
|
+
{val:input('02/2000', {'format':'mm/yyyy', '':'date'}), isValid:true},
|
388
|
+
{val:input('29/02/2013', {'format':'dd/mm/yyyy', '':'date'}), isValid:false},
|
389
|
+
{val:input('29/13/2013', {'format':'dd/mm/yyyy', '':'date'}), isValid:false},
|
390
|
+
{val:input('29/00/2013', {'format':'dd/mm/yyyy', '':'date'}), isValid:false},
|
391
|
+
{val:'', isValid:false},
|
392
|
+
{val:input('', {'optional':'true', 'format':'dd/mm/yyyy', '':'date'}), isValid:true},
|
393
|
+
{val:'2014-01-01', isValid:true},
|
394
|
+
{val:'1880-01-01', isValid:true}
|
395
|
+
];
|
396
|
+
|
397
|
+
$.each(dates, function(i, obj) {
|
398
|
+
runTest(obj, 'date');
|
399
|
+
});
|
400
|
+
});
|
401
|
+
|
402
|
+
/*
|
403
|
+
* BIRTH DATE VALIDATION
|
404
|
+
*/
|
405
|
+
test("Birth date validation", function() {
|
406
|
+
|
407
|
+
clearForm();
|
408
|
+
|
409
|
+
var dates = [
|
410
|
+
{val:'2000-01-01', isValid:true},
|
411
|
+
{val:'2000-01-1', isValid:false},
|
412
|
+
{val:'2000-01-32', isValid:false},
|
413
|
+
{val:'2000-02-29', isValid:true}, // leap year
|
414
|
+
{val:'2013-02-29', isValid:false},
|
415
|
+
{val:'2000-04-31', isValid:false},
|
416
|
+
{val:'2000-13-1', isValid:false},
|
417
|
+
{val:'2000-1-1', isValid:false},
|
418
|
+
{val:'-01-01', isValid:false},
|
419
|
+
{val:input('01/01/2000', {'format':'dd/mm/yyyy', '':'date'}), isValid:true},
|
420
|
+
{val:input('29/02/2000', {'format':'dd/mm/yyyy', '':'date'}), isValid:true},
|
421
|
+
{val:input('29/02/2013', {'format':'dd/mm/yyyy', '':'date'}), isValid:false},
|
422
|
+
{val:input('29/13/2013', {'format':'dd/mm/yyyy', '':'date'}), isValid:false},
|
423
|
+
{val:input('29/00/2013', {'format':'dd/mm/yyyy', '':'date'}), isValid:false},
|
424
|
+
{val:'2030-01-01', isValid:false}, // no future date
|
425
|
+
{val:'1880-01-01', isValid:false} // no date that is to old
|
426
|
+
];
|
427
|
+
|
428
|
+
$.each(dates, function(i, obj) {
|
429
|
+
runTest(obj, 'birthdate');
|
430
|
+
});
|
431
|
+
});
|
432
|
+
|
433
|
+
/*
|
434
|
+
* TIME VALIDATION
|
435
|
+
*/
|
436
|
+
test("Time validation", function() {
|
437
|
+
|
438
|
+
clearForm();
|
439
|
+
|
440
|
+
var links = [
|
441
|
+
{val:'00:00', isValid:true},
|
442
|
+
{val:'00:01', isValid:true},
|
443
|
+
{val:'09:59', isValid:true},
|
444
|
+
{val:'19:59', isValid:true},
|
445
|
+
{val:'19:60', isValid:false},
|
446
|
+
{val:'19:61', isValid:false},
|
447
|
+
{val:'24:01', isValid:false},
|
448
|
+
{val:'24:00', isValid:false},
|
449
|
+
{val:'2200', isValid:false},
|
450
|
+
{val:'', isValid:false},
|
451
|
+
{val:'23', isValid:false},
|
452
|
+
{val:'23;00', isValid:false},
|
453
|
+
{val:'23-00', isValid:false}
|
454
|
+
];
|
455
|
+
|
456
|
+
$.each(links, function(i, obj) {
|
457
|
+
runTest(obj, 'time');
|
458
|
+
});
|
459
|
+
});
|
460
|
+
|
461
|
+
|
462
|
+
/*
|
463
|
+
* SWEDISH MOBILE VALIDATION
|
464
|
+
*/
|
465
|
+
test("Swe mobile validation", function() {
|
466
|
+
|
467
|
+
clearForm();
|
468
|
+
|
469
|
+
var links = [
|
470
|
+
{val:'0702777118', isValid:true},
|
471
|
+
{val:'0722777118', isValid:true},
|
472
|
+
{val:'46702777118', isValid:true},
|
473
|
+
{val:'45702777118', isValid:false},
|
474
|
+
{val:'+46702777118', isValid:true},
|
475
|
+
{val:'+45702777118', isValid:false},
|
476
|
+
{val:'0732777118', isValid:true},
|
477
|
+
{val:'0302777118', isValid:false},
|
478
|
+
{val:'07027771', isValid:false}
|
479
|
+
];
|
480
|
+
|
481
|
+
$.each(links, function(i, obj) {
|
482
|
+
runTest(obj, 'swemobile');
|
483
|
+
});
|
484
|
+
});
|
485
|
+
|
486
|
+
/*
|
487
|
+
* LENGTH VALIDATION
|
488
|
+
*/
|
489
|
+
test("Length validation", function() {
|
490
|
+
|
491
|
+
clearForm();
|
492
|
+
|
493
|
+
var links = [
|
494
|
+
{val:input('1234', {'length':'max3', '':'length'}), isValid:false},
|
495
|
+
{val:input('1234', {'length':'min3', '':'length'}), isValid:true},
|
496
|
+
{val:input('1234', {'length':'min5', '':'length'}), isValid:false},
|
497
|
+
{val:input('1234', {'length':'2-35', '':'length'}), isValid:true},
|
498
|
+
{val:input('123456', {'length':'2-5', '':'length'}), isValid:false},
|
499
|
+
{val:input('1234', {'length':'max4', '':'length'}), isValid:true},
|
500
|
+
{val:input('1234', {length : 'min5', '':'number length'}), isValid:false},
|
501
|
+
{val:input('12345', {length : 'min5', '':'number length'}), isValid:true},
|
502
|
+
{val:input('1234a', {length : 'min5', '':'number length'}), isValid:false},
|
503
|
+
{val:input('12345678', {length : 'min5', '':'number length'}), isValid:true}
|
504
|
+
];
|
505
|
+
|
506
|
+
$.each(links, function(i, obj) {
|
507
|
+
runTest(obj, 'length');
|
508
|
+
});
|
509
|
+
});
|
510
|
+
|
511
|
+
/*
|
512
|
+
* SWEDISH SSN VALIDATION
|
513
|
+
*/
|
514
|
+
test("Swedish SSN validation", function() {
|
515
|
+
|
516
|
+
clearForm();
|
517
|
+
|
518
|
+
var links = [
|
519
|
+
{val:'19:59', isValid:false},
|
520
|
+
{val:'', isValid:false},
|
521
|
+
{val:'198311084936', isValid:true},
|
522
|
+
{val:'198311084935', isValid:false},
|
523
|
+
{val:'198301128529', isValid:true},
|
524
|
+
{val:'198301128528', isValid:false},
|
525
|
+
{val:input('', {'use-hyphen' : 'true', '':'swesec'}), isValid:false},
|
526
|
+
{val:input('198301128529', {'use-hyphen' : 'true', '':'swesec'}), isValid:false},
|
527
|
+
{val:input('198311084936', {'use-hyphen' : 'true', '':'swesec'}), isValid:false},
|
528
|
+
{val:input('19830112-8529', {'use-hyphen' : 'true', '':'swesec'}), isValid:true},
|
529
|
+
{val:input('19831108-4936', {'use-hyphen' : 'true', '':'swesec'}), isValid:true}
|
530
|
+
];
|
531
|
+
|
532
|
+
$.each(links, function(i, obj) {
|
533
|
+
runTest(obj, 'swesec');
|
534
|
+
});
|
535
|
+
});
|
536
|
+
|
537
|
+
/*
|
538
|
+
* FILE VALIDATION
|
539
|
+
*/
|
540
|
+
test('File validation', function() {
|
541
|
+
|
542
|
+
clearForm();
|
543
|
+
|
544
|
+
equal(100, $.formUtils.convertSizeNameToBytes('100'));
|
545
|
+
equal(100, $.formUtils.convertSizeNameToBytes('100b'));
|
546
|
+
equal(100, $.formUtils.convertSizeNameToBytes('100B'));
|
547
|
+
equal(112640, $.formUtils.convertSizeNameToBytes('110kb'));
|
548
|
+
equal(112640, $.formUtils.convertSizeNameToBytes('110KB'));
|
549
|
+
equal(10485760, $.formUtils.convertSizeNameToBytes('10M'));
|
550
|
+
equal(10485760, $.formUtils.convertSizeNameToBytes('10MB'));
|
551
|
+
equal(10485760, $.formUtils.convertSizeNameToBytes('10mb'));
|
552
|
+
equal(10485760, $.formUtils.convertSizeNameToBytes('10m'));
|
553
|
+
|
554
|
+
/*
|
555
|
+
todo: test this somehow
|
556
|
+
var extensionTests = [
|
557
|
+
{val:input('file.jpg', {'allowing' : 'jpg', '':'extension'}), isValid:true},
|
558
|
+
{val:input('file.JPG', {'allowing' : 'jpg', '':'extension'}), isValid:true},
|
559
|
+
{val:input('file.jpgs', {'allowing' : 'jpg', '':'extension'}, {type:'file'}), isValid:false},
|
560
|
+
{val:input('file', {'allowing' : 'jpg', '':'extension'}), isValid:false},
|
561
|
+
{val:input('file.jpeg', {'allowing' : 'jpg', '':'extension'}), isValid:true},
|
562
|
+
{val:input('file.JPEG', {'allowing' : 'jpg, png, gif', '':'extension'}), isValid:true},
|
563
|
+
{val:input('file.JPEG', {'allowing' : 'jpg,', '':'extension'}), isValid:true},
|
564
|
+
{val:input('file.JPEG', {'allowing' : ' jpg ', '':'extension'}), isValid:true}
|
565
|
+
];
|
566
|
+
|
567
|
+
$.each(extensionTests, function(i, obj) {
|
568
|
+
runTest(obj, 'extension');
|
569
|
+
});
|
570
|
+
*/
|
571
|
+
});
|
572
|
+
|
573
|
+
test('Confirmation', function() {
|
574
|
+
|
575
|
+
clearForm();
|
576
|
+
|
577
|
+
var $inputA = input('hejsan', {'':'confirmation'}, {name:'test'}),
|
578
|
+
$inputB = input('hej', undefined, {name:'test_confirmation'}),
|
579
|
+
result = $.formUtils.validateInput($inputA, $.formUtils.LANG, $.formUtils.defaultConfig(), $form);
|
580
|
+
|
581
|
+
equal(
|
582
|
+
typeof(result) == 'string', // Should be an error message
|
583
|
+
true,
|
584
|
+
'Could not check that inputs did not confirmation each other'
|
585
|
+
);
|
586
|
+
|
587
|
+
$inputB.val('hejsan');
|
588
|
+
result = $.formUtils.validateInput($inputA, $.formUtils.LANG, $.formUtils.defaultConfig(), $form);
|
589
|
+
equal(
|
590
|
+
result,
|
591
|
+
true,
|
592
|
+
'Could not validate confirmation'
|
593
|
+
);
|
594
|
+
|
595
|
+
clearForm();
|
596
|
+
|
597
|
+
var $inputC = input('value', {'':'confirmation', 'confirm':'input-D'}, {name:'test'}),
|
598
|
+
$inputD = input('hej', undefined, {name:'input-D'});
|
599
|
+
|
600
|
+
result = $.formUtils.validateInput($inputC, $.formUtils.LANG, $.formUtils.defaultConfig(), $form);
|
601
|
+
|
602
|
+
equal(
|
603
|
+
typeof(result) == 'string', // Should be an error message
|
604
|
+
true,
|
605
|
+
'Could not check that inputs did not confirmation each other'
|
606
|
+
);
|
607
|
+
|
608
|
+
$inputD.val('value');
|
609
|
+
result = $.formUtils.validateInput($inputC, $.formUtils.LANG, $.formUtils.defaultConfig(), $form);
|
610
|
+
equal(
|
611
|
+
result,
|
612
|
+
true,
|
613
|
+
'Could not validate confirmation'
|
614
|
+
);
|
615
|
+
});
|
616
|
+
|
617
|
+
// TODO: Write more tests...
|
618
|
+
|
619
|
+
}
|
620
|
+
|
621
|
+
var dev = window.location.hash.indexOf('dev') > -1 ? '.dev' : '';
|
622
|
+
|
623
|
+
$.validate({
|
624
|
+
modules : 'security'+dev+', location'+dev+', sweden'+dev+', file'+dev+', date'+dev+', uk'+dev,
|
625
|
+
onModulesLoaded: function( $form ) {
|
626
|
+
console.log('About to run all tests');
|
627
|
+
runAllTests();
|
628
|
+
}
|
629
|
+
});
|
630
|
+
|
631
|
+
})(jQuery);
|
632
|
+
</script>
|
633
|
+
|
634
|
+
</body>
|
635
|
+
</html>
|