|
|
/*! * # Semantic UI 1.12.0 - Form Validation * http://github.com/semantic-org/semantic-ui/
* * * Copyright 2014 Contributors * Released under the MIT license * http://opensource.org/licenses/MIT
* */ !function(e,t,n,i){"use strict";e.fn.form=function(t,r){var o,a=e(this),s=e.extend(!0,{},e.fn.form.settings,r),l=e.extend({},e.fn.form.settings.defaults,t),c=s.namespace,u=s.metadata,d=s.selector,f=s.className,p=(s.error,"."+c),v="module-"+c,m=a.selector||"",h=(new Date).getTime(),g=[],b=arguments[0],k="string"==typeof b,y=[].slice.call(arguments,1);return a.each(function(){var t,r=e(this),c=e(this).find(d.field),x=e(this).find(d.group),w=e(this).find(d.message),E=(e(this).find(d.prompt),e(this).find(d.submit)),C=e(this).find(d.clear),S=e(this).find(d.reset),R=[],F=!1,z=this,T=r.data(v);t={initialize:function(){t.verbose("Initializing form validation",r,l,s),t.bindEvents(),t.set.defaults(),t.instantiate()},instantiate:function(){t.verbose("Storing instance of module",t),T=t,r.data(v,t)},destroy:function(){t.verbose("Destroying previous module",T),t.removeEvents(),r.removeData(v)},refresh:function(){t.verbose("Refreshing selector cache"),c=r.find(d.field)},submit:function(){t.verbose("Submitting form",r),r.submit()},attachEvents:function(n,i){i=i||"submit",e(n).on("click",function(e){t[i](),e.preventDefault()})},bindEvents:function(){s.keyboardShortcuts&&c.on("keydown"+p,t.event.field.keydown),r.on("submit"+p,t.validate.form),c.on("blur"+p,t.event.field.blur),t.attachEvents(E,"submit"),t.attachEvents(S,"reset"),t.attachEvents(C,"clear"),c.each(function(){var n=e(this).prop("type"),i=t.get.changeEvent(n);e(this).on(i+p,t.event.field.change)})},clear:function(){c.each(function(){var n=e(this),i=n.parent(),r=n.closest(x),o=r.find(d.prompt),a=n.data(u.defaultValue)||"",s=i.is(d.uiCheckbox),l=i.is(d.uiDropdown),c=r.hasClass(f.error);c&&(t.verbose("Resetting error on field",r),r.removeClass(f.error),o.remove()),l?(t.verbose("Resetting dropdown value",i,a),i.dropdown("clear")):s?i.checkbox("uncheck"):(t.verbose("Resetting field value",n,a),n.val(""))})},reset:function(){c.each(function(){var n=e(this),i=n.parent(),r=n.closest(x),o=r.find(d.prompt),a=n.data(u.defaultValue)||"",s=i.is(d.uiCheckbox),l=i.is(d.uiDropdown),c=r.hasClass(f.error);c&&(t.verbose("Resetting error on field",r),r.removeClass(f.error),o.remove()),l?(t.verbose("Resetting dropdown value",i,a),i.dropdown("restore defaults")):s?(t.verbose("Resetting checkbox value",i,a),i.checkbox(a===!0?"check":"uncheck")):(t.verbose("Resetting field value",n,a),n.val(a))})},removeEvents:function(){r.off(p),c.off(p),E.off(p),c.off(p)},event:{field:{keydown:function(n){var i=e(this),r=n.which,o={enter:13,escape:27};r==o.escape&&(t.verbose("Escape key pressed blurring field"),i.blur()),!n.ctrlKey&&r==o.enter&&i.is(d.input)&&i.not(d.checkbox).length>0&&(E.addClass(f.pressed),F||(i.one("keyup"+p,t.event.field.keyup),t.submit(),t.debug("Enter pressed on input submitting form")),F=!0)},keyup:function(){F=!1,E.removeClass(f.pressed)},blur:function(){var n=e(this),i=n.closest(x);i.hasClass(f.error)?(t.debug("Revalidating field",n,t.get.validation(n)),t.validate.field(t.get.validation(n))):("blur"==s.on||"change"==s.on)&&t.validate.field(t.get.validation(n))},change:function(){var n=e(this),i=n.closest(x);("change"==s.on||i.hasClass(f.error)&&s.revalidate)&&(clearTimeout(t.timer),t.timer=setTimeout(function(){t.debug("Revalidating field",n,t.get.validation(n)),t.validate.field(t.get.validation(n))},s.delay))}}},get:{changeEvent:function(e){return"checkbox"==e||"radio"==e||"hidden"==e?"change":t.get.inputEvent()},inputEvent:function(){return n.createElement("input").oninput!==i?"input":n.createElement("input").onpropertychange!==i?"propertychange":"keyup"},field:function(n){return t.verbose("Finding field with identifier",n),c.filter("#"+n).length>0?c.filter("#"+n):c.filter('[name="'+n+'"]').length>0?c.filter('[name="'+n+'"]'):c.filter('[name="'+n+'[]"]').length>0?c.filter('[name="'+n+'[]"]'):c.filter("[data-"+u.validate+'="'+n+'"]').length>0?c.filter("[data-"+u.validate+'="'+n+'"]'):e("<input/>")},fields:function(n){var i=e();return e.each(n,function(e,n){i=i.add(t.get.field(n))}),i},validation:function(n){var i;return e.each(l,function(e,r){t.get.field(r.identifier).get(0)==n.get(0)&&(
|