/* * inline form validation engine 2.6.2, jquery plugin * * copyright(c) 2010, cedric dugas * http://www.position-absolute.com * * 2.0 rewrite by olivier refalo * http://www.crionics.com * * form validation engine allowing custom regex rules to be added. * licensed under the mit license */ !function(a){"use strict";array.indexof||(array.prototype.indexof=function(a){for(var b=0;b0&&e.onfieldfailure());return e.onvalidationcomplete?!!e.onvalidationcomplete(f,d):d},updatepromptsposition:function(c){var d,e,f;return c&&this==window?(d=c.data.formelem,e=c.data.noanimation):d=a(this.closest("form, .validationenginecontainer")),f=d.data("jqv"),d.find("["+f.validateattribute+"*=validate]").not(":disabled").each(function(){var g,h,c=a(this);f.prettyselect&&c.is(":hidden")&&(c=d.find("#"+f.useprefix+c.attr("id")+f.usesuffix)),g=b._getprompt(c),h=a(g).find(".formerrorcontent").html(),g&&b._updateprompt(c,a(g),h,void 0,!1,f,e)}),this},showprompt:function(a,c,d,e){var f=this.closest("form, .validationenginecontainer"),g=f.data("jqv");return g||(g=b._saveoptions(this,g)),d&&(g.promptposition=d),g.showarrow=1==e,b._showprompt(this,a,c,!1,g),this},hide:function(){var f,c=a(this).closest("form, .validationenginecontainer"),d=c.data("jqv"),e=d&&d.fadeduration?d.fadeduration:.3;return f=a(this).is("form")||a(this).hasclass("validationenginecontainer")?"parentform"+b._getclassname(a(this).attr("id")):b._getclassname(a(this).attr("id"))+"formerror",a("."+f).fadeto(e,.3,function(){a(this).parent(".formerrorouter").remove(),a(this).remove()}),this},hideall:function(){var b=this,c=b.data("jqv"),d=c?c.fadeduration:300;return a(".formerror").fadeto(d,300,function(){a(this).parent(".formerrorouter").remove(),a(this).remove()}),this},_onfieldevent:function(c){var d=a(this),e=d.closest("form, .validationenginecontainer"),f=e.data("jqv");f.eventtrigger="field",window.settimeout(function(){b._validatefield(d,f),0==f.invalidfields.length&&f.onfieldsuccess?f.onfieldsuccess():f.invalidfields.length>0&&f.onfieldfailure&&f.onfieldfailure()},c.data?c.data.delay:0)},_onsubmitevent:function(){var e,f,c=a(this),d=c.data("jqv");return c.data("jqv_submitbutton")&&(e=a("#"+c.data("jqv_submitbutton")),e&&e.length>0&&(e.hasclass("validate-skip")||"true"==e.attr("data-validation-engine-skip")))?!0:(d.eventtrigger="submit",f=b._validatefields(c),f&&d.ajaxformvalidation?(b._validateformwithajax(c,d),!1):d.onvalidationcomplete?!!d.onvalidationcomplete(c,f):f)},_checkajaxstatus:function(b){var c=!0;return a.each(b.ajaxvalidcache,function(a,b){return b?void 0:(c=!1,!1)}),c},_checkajaxfieldstatus:function(a,b){return 1==b.ajaxvalidcache[a]},_validatefields:function(c){var f,g,h,i,j,k,l,m,n,d=c.data("jqv"),e=!1;if(c.trigger("jqv.form.validating"),f=null,c.find("["+d.validateattribute+"*=validate]").not(":disabled").each(function(){var g=a(this),h=[];if(a.inarray(g.attr("name"),h)<0){if(e|=b._validatefield(g,d),e&&null==f&&(g.is(":hidden")&&d.prettyselect?f=g=c.find("#"+d.useprefix+b._jqselector(g.attr("id"))+d.usesuffix):(g.data("jqv-prompt-at")instanceof jquery?g=g.data("jqv-prompt-at"):g.data("jqv-prompt-at")&&(g=a(g.data("jqv-prompt-at"))),f=g)),d.donotshowallerrosonsubmit)return!1;if(h.push(g.attr("name")),1==d.showonemessage&&e)return!1}}),c.trigger("jqv.form.result",[e]),e){if(d.scroll)if(g=f.offset().top,h=f.offset().left,i=d.promptposition,"string"==typeof i&&-1!=i.indexof(":")&&(i=i.substring(0,i.indexof(":"))),"bottomright"!=i&&"bottomleft"!=i&&(j=b._getprompt(f),j&&(g=j.offset().top)),d.scrolloffset&&(g-=d.scrolloffset),d.isoverflown){if(k=a(d.overflowndiv),!k.length)return!1;l=k.scrolltop(),m=-parseint(k.offset().top),g+=l+m-5,n=a(d.overflowndiv+":not(:animated)"),n.animate({scrolltop:g},1100,function(){d.focusfirstfield&&f.focus()})}else a("html, body").animate({scrolltop:g},1100,function(){d.focusfirstfield&&f.focus()}),a("html, body").animate({scrollleft:h},1100);else d.focusfirstfield&&f.focus();return!1}return!0},_validateformwithajax:function(c,d){var e=c.serialize(),f=d.ajaxformvalidationmethod?d.ajaxformvalidationmethod:"get",g=d.ajaxformvalidationurl?d.ajaxformvalidationurl:c.attr("action"),h=d.datatype?d.datatype:"json";a.ajax({type:f,url:g,cache:!1,datatype:h,data:e,form:c,methods:b,options:d,beforesend:function(){return d.onbeforeajaxformvalidation(c,d)},error:function(a,c){d.onfailure?d.onfailure(a,c):b._ajaxerror(a,c)},success:function(e){var f,g,i,j,k,l,m;if("json"==h&&e!==!0){for(f=!1,g=0;g0&&(o=!0),p=a(c.closest("form, .validationenginecontainer")),q=0;q=d.maxerrorsperfield){n||(s=a.inarray("required",i),n=-1!=s&&s>=q);break}switch(t=void 0,i[q]){case"required":n=!0,t=b._geterrormessage(p,c,i[q],i,q,d,b._required);break;case"custom":t=b._geterrormessage(p,c,i[q],i,q,d,b._custom);break;case"grouprequired":u="["+d.validateattribute+"*="+i[q+1]+"]",v=p.find(u).eq(0),v[0]!=c[0]&&(b._validatefield(v,d,e),d.showarrow=!0),t=b._geterrormessage(p,c,i[q],i,q,d,b._grouprequired),t&&(n=!0),d.showarrow=!1;break;case"ajax":t=b._ajax(c,i,q,d),t&&(m="load");break;case"minsize":t=b._geterrormessage(p,c,i[q],i,q,d,b._minsize);break;case"maxsize":t=b._geterrormessage(p,c,i[q],i,q,d,b._maxsize);break;case"min":t=b._geterrormessage(p,c,i[q],i,q,d,b._min);break;case"max":t=b._geterrormessage(p,c,i[q],i,q,d,b._max);break;case"past":t=b._geterrormessage(p,c,i[q],i,q,d,b._past);break;case"future":t=b._geterrormessage(p,c,i[q],i,q,d,b._future);break;case"daterange":u="["+d.validateattribute+"*="+i[q+1]+"]",d.firstofgroup=p.find(u).eq(0),d.secondofgroup=p.find(u).eq(1),(d.firstofgroup[0].value||d.secondofgroup[0].value)&&(t=b._geterrormessage(p,c,i[q],i,q,d,b._daterange)),t&&(n=!0),d.showarrow=!1;break;case"datetimerange":u="["+d.validateattribute+"*="+i[q+1]+"]",d.firstofgroup=p.find(u).eq(0),d.secondofgroup=p.find(u).eq(1),(d.firstofgroup[0].value||d.secondofgroup[0].value)&&(t=b._geterrormessage(p,c,i[q],i,q,d,b._datetimerange)),t&&(n=!0),d.showarrow=!1;break;case"maxcheckbox":c=a(p.find("input[name='"+k+"']")),t=b._geterrormessage(p,c,i[q],i,q,d,b._maxcheckbox);break;case"mincheckbox":c=a(p.find("input[name='"+k+"']")),t=b._geterrormessage(p,c,i[q],i,q,d,b._mincheckbox);break;case"equals":t=b._geterrormessage(p,c,i[q],i,q,d,b._equals);break;case"funccall":t=b._geterrormessage(p,c,i[q],i,q,d,b._funccall);break;case"creditcard":t=b._geterrormessage(p,c,i[q],i,q,d,b._creditcard);break;case"condrequired":t=b._geterrormessage(p,c,i[q],i,q,d,b._condrequired),void 0!==t&&(n=!0)}if(w=!1,"object"==typeof t)switch(t.status){case"_break":w=!0;break;case"_error":t=t.message;break;case"_error_no_prompt":return!0}if(w)break;"string"==typeof t&&(l+=t+"
",d.iserror=!0,r++)}return!n&&!c.val()&&c.val().length<1&&i.indexof("equals")<0&&(d.iserror=!1),x=c.prop("type"),y=c.data("promptposition")||d.promptposition,("radio"==x||"checkbox"==x)&&p.find("input[name='"+k+"']").size()>1&&(c="inline"===y?a(p.find("input[name='"+k+"'][type!=hidden]:last")):a(p.find("input[name='"+k+"'][type!=hidden]:first")),d.showarrow=!1),c.is(":hidden")&&d.prettyselect&&(c=p.find("#"+d.useprefix+b._jqselector(c.attr("id"))+d.usesuffix)),d.iserror&&d.showprompts?b._showprompt(c,l,m,!1,d):j||b._closeprompt(c),j||c.trigger("jqv.field.result",[c,d.iserror,l]),z=a.inarray(c[0],d.invalidfields),-1==z?d.iserror&&d.invalidfields.push(c[0]):d.iserror||d.invalidfields.splice(z,1),b._handlestatuscssclasses(c,d),d.iserror&&d.onfieldfailure&&d.onfieldfailure(c),!d.iserror&&d.onfieldsuccess&&d.onfieldsuccess(c),d.iserror},_handlestatuscssclasses:function(a,b){b.addsuccesscssclasstofield&&a.removeclass(b.addsuccesscssclasstofield),b.addfailurecssclasstofield&&a.removeclass(b.addfailurecssclasstofield),b.addsuccesscssclasstofield&&!b.iserror&&a.addclass(b.addsuccesscssclasstofield),b.addfailurecssclasstofield&&b.iserror&&a.addclass(b.addfailurecssclasstofield)},_geterrormessage:function(c,d,e,f,g,h,i){var k,l,m,n,o,p,j=jquery.inarray(e,f);return("custom"===e||"funccall"===e)&&(k=f[j+1],e=e+"["+k+"]",delete f[j]),l=e,m=d.attr("data-validation-engine")?d.attr("data-validation-engine"):d.attr("class"),n=m.split(" "),o="future"==e||"past"==e||"maxcheckbox"==e||"mincheckbox"==e?i(c,d,f,g,h):i(d,f,g,h),void 0!=o&&(p=b._getcustomerrormessage(a(d),n,l,h),p&&(o=p)),o},_getcustomerrormessage:function(a,c,d,e){var h,i,j,f=!1,g=/^custom\[.*\]$/.test(d)?b._validityprop.custom:b._validityprop[d];if(void 0!=g&&(f=a.attr("data-errormessage-"+g),void 0!=f))return f;if(f=a.attr("data-errormessage"),void 0!=f)return f;if(h="#"+a.attr("id"),"undefined"!=typeof e.custom_error_messages[h]&&"undefined"!=typeof e.custom_error_messages[h][d])f=e.custom_error_messages[h][d].message;else if(c.length>0)for(i=0;i0;i++)if(j="."+c[i],"undefined"!=typeof e.custom_error_messages[j]&&"undefined"!=typeof e.custom_error_messages[j][d]){f=e.custom_error_messages[j][d].message;break}return f||"undefined"==typeof e.custom_error_messages[d]||"undefined"==typeof e.custom_error_messages[d].message||(f=e.custom_error_messages[d].message),f},_validityprop:{required:"value-missing",custom:"custom-error",grouprequired:"value-missing",ajax:"custom-error",minsize:"range-underflow",maxsize:"range-overflow",min:"range-underflow",max:"range-overflow",past:"type-mismatch",future:"type-mismatch",daterange:"type-mismatch",datetimerange:"type-mismatch",maxcheckbox:"range-overflow",mincheckbox:"range-underflow",equals:"pattern-mismatch",funccall:"custom-error",creditcard:"pattern-mismatch",condrequired:"value-missing"},_required:function(b,c,d,e,f){var g,h,i,j,k;switch(b.prop("type")){case"text":case"password":case"textarea":case"file":case"select-one":case"select-multiple":default:if(g=a.trim(b.val()),h=a.trim(b.attr("data-validation-placeholder")),i=a.trim(b.attr("placeholder")),!g||h&&g==h||i&&g==i)return e.allrules[c[d]].alerttext;break;case"radio":case"checkbox":if(f){if(!b.attr("checked"))return e.allrules[c[d]].alerttextcheckboxmultiple;break}if(j=b.closest("form, .validationenginecontainer"),k=b.attr("name"),0==j.find("input[name='"+k+"']:checked").size())return 1==j.find("input[name='"+k+"']:visible").size()?e.allrules[c[d]].alerttextcheckboxe:e.allrules[c[d]].alerttextcheckboxmultiple}},_grouprequired:function(c,d,e,f){var g="["+f.validateattribute+"*="+d[e+1]+"]",h=!1;return c.closest("form, .validationenginecontainer").find(g).each(function(){return b._required(a(this),d,e,f)?void 0:(h=!0,!1)}),h?void 0:f.allrules[d[e]].alerttext},_custom:function(a,b,c,d){var g,h,i,e=b[c+1],f=d.allrules[e];if(!f)return alert("jqv:custom rule not found - "+e),void 0;if(f.regex){if(h=f.regex,!h)return alert("jqv:custom regex not found - "+e),void 0;if(i=new regexp(h),!i.test(a.val()))return d.allrules[e].alerttext}else{if(!f.func)return alert("jqv:custom type not allowed "+e),void 0;if(g=f.func,"function"!=typeof g)return alert("jqv:custom parameter 'function' is no function - "+e),void 0;if(!g(a,b,c,d))return d.allrules[e].alerttext}},_funccall:function(a,b,c,d){var f,g,h,e=b[c+1];if(e.indexof(".")>-1){for(g=e.split("."),h=window;g.length;)h=h[g.shift()];f=h}else f=window[e]||d.customfunctions[e];return"function"==typeof f?f(a,b,c,d):void 0},_equals:function(b,c,d,e){var f=c[d+1];return b.val()!=a("#"+f).val()?e.allrules.equals.alerttext:void 0},_maxsize:function(a,b,c,d){var g,e=b[c+1],f=a.val().length;return f>e?(g=d.allrules.maxsize,g.alerttext+e+g.alerttext2):void 0},_minsize:function(a,b,c,d){var g,e=b[c+1],f=a.val().length;return e>f?(g=d.allrules.minsize,g.alerttext+e+g.alerttext2):void 0},_min:function(a,b,c,d){var g,e=parsefloat(b[c+1]),f=parsefloat(a.val());return e>f?(g=d.allrules.min,g.alerttext2?g.alerttext+e+g.alerttext2:g.alerttext+e):void 0},_max:function(a,b,c,d){var g,e=parsefloat(b[c+1]),f=parsefloat(a.val());return f>e?(g=d.allrules.max,g.alerttext2?g.alerttext+e+g.alerttext2:g.alerttext+e):void 0},_past:function(c,d,e,f,g){var j,k,l,h=e[f+1],i=a(c.find("*[name='"+h.replace(/^#+/,"")+"']"));if("now"==h.tolowercase())j=new date;else if(void 0!=i.val()){if(i.is(":disabled"))return;j=b._parsedate(i.val())}else j=b._parsedate(h);return k=b._parsedate(d.val()),k>j?(l=g.allrules.past,l.alerttext2?l.alerttext+b._datetostring(j)+l.alerttext2:l.alerttext+b._datetostring(j)):void 0},_future:function(c,d,e,f,g){var j,k,l,h=e[f+1],i=a(c.find("*[name='"+h.replace(/^#+/,"")+"']"));if("now"==h.tolowercase())j=new date;else if(void 0!=i.val()){if(i.is(":disabled"))return;j=b._parsedate(i.val())}else j=b._parsedate(h);return k=b._parsedate(d.val()),j>k?(l=g.allrules.future,l.alerttext2?l.alerttext+b._datetostring(j)+l.alerttext2:l.alerttext+b._datetostring(j)):void 0},_isdate:function(a){var b=new regexp(/^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(?:(?:0?[1-9]|1[0-2])(\/|-)(?:0?[1-9]|1\d|2[0-8]))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^(0?2(\/|-)29)(\/|-)(?:(?:0[48]00|[13579][26]00|[2468][048]00)|(?:\d\d)?(?:0[48]|[2468][048]|[13579][26]))$/);return b.test(a)},_isdatetime:function(a){var b=new regexp(/^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|am|pm){1}$|^(?:(?:(?:0?[13578]|1[02])(\/|-)31)|(?:(?:0?[1,3-9]|1[0-2])(\/|-)(?:29|30)))(\/|-)(?:[1-9]\d\d\d|\d[1-9]\d\d|\d\d[1-9]\d|\d\d\d[1-9])$|^((1[012]|0?[1-9]){1}\/(0?[1-9]|[12][0-9]|3[01]){1}\/\d{2,4}\s+(1[012]|0?[1-9]){1}:(0?[1-5]|[0-6][0-9]){1}:(0?[0-6]|[0-6][0-9]){1}\s+(am|pm|am|pm){1})$/);return b.test(a)},_datecompare:function(a,b){return new date(a.tostring())f?(e.showarrow=!1,e.allrules.maxcheckbox.alerttext2?e.allrules.maxcheckbox.alerttext+" "+f+" "+e.allrules.maxcheckbox.alerttext2:e.allrules.maxcheckbox.alerttext):void 0},_mincheckbox:function(a,b,c,d,e){var f=c[d+1],g=b.attr("name"),h=a.find("input[name='"+g+"']:checked").size();return f>h?(e.showarrow=!1,e.allrules.mincheckbox.alerttext+" "+f+" "+e.allrules.mincheckbox.alerttext2):void 0},_creditcard:function(a,b,c,d){var j,h,i,k,e=!1,f=a.val().replace(/ +/g,"").replace(/-+/g,""),g=f.length;if(g>=14&&16>=g&&parseint(f)>0){h=0,c=g-1,i=1,k=new string;do j=parseint(f.charat(c)),k+=0==i++%2?2*j:j;while(--c>=0);for(c=0;c");switch(h.addclass(b._getclassname(c.attr("id"))+"formerror"),h.addclass("parentform"+b._getclassname(c.closest("form, .validationenginecontainer").attr("id"))),h.addclass("formerror"),e){case"pass":h.addclass("greenpopup");break;case"load":h.addclass("blackpopup")}if(f&&h.addclass("ajaxed"),a("
").addclass("formerrorcontent").html(d).appendto(h),j=c.data("promptposition")||g.promptposition,g.showarrow)switch(k=a("
").addclass("formerrorarrow"),"string"==typeof j&&(l=j.indexof(":"),-1!=l&&(j=j.substring(0,l))),j){case"bottomleft":case"bottomright":h.find(".formerrorcontent").before(k),k.addclass("formerrorarrowbottom").html('
');break;case"topleft":case"topright":k.html('
'),h.append(k)}return g.addpromptclass&&h.addclass(g.addpromptclass),m=c.attr("data-required-class"),void 0!==m?h.addclass(m):g.prettyselect&&a("#"+c.attr("id")).next().is("select")&&(n=a("#"+c.attr("id").substr(g.useprefix.length).substring(g.usesuffix.length)).attr("data-required-class"),void 0!==n&&h.addclass(n)),h.css({opacity:0}),"inline"===j?(h.addclass("inline"),"undefined"!=typeof c.attr("data-prompt-target")&&a("#"+c.attr("data-prompt-target")).length>0?h.appendto(a("#"+c.attr("data-prompt-target"))):c.after(h)):c.before(h),l=b._calculateposition(c,h,g),h.css({position:"inline"===j?"relative":"absolute",top:l.callertopposition,left:l.callerleftposition,margintop:l.margintopsize,opacity:0}).data("callerfield",c),g.autohideprompt&&settimeout(function(){h.animate({opacity:0},function(){h.closest(".formerrorouter").remove(),h.remove()})},g.autohidedelay),h.animate({opacity:.87})},_updateprompt:function(a,c,d,e,f,g,h){var i,j;c&&("undefined"!=typeof e&&("pass"==e?c.addclass("greenpopup"):c.removeclass("greenpopup"),"load"==e?c.addclass("blackpopup"):c.removeclass("blackpopup")),f?c.addclass("ajaxed"):c.removeclass("ajaxed"),c.find(".formerrorcontent").html(d),i=b._calculateposition(a,c,g),j={top:i.callertopposition,left:i.callerleftposition,margintop:i.margintopsize},h?c.css(j):c.animate(j))},_closeprompt:function(a){var c=b._getprompt(a);c&&c.fadeto("fast",0,function(){c.parent(".formerrorouter").remove(),c.remove()})},closeprompt:function(a){return b._closeprompt(a)},_getprompt:function(c){var d=a(c).closest("form, .validationenginecontainer").attr("id"),e=b._getclassname(c.attr("id"))+"formerror",f=a("."+b._escapeexpression(e)+".parentform"+b._getclassname(d))[0];return f?a(f):void 0},_escapeexpression:function(a){return a.replace(/([#;&,\.\+\*\~':"\!\^$\[\]\(\)=>\|])/g,"\\$1")},isrtl:function(b){var c=a(document),d=a("body"),e=b&&b.hasclass("rtl")||b&&"rtl"===(b.attr("dir")||"").tolowercase()||c.hasclass("rtl")||"rtl"===(c.attr("dir")||"").tolowercase()||d.hasclass("rtl")||"rtl"===(d.attr("dir")||"").tolowercase();return boolean(e)},_calculateposition:function(a,b,c){var d,e,f,k,l,m,n,o,p,g=a.width(),h=a.position().left,i=a.position().top;switch(a.height(),k=b.height(),d=e=0,f=-k,l=a.data("promptposition")||c.promptposition,m="",n="",o=0,p=0,"string"==typeof l&&-1!=l.indexof(":")&&(m=l.substring(l.indexof(":")+1),l=l.substring(0,l.indexof(":")),-1!=m.indexof(",")&&(n=m.substring(m.indexof(",")+1),m=m.substring(0,m.indexof(",")),p=parseint(n),isnan(p)&&(p=0)),o=parseint(m),isnan(m)&&(m=0)),l){default:case"topright":e+=h+g-30,d+=i;break;case"topleft":d+=i,e+=h;break;case"centerright":d=i,f=0,e=h+a.outerwidth(!0)+5;break;case"centerleft":e=h-b.outerwidth(),d=i,f=0;break;case"bottomleft":d=i+a.outerheight(),f=0,e=h;break;case"bottomright":e=h+g-30,d=i+a.outerheight(),f=0;break;case"inline":e=0,d=0,f=0}return e+=o,d+=p,{callertopposition:d+"px",callerleftposition:e+"px",margintopsize:f+"px"}},_saveoptions:function(b,c){var d,e;return a.validationenginelanguage?d=a.validationenginelanguage.allrules:a.error("jquery.validationengine rules are not loaded, plz add localization files to the page"),a.validationengine.defaults.allrules=d,e=a.extend(!0,{},a.validationengine.defaults,c),b.data("jqv",e),e},_getclassname:function(a){return a?a.replace(/:/g,"_").replace(/\./g,"_"):void 0},_jqselector:function(a){return a.replace(/([;&,\.\+\*\~':"\!\^#$%@\[\]\(\)=>\|])/g,"\\$1")},_condrequired:function(a,c,d,e){var f,g;for(f=d+1;f