11 lines
No EOL
26 KiB
JavaScript
11 lines
No EOL
26 KiB
JavaScript
/*
|
|
* # Fomantic UI - 2.8.8
|
|
* https://github.com/fomantic/Fomantic-UI
|
|
* http://fomantic-ui.com/
|
|
*
|
|
* Copyright 2022 Contributors
|
|
* Released under the MIT license
|
|
* http://opensource.org/licenses/MIT
|
|
*
|
|
*/
|
|
!function($,I,O,L){"use strict";$.isFunction=$.isFunction||function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},I=void 0!==I&&I.Math==Math?I:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),$.fn.form=function(C){var w,V=$(this),A=V.selector||"",D=(new Date).getTime(),F=[],R=C,S=arguments[1],T="string"==typeof R,j=[].slice.call(arguments,1);return V.each(function(){var n,d,t,e,f,s,m,p,g,r,c,i,a,l,v,u=$(this),b=this,y=[],x=!1,o=!1,k=!1,E=["clean","clean"],h={initialize:function(){h.get.settings(),T?(v===L&&h.instantiate(),h.invoke(R)):(v!==L&&(v.invoke("destroy"),h.refresh()),h.verbose("Initializing form validation",u,f),h.bindEvents(),h.set.defaults(),f.autoCheckRequired&&h.set.autoCheck(),h.instantiate())},instantiate:function(){h.verbose("Storing instance of module",h),v=h,u.data(a,h)},destroy:function(){h.verbose("Destroying previous module",v),h.removeEvents(),u.removeData(a)},refresh:function(){h.verbose("Refreshing selector cache"),n=u.find(p.field),d=u.find(p.group),t=u.find(p.message),u.find(p.prompt),e=u.find(p.submit),u.find(p.clear),u.find(p.reset)},submit:function(){h.verbose("Submitting form",u),o=!0,u.submit()},attachEvents:function(e,t){t=t||"submit",$(e).on("click"+l,function(e){h[t](),e.preventDefault()})},bindEvents:function(){h.verbose("Attaching form events"),u.on("submit"+l,h.validate.form).on("blur"+l,p.field,h.event.field.blur).on("click"+l,p.submit,h.submit).on("click"+l,p.reset,h.reset).on("click"+l,p.clear,h.clear),f.keyboardShortcuts&&u.on("keydown"+l,p.field,h.event.field.keydown),n.each(function(e,t){var t=$(t),n=t.prop("type"),n=h.get.changeEvent(n,t);t.on(n+l,h.event.field.change)}),f.preventLeaving&&$(I).on("beforeunload"+l,h.event.beforeUnload),n.on("change click keyup keydown blur",function(e){h.determine.isDirty()}),u.on("dirty"+l,function(e){f.onDirty.call()}),u.on("clean"+l,function(e){f.onClean.call()})},clear:function(){n.each(function(u,e){var e=$(e),t=e.parent(),n=e.closest(d),r=n.find(p.prompt),i=e.closest(p.uiCalendar),a=e.data(m.defaultValue)||"",o=t.is(p.uiCheckbox),l=t.is(p.uiDropdown)&&h.can.useElement("dropdown"),s=0<i.length&&h.can.useElement("calendar");n.hasClass(g.error)&&(h.verbose("Resetting error on field",n),n.removeClass(g.error),r.remove()),l?(h.verbose("Resetting dropdown value",t,a),t.dropdown("clear",!0)):o?e.prop("checked",!1):s?i.calendar("clear"):(h.verbose("Resetting field value",e,a),e.val(""))}),h.remove.states()},reset:function(){n.each(function(c,e){var e=$(e),t=e.parent(),n=e.closest(d),r=e.closest(p.uiCalendar),i=n.find(p.prompt),a=e.data(m.defaultValue),o=t.is(p.uiCheckbox),l=t.is(p.uiDropdown)&&h.can.useElement("dropdown"),s=0<r.length&&h.can.useElement("calendar"),u=n.hasClass(g.error);a!==L&&(u&&(h.verbose("Resetting error on field",n),n.removeClass(g.error),i.remove()),l?(h.verbose("Resetting dropdown value",t,a),t.dropdown("restore defaults",!0)):o?(h.verbose("Resetting checkbox value",t,a),e.prop("checked",a)):s?r.calendar("set date",a):(h.verbose("Resetting field value",e,a),e.val(a)))}),h.remove.states()},determine:{isValid:function(){var n=!0;return $.each(s,function(e,t){h.validate.field(t,e,!0)||(n=!1)}),n},isDirty:function(e){var r=!1;n.each(function(e,t){var t=$(t),n=0<t.filter(p.checkbox).length?h.is.checkboxDirty(t):h.is.fieldDirty(t);t.data(f.metadata.isDirty,n),r|=n}),r?h.set.dirty():h.set.clean()}},is:{bracketedRule:function(e){return e.type&&e.type.match(f.regExp.bracket)},shorthandRules:function(e){return"string"==typeof e||Array.isArray(e)},empty:function(e){return!e||0===e.length||(e.is(p.checkbox)?!e.is(":checked"):h.is.blank(e))},blank:function(e){return""===String(e.val()).trim()},valid:function(e,n){var r=!0;return e?(h.verbose("Checking if field is valid",e),h.validate.field(s[e],e,!!n)):(h.verbose("Checking if form is valid"),$.each(s,function(e,t){h.is.valid(e,n)||(r=!1)}),r)},dirty:function(){return k},clean:function(){return!k},fieldDirty:function(e){var t=e.data(m.defaultValue),e=(null==t?t="":Array.isArray(t)&&(t=t.toString()),e.val()),n=(null==e?e="":Array.isArray(e)&&(e=e.toString()),/^(true|false)$/i);return n.test(t)&&n.test(e)?!new RegExp("^"+t+"$","i").test(e):e!==t},checkboxDirty:function(e){return e.data(m.defaultValue)!==e.is(":checked")},justDirty:function(){return"dirty"===E[0]},justClean:function(){return"clean"===E[0]}},removeEvents:function(){u.off(l),n.off(l),e.off(l),n.off(l)},event:{field:{keydown:function(e){var t=$(this),n=e.which,r=t.is(p.input),i=t.is(p.checkbox),a=0<t.closest(p.uiDropdown).length,o=13;n==27&&(h.verbose("Escape key pressed blurring field"),t[0].blur()),e.ctrlKey||n!=o||!r||a||i||(x||(t.one("keyup"+l,h.event.field.keyup),h.submit(),h.debug("Enter pressed on input submitting form")),x=!0)},keyup:function(){x=!1},blur:function(e){var t=$(this),n=t.closest(d),r=h.get.validation(t);r&&("blur"==f.on||n.hasClass(g.error)&&f.revalidate)&&(h.debug("Revalidating field",t,r),h.validate.field(r),f.inline||h.validate.form(!1,!0))},change:function(e){var t=$(this),n=t.closest(d),r=h.get.validation(t);r&&("change"==f.on||n.hasClass(g.error)&&f.revalidate)&&(clearTimeout(h.timer),h.timer=setTimeout(function(){h.debug("Revalidating field",t,r),h.validate.field(r),f.inline||h.validate.form(!1,!0)},f.delay))}},beforeUnload:function(e){if(h.is.dirty()&&!o)return(e=e||I.event)&&(e.returnValue=f.text.leavingMessage),f.text.leavingMessage}},get:{ancillaryValue:function(e){return!(!e.type||!e.value&&!h.is.bracketedRule(e))&&(e.value!==L?e.value:e.type.match(f.regExp.bracket)[1]+"")},ruleName:function(e){return h.is.bracketedRule(e)?e.type.replace(e.type.match(f.regExp.bracket)[0],""):e.type},changeEvent:function(e,t){return"checkbox"==e||"radio"==e||"hidden"==e||t.is("select")?"change":h.get.inputEvent()},inputEvent:function(){return O.createElement("input").oninput!==L?"input":O.createElement("input").onpropertychange!==L?"propertychange":"keyup"},fieldsFromShorthand:function(e){var r={};return $.each(e,function(n,e){Array.isArray(e)||"object"!=typeof e?("string"==typeof e&&(e=[e]),r[n]={rules:[]},$.each(e,function(e,t){r[n].rules.push({type:t})})):r[n]=e}),r},prompt:function(e,t){var n,r=h.get.ruleName(e),i=h.get.ancillaryValue(e),a=h.get.field(t.identifier),o=a.val(),o=$.isFunction(e.prompt)?e.prompt(o):e.prompt||f.prompt[r]||f.text.unspecifiedRule,l=-1!==o.search("{value}"),s=-1!==o.search("{name}");return i&&0<=i.indexOf("..")&&(n=i.split("..",2),e.prompt||(o+=(""===n[0]?f.prompt.maxValue.replace(/\{ruleValue\}/g,"{max}"):""===n[1]?f.prompt.minValue.replace(/\{ruleValue\}/g,"{min}"):f.prompt.range).replace(/\{name\}/g," "+f.text.and)),o=(o=o.replace(/\{min\}/g,n[0])).replace(/\{max\}/g,n[1])),l&&(o=o.replace(/\{value\}/g,a.val())),s&&(l=1==(n=a.closest(p.group).find("label").eq(0)).length?n.text():a.prop("placeholder")||f.text.unspecifiedField,o=o.replace(/\{name\}/g,l)),o=(o=o.replace(/\{identifier\}/g,t.identifier)).replace(/\{ruleValue\}/g,i),e.prompt||h.verbose("Using default validation prompt for type",o,r),o},settings:function(){var e;$.isPlainObject(C)?0<(e=Object.keys(C)).length&&(C[e[0]].identifier!==L&&C[e[0]].rules!==L)?(f=$.extend(!0,{},$.fn.form.settings,S),s=$.extend({},$.fn.form.settings.defaults,C),h.error(f.error.oldSyntax,b),h.verbose("Extending settings from legacy parameters",s,f)):(C.fields&&(C.fields=h.get.fieldsFromShorthand(C.fields)),f=$.extend(!0,{},$.fn.form.settings,C),s=$.extend({},$.fn.form.settings.defaults,f.fields),h.verbose("Extending settings",s,f)):(f=$.fn.form.settings,s=$.fn.form.settings.defaults,h.verbose("Using default form validation",s,f)),i=f.namespace,m=f.metadata,p=f.selector,g=f.className,r=f.regExp,c=f.error,a="module-"+i,l="."+i,((v=u.data(a))||h).refresh()},field:function(e){var t;return h.verbose("Finding field with identifier",e),e=h.escape.string(e),0<(t=n.filter("#"+e)).length||0<(t=n.filter('[name="'+e+'"]')).length||0<(t=n.filter('[name="'+e+'[]"]')).length||0<(t=n.filter("[data-"+m.validate+'="'+e+'"]')).length?t:$("<input/>")},fields:function(e){var n=$();return $.each(e,function(e,t){n=n.add(h.get.field(t))}),n},validation:function(r){var i,a;return!!s&&($.each(s,function(e,n){a=n.identifier||e,$.each(h.get.field(a),function(e,t){if(t==r[0])return n.identifier=a,i=n,!1})}),i||!1)},value:function(e){var t=[];return t.push(e),h.get.values.call(b,t)[e]},values:function(e){var e=Array.isArray(e)?h.get.fields(e):n,d={};return e.each(function(c,e){var e=$(e),t=e.closest(p.uiCalendar),n=e.prop("name"),r=e.val(),i=e.is(p.checkbox),a=e.is(p.radio),o=-1!==n.indexOf("[]"),l=0<t.length&&h.can.useElement("calendar"),e=!!i&&e.is(":checked");if(n)if(o)n=n.replace("[]",""),d[n]||(d[n]=[]),i?e?d[n].push(r||!0):d[n].push(!1):d[n].push(r);else if(a)d[n]!==L&&!1!==d[n]||(d[n]=!!e&&(r||!0));else if(i)d[n]=!!e&&(r||!0);else if(l){var s=t.calendar("get date");if(null!==s){if("date"==f.dateHandling)d[n]=s;else if("input"==f.dateHandling)d[n]=t.calendar("get input date");else if("formatter"==f.dateHandling){var u=t.calendar("setting","type");switch(u){case"date":d[n]=f.formatter.date(s);break;case"datetime":d[n]=f.formatter.datetime(s);break;case"time":d[n]=f.formatter.time(s);break;case"month":d[n]=f.formatter.month(s);break;case"year":d[n]=f.formatter.year(s);break;default:h.debug("Wrong calendar mode",t,u),d[n]=""}}}else d[n]=""}else d[n]=r}),d},dirtyFields:function(){return n.filter(function(e,t){return $(t).data(m.isDirty)})}},has:{field:function(e){return h.verbose("Checking for existence of a field with identifier",e),"string"!=typeof(e=h.escape.string(e))&&h.error(c.identifier,e),0<n.filter("#"+e).length||(0<n.filter('[name="'+e+'"]').length||0<n.filter("[data-"+m.validate+'="'+e+'"]').length)}},can:{useElement:function(e){return $.fn[e]!==L||(h.error(c.noElement.replace("{element}",e)),!1)}},escape:{string:function(e){return(e=String(e)).replace(r.escape,"\\$&")}},add:{rule:function(e,t){h.add.field(e,t)},field:function(n,e){s[n]!==L&&s[n].rules!==L||(s[n]={rules:[]});var r={rules:[]};h.is.shorthandRules(e)?(e=Array.isArray(e)?e:[e],$.each(e,function(e,t){r.rules.push({type:t})})):r.rules=e.rules,$.each(r.rules,function(e,t){0==$.grep(s[n].rules,function(e){return e.type==t.type}).length&&s[n].rules.push(t)}),h.debug("Adding rules",r.rules,s)},fields:function(e){s=$.extend({},s,h.get.fieldsFromShorthand(e))},prompt:function(e,t,n){var r=h.get.field(e).closest(d),i=r.children(p.prompt),a=0!==i.length;t="string"==typeof t?[t]:t,h.verbose("Adding field error state",e),n||r.addClass(g.error),f.inline&&(a||(i=f.templates.prompt(t,g.label)).appendTo(r),i.html(t[0]),a?h.verbose("Inline errors are disabled, no inline error added",e):f.transition&&h.can.useElement("transition")&&u.transition("is supported")?(h.verbose("Displaying error with css transition",f.transition),i.transition(f.transition+" in",f.duration)):(h.verbose("Displaying error with fallback javascript animation"),i.fadeIn(f.duration)))},errors:function(e){h.debug("Adding form error messages",e),h.set.error(),t.html(f.templates.error(e))}},remove:{errors:function(){h.debug("Removing form error messages"),t.empty()},states:function(){u.removeClass(g.error).removeClass(g.success),f.inline||h.remove.errors(),h.determine.isDirty()},rule:function(n,e){var r=Array.isArray(e)?e:[e];if(s[n]!==L&&Array.isArray(s[n].rules))return e===L?(h.debug("Removed all rules"),void(s[n].rules=[])):void $.each(s[n].rules,function(e,t){t&&-1!==r.indexOf(t.type)&&(h.debug("Removed rule",t.type),s[n].rules.splice(e,1))})},field:function(e){e=Array.isArray(e)?e:[e];$.each(e,function(e,t){h.remove.rule(t)})},rules:function(e,n){Array.isArray(e)?$.each(e,function(e,t){h.remove.rule(t,n)}):h.remove.rule(e,n)},fields:function(e){h.remove.field(e)},prompt:function(e){var t=h.get.field(e).closest(d),n=t.children(p.prompt);t.removeClass(g.error),f.inline&&n.is(":visible")&&(h.verbose("Removing prompt for field",e),f.transition&&h.can.useElement("transition")&&u.transition("is supported")?n.transition(f.transition+" out",f.duration,function(){n.remove()}):n.fadeOut(f.duration,function(){n.remove()}))}},set:{success:function(){u.removeClass(g.error).addClass(g.success)},defaults:function(){n.each(function(e,t){var t=$(t),n=t.parent(),r=0<t.filter(p.checkbox).length,i=n.is(p.uiDropdown)&&h.can.useElement("dropdown"),a=t.closest(p.uiCalendar),o=0<a.length&&h.can.useElement("calendar"),r=r?t.is(":checked"):t.val();i?n.dropdown("save defaults"):o&&a.calendar("refresh"),t.data(m.defaultValue,r),t.data(m.isDirty,!1)})},error:function(){u.removeClass(g.success).addClass(g.error)},value:function(e,t){var n={};return n[e]=t,h.set.values.call(b,n)},values:function(e){$.isEmptyObject(e)||$.each(e,function(e,t){var n,r=h.get.field(e),i=r.parent(),e=r.closest(p.uiCalendar),a=Array.isArray(t),o=i.is(p.uiCheckbox)&&h.can.useElement("checkbox"),l=i.is(p.uiDropdown)&&h.can.useElement("dropdown"),s=r.is(p.radio)&&o,u=0<e.length&&h.can.useElement("calendar");0<r.length&&(a&&o?(h.verbose("Selecting multiple",t,r),i.checkbox("uncheck"),$.each(t,function(e,t){n=r.filter('[value="'+t+'"]'),i=n.parent(),0<n.length&&i.checkbox("check")})):s?(h.verbose("Selecting radio value",t,r),r.filter('[value="'+t+'"]').parent(p.uiCheckbox).checkbox("check")):o?(h.verbose("Setting checkbox value",t,i),!0===t||1===t?i.checkbox("check"):i.checkbox("uncheck")):l?(h.verbose("Setting dropdown value",t,i),i.dropdown("set selected",t)):u?e.calendar("set date",t):(h.verbose("Setting field value",t,r),r.val(t)))})},dirty:function(){h.verbose("Setting state dirty"),k=!0,E[0]=E[1],E[1]="dirty",h.is.justClean()&&u.trigger("dirty")},clean:function(){h.verbose("Setting state clean"),k=!1,E[0]=E[1],E[1]="clean",h.is.justDirty()&&u.trigger("clean")},asClean:function(){h.set.defaults(),h.set.clean()},asDirty:function(){h.set.defaults(),h.set.dirty()},autoCheck:function(){h.debug("Enabling auto check on required fields"),n.each(function(e,t){var n=$(t),t=$(t).closest(d),r=0<n.filter(p.checkbox).length,i=n.prop("required")||t.hasClass(g.required)||t.parent().hasClass(g.required),t=n.is(":disabled")||t.hasClass(g.disabled)||t.parent().hasClass(g.disabled),a=h.get.validation(n),o=!!a&&0!==$.grep(a.rules,function(e){return"empty"==e.type}),a=a.identifier||n.attr("id")||n.attr("name")||n.data(m.validate);!i||t||o||a===L||(r?(h.verbose("Adding 'checked' rule on field",a),h.add.rule(a,"checked")):(h.verbose("Adding 'empty' rule on field",a),h.add.rule(a,"empty")))})},optional:function(n,r){r=!1!==r,$.each(s,function(e,t){n!=e&&n!=t.identifier||(t.optional=r)})}},validate:{form:function(e,t){var n,r=h.get.values();if(x)return!1;if(y=[],h.determine.isValid()){if(h.debug("Form has no validation errors, submitting"),h.set.success(),f.inline||h.remove.errors(),!0!==t)return f.onSuccess.call(b,e,r)}else if(h.debug("Form has errors"),o=!1,h.set.error(),f.inline||h.add.errors(y),e&&u.data("moduleApi")!==L&&e.stopImmediatePropagation(),f.errorFocus&&(e=!0,"string"==typeof f.errorFocus?(e=(n=$(f.errorFocus)).is("[tabindex]"))||n.attr("tabindex",-1):n=d.filter("."+g.error).first().find(p.field),n.focus(),e||n.removeAttr("tabindex")),!0!==t)return f.onFailure.call(b,y,r)},field:function(r,e,i){i=i===L||i,"string"==typeof r&&(h.verbose("Validating field",r),r=s[e=r]);var a=r.identifier||e,e=h.get.field(a),t=!!r.depends&&h.get.field(r.depends),o=!0,l=[];return r.identifier||(h.debug("Using field name as identifier",a),r.identifier=a),!e.filter(":not(:disabled)").length?h.debug("Field is disabled. Skipping",a):r.optional&&h.is.blank(e)?h.debug("Field is optional and blank. Skipping",a):r.depends&&h.is.empty(t)?h.debug("Field depends on another value that is not present or empty. Skipping",t):r.rules!==L&&(i&&e.closest(d).removeClass(g.error),$.each(r.rules,function(e,t){var n;!h.has.field(a)||0<(n=h.validate.rule(r,t,!0)||[]).length&&(h.debug("Field is invalid",a,t.type),l.push(h.get.prompt(t,r)),o=!1,i&&$(n).closest(d).addClass(g.error))})),o?(i&&(h.remove.prompt(a,l),f.onValid.call(e)),!0):(i&&(y=y.concat(l),h.add.prompt(a,l,!0),f.onInvalid.call(e,l)),!1)},rule:function(e,n,t){function r(e){var t=(t=(s?$(e).filter(":checked"):$(e)).val())===L||""===t||null===t?"":f.shouldTrim&&!1!==n.shouldTrim||n.shouldTrim?String(t+"").trim():String(t+"");return o.call(e,t,i,u)}var e=h.get.field(e.identifier),i=h.get.ancillaryValue(n),a=h.get.ruleName(n),o=f.rules[a],l=[],s=e.is(p.checkbox);if($.isFunction(o))return s?r(e)||(l=e):$.each(e,function(e,t){r(t)||l.push(t)}),t?l:!(0<l.length);h.error(c.noRule,a)}},setting:function(e,t){if($.isPlainObject(e))$.extend(!0,f,e);else{if(t===L)return f[e];f[e]=t}},internal:function(e,t){if($.isPlainObject(e))$.extend(!0,h,e);else{if(t===L)return h[e];h[e]=t}},debug:function(){!f.silent&&f.debug&&(f.performance?h.performance.log(arguments):(h.debug=Function.prototype.bind.call(console.info,console,f.name+":"),h.debug.apply(console,arguments)))},verbose:function(){!f.silent&&f.verbose&&f.debug&&(f.performance?h.performance.log(arguments):(h.verbose=Function.prototype.bind.call(console.info,console,f.name+":"),h.verbose.apply(console,arguments)))},error:function(){f.silent||(h.error=Function.prototype.bind.call(console.error,console,f.name+":"),h.error.apply(console,arguments))},performance:{log:function(e){var t,n;f.performance&&(n=(t=(new Date).getTime())-(D||t),D=t,F.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:b,"Execution Time":n})),clearTimeout(h.performance.timer),h.performance.timer=setTimeout(h.performance.display,500)},display:function(){var e=f.name+":",n=0;D=!1,clearTimeout(h.performance.timer),$.each(F,function(e,t){n+=t["Execution Time"]}),e+=" "+n+"ms",A&&(e+=" '"+A+"'"),1<V.length&&(e+=" ("+V.length+")"),(console.group!==L||console.table!==L)&&0<F.length&&(console.groupCollapsed(e),console.table?console.table(F):$.each(F,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),F=[]}},invoke:function(r,e,t){var i,a,n,o=v;return e=e||j,t=b||t,"string"==typeof r&&o!==L&&(r=r.split(/[\. ]/),i=r.length-1,$.each(r,function(e,t){var n=e!=i?t+r[e+1].charAt(0).toUpperCase()+r[e+1].slice(1):r;if($.isPlainObject(o[n])&&e!=i)o=o[n];else{if(o[n]!==L)return a=o[n],!1;{if(!$.isPlainObject(o[t])||e==i)return o[t]!==L&&(a=o[t]),!1;o=o[t]}}})),$.isFunction(a)?n=a.apply(t,e):a!==L&&(n=a),Array.isArray(w)?w.push(n):w!==L?w=[w,n]:n!==L&&(w=n),a}};h.initialize()}),w!==L?w:this},$.fn.form.settings={name:"Form",namespace:"form",debug:!1,verbose:!1,performance:!0,fields:!1,keyboardShortcuts:!0,on:"submit",inline:!1,delay:200,revalidate:!0,shouldTrim:!0,transition:"scale",duration:200,autoCheckRequired:!1,preventLeaving:!1,errorFocus:!1,dateHandling:"date",onValid:function(){},onInvalid:function(){},onSuccess:function(){return!0},onFailure:function(){return!1},onDirty:function(){},onClean:function(){},metadata:{defaultValue:"default",validate:"validate",isDirty:"isDirty"},regExp:{htmlID:/^[a-zA-Z][\w:.-]*$/g,bracket:/\[(.*)\]/i,decimal:/^\d+\.?\d*$/,email:/^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i,escape:/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|:,=@]/g,flags:/^\/(.*)\/(.*)?/,integer:/^\-?\d+$/,number:/^\-?\d*(\.\d+)?$/,url:/(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/i},text:{and:"and",unspecifiedRule:"Please enter a valid value",unspecifiedField:"This field",leavingMessage:"There are unsaved changes on this page which will be discarded if you continue."},prompt:{range:"{name} must be in a range from {min} to {max}",maxValue:"{name} must have a maximum value of {ruleValue}",minValue:"{name} must have a minimum value of {ruleValue}",empty:"{name} must have a value",checked:"{name} must be checked",email:"{name} must be a valid e-mail",url:"{name} must be a valid url",regExp:"{name} is not formatted correctly",integer:"{name} must be an integer",decimal:"{name} must be a decimal number",number:"{name} must be set to a number",is:'{name} must be "{ruleValue}"',isExactly:'{name} must be exactly "{ruleValue}"',not:'{name} cannot be set to "{ruleValue}"',notExactly:'{name} cannot be set to exactly "{ruleValue}"',contain:'{name} must contain "{ruleValue}"',containExactly:'{name} must contain exactly "{ruleValue}"',doesntContain:'{name} cannot contain "{ruleValue}"',doesntContainExactly:'{name} cannot contain exactly "{ruleValue}"',minLength:"{name} must be at least {ruleValue} characters",length:"{name} must be at least {ruleValue} characters",exactLength:"{name} must be exactly {ruleValue} characters",maxLength:"{name} cannot be longer than {ruleValue} characters",match:"{name} must match {ruleValue} field",different:"{name} must have a different value than {ruleValue} field",creditCard:"{name} must be a valid credit card number",minCount:"{name} must have at least {ruleValue} choices",exactCount:"{name} must have exactly {ruleValue} choices",maxCount:"{name} must have {ruleValue} or less choices"},selector:{checkbox:'input[type="checkbox"], input[type="radio"]',clear:".clear",field:'input:not(.search):not([type="file"]), textarea, select',group:".field",input:'input:not([type="file"])',message:".error.message",prompt:".prompt.label",radio:'input[type="radio"]',reset:'.reset:not([type="reset"])',submit:'.submit:not([type="submit"])',uiCheckbox:".ui.checkbox",uiDropdown:".ui.dropdown",uiCalendar:".ui.calendar"},className:{error:"error",label:"ui basic red pointing prompt label",pressed:"down",success:"success",required:"required",disabled:"disabled"},error:{identifier:"You must specify a string identifier for each field",method:"The method you called is not defined.",noRule:"There is no rule matching the one you specified",oldSyntax:"Starting in 2.0 forms now only take a single settings object. Validation settings converted to new syntax automatically.",noElement:"This module requires ui {element}"},templates:{error:function(e){var n='<ul class="list">';return $.each(e,function(e,t){n+="<li>"+t+"</li>"}),$(n+="</ul>")},prompt:function(e,t){return $("<div/>").addClass(t).html(e[0])}},formatter:{date:function(e){return Intl.DateTimeFormat("en-GB").format(e)},datetime:function(e){return Intl.DateTimeFormat("en-GB",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(e)},time:function(e){return Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(e)},month:function(e){return Intl.DateTimeFormat("en-GB",{month:"2-digit",year:"numeric"}).format(e)},year:function(e){return Intl.DateTimeFormat("en-GB",{year:"numeric"}).format(e)}},rules:{empty:function(e){return!(e===L||""===e||Array.isArray(e)&&0===e.length)},checked:function(){return 0<$(this).filter(":checked").length},email:function(e){return $.fn.form.settings.regExp.email.test(e)},url:function(e){return $.fn.form.settings.regExp.url.test(e)},regExp:function(e,t){if(t instanceof RegExp)return e.match(t);var n,r=t.match($.fn.form.settings.regExp.flags);return r&&(t=2<=r.length?r[1]:t,n=3<=r.length?r[2]:""),e.match(new RegExp(t,n))},minValue:function(e,t){return $.fn.form.settings.rules.range(e,t+"..","number")},maxValue:function(e,t){return $.fn.form.settings.rules.range(e,".."+t,"number")},integer:function(e,t){return $.fn.form.settings.rules.range(e,t,"integer")},range:function(e,t,n){var r,i;return(n="string"==typeof n?$.fn.form.settings.regExp[n]:n)instanceof RegExp||(n=$.fn.form.settings.regExp.integer),t&&-1===["",".."].indexOf(t)&&(-1==t.indexOf("..")?n.test(t)&&(r=i=+t):(t=t.split("..",2),n.test(t[0])&&(r=+t[0]),n.test(t[1])&&(i=+t[1]))),n.test(e)&&(r===L||r<=e)&&(i===L||e<=i)},decimal:function(e,t){return $.fn.form.settings.rules.range(e,t,"decimal")},number:function(e,t){return $.fn.form.settings.rules.range(e,t,"number")},is:function(e,t){return t="string"==typeof t?t.toLowerCase():t,(e="string"==typeof e?e.toLowerCase():e)==t},isExactly:function(e,t){return e==t},not:function(e,t){return(e="string"==typeof e?e.toLowerCase():e)!=(t="string"==typeof t?t.toLowerCase():t)},notExactly:function(e,t){return e!=t},contains:function(e,t){return t=t.replace($.fn.form.settings.regExp.escape,"\\$&"),-1!==e.search(new RegExp(t,"i"))},containsExactly:function(e,t){return t=t.replace($.fn.form.settings.regExp.escape,"\\$&"),-1!==e.search(new RegExp(t))},doesntContain:function(e,t){return t=t.replace($.fn.form.settings.regExp.escape,"\\$&"),-1===e.search(new RegExp(t,"i"))},doesntContainExactly:function(e,t){return t=t.replace($.fn.form.settings.regExp.escape,"\\$&"),-1===e.search(new RegExp(t))},minLength:function(e,t){return e!==L&&e.length>=t},length:function(e,t){return e!==L&&e.length>=t},exactLength:function(e,t){return e!==L&&e.length==t},maxLength:function(e,t){return e!==L&&e.length<=t},match:function(e,t,n){var r,i;return 0<(i=n.find('[data-validate="'+t+'"]')).length||0<(i=n.find("#"+t)).length||0<(i=n.find('[name="'+t+'"]')).length?r=i.val():0<(i=n.find('[name="'+t+'[]"]')).length&&(r=i),r!==L&&e.toString()==r.toString()},different:function(e,t,n){var r,i;return 0<(i=n.find('[data-validate="'+t+'"]')).length||0<(i=n.find("#"+t)).length||0<(i=n.find('[name="'+t+'"]')).length?r=i.val():0<(i=n.find('[name="'+t+'[]"]')).length&&(r=i),r!==L&&e.toString()!==r.toString()},creditCard:function(n,e){var r,i,a={visa:{pattern:/^4/,length:[16]},amex:{pattern:/^3[47]/,length:[15]},mastercard:{pattern:/^5[1-5]/,length:[16]},discover:{pattern:/^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)/,length:[16]},unionPay:{pattern:/^(62|88)/,length:[16,17,18,19]},jcb:{pattern:/^35(2[89]|[3-8][0-9])/,length:[16]},maestro:{pattern:/^(5018|5020|5038|6304|6759|676[1-3])/,length:[12,13,14,15,16,17,18,19]},dinersClub:{pattern:/^(30[0-5]|^36)/,length:[14]},laser:{pattern:/^(6304|670[69]|6771)/,length:[16,17,18,19]},visaElectron:{pattern:/^(4026|417500|4508|4844|491(3|7))/,length:[16]}},o=!1,e="string"==typeof e&&e.split(",");if("string"==typeof n&&0!==n.length){if(n=n.replace(/[\s\-]/g,""),e&&($.each(e,function(e,t){(i=a[t])&&(r={length:-1!==$.inArray(n.length,i.length),pattern:-1!==n.search(i.pattern)}).length&&r.pattern&&(o=!0)}),!o))return!1;if((e={number:-1!==$.inArray(n.length,a.unionPay.length),pattern:-1!==n.search(a.unionPay.pattern)}).number&&e.pattern)return!0;for(var t=n.length,l=0,s=[[0,1,2,3,4,5,6,7,8,9],[0,2,4,6,8,1,3,5,7,9]],u=0;t--;)u+=s[l][parseInt(n.charAt(t),10)],l^=1;return u%10==0&&0<u}},minCount:function(e,t){return 0==t||(1==t?""!==e:e.split(",").length>=t)},exactCount:function(e,t){return 0==t?""===e:1==t?""!==e&&-1===e.search(","):e.split(",").length==t},maxCount:function(e,t){return 0!=t&&(1==t?-1===e.search(","):e.split(",").length<=t)}}}}(jQuery,window,document); |