|
|
/*! * # Semantic UI 2.0.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){var r,o=e(this),a=o.selector||"",s=(new Date).getTime(),l=[],c=arguments[0],u=arguments[1],d="string"==typeof c,f=[].slice.call(arguments,1);return o.each(function(){var p,g,m,v,h,b,y,k,x,w,C,E,S,R,w,A,F,O,T,z=e(this),D=this,j=[],V=!1;T={initialize:function(){T.get.settings(),d?T.invoke(c):(T.verbose("Initializing form validation",z,k),T.bindEvents(),T.set.defaults(),T.instantiate())},instantiate:function(){T.verbose("Storing instance of module",T),O=T,z.data(A,T)},destroy:function(){T.verbose("Destroying previous module",O),T.removeEvents(),z.removeData(A)},refresh:function(){T.verbose("Refreshing selector cache"),p=z.find(E.field),g=z.find(E.group),m=z.find(E.message),v=z.find(E.prompt),h=z.find(E.submit),b=z.find(E.clear),y=z.find(E.reset)},submit:function(){T.verbose("Submitting form",z),z.submit()},attachEvents:function(t,n){n=n||"submit",e(t).on("click"+F,function(e){T[n](),e.preventDefault()})},bindEvents:function(){T.verbose("Attaching form events"),k.keyboardShortcuts&&p.on("keydown"+F,T.event.field.keydown),z.on("submit"+F,T.validate.form),p.on("blur"+F,T.event.field.blur),T.attachEvents(h,"submit"),T.attachEvents(y,"reset"),T.attachEvents(b,"clear"),p.each(function(){var t=e(this),n=t.prop("type"),i=T.get.changeEvent(n,t);e(this).on(i+F,T.event.field.change)})},clear:function(){p.each(function(){var t=e(this),n=t.parent(),i=t.closest(g),r=i.find(E.prompt),o=t.data(C.defaultValue)||"",a=n.is(E.uiCheckbox),s=n.is(E.uiDropdown),l=i.hasClass(S.error);l&&(T.verbose("Resetting error on field",i),i.removeClass(S.error),r.remove()),s?(T.verbose("Resetting dropdown value",n,o),n.dropdown("clear")):a?n.checkbox("uncheck"):(T.verbose("Resetting field value",t,o),t.val(""))})},reset:function(){p.each(function(){var t=e(this),n=t.parent(),i=t.closest(g),r=i.find(E.prompt),o=t.data(C.defaultValue)||"",a=n.is(E.uiCheckbox),s=n.is(E.uiDropdown),l=i.hasClass(S.error);l&&(T.verbose("Resetting error on field",i),i.removeClass(S.error),r.remove()),s?(T.verbose("Resetting dropdown value",n,o),n.dropdown("restore defaults")):a?(T.verbose("Resetting checkbox value",n,o),n.checkbox(o===!0?"check":"uncheck")):(T.verbose("Resetting field value",t,o),t.val(o))})},removeEvents:function(){z.off(F),p.off(F),h.off(F),p.off(F)},event:{field:{keydown:function(t){var n=e(this),i=t.which,r={enter:13,escape:27};i==r.escape&&(T.verbose("Escape key pressed blurring field"),n.blur()),!t.ctrlKey&&i==r.enter&&n.is(E.input)&&n.not(E.checkbox).length>0&&(h.addClass(S.pressed),V||(n.one("keyup"+F,T.event.field.keyup),T.submit(),T.debug("Enter pressed on input submitting form")),V=!0)},keyup:function(){V=!1,h.removeClass(S.pressed)},blur:function(){var t=e(this),n=t.closest(g);n.hasClass(S.error)?(T.debug("Revalidating field",t,T.get.validation(t)),T.validate.field(T.get.validation(t))):("blur"==k.on||"change"==k.on)&&T.validate.field(T.get.validation(t))},change:function(){var t=e(this),n=t.closest(g);("change"==k.on||n.hasClass(S.error)&&k.revalidate)&&(clearTimeout(T.timer),T.timer=setTimeout(function(){T.debug("Revalidating field",t,T.get.validation(t)),T.validate.field(T.get.validation(t))},k.delay))}}},get:{changeEvent:function(e,t){return"checkbox"==e||"radio"==e||"hidden"==e||t.is("select")?"change":T.get.inputEvent()},inputEvent:function(){return n.createElement("input").oninput!==i?"input":n.createElement("input").onpropertychange!==i?"propertychange":"keyup"},settings:function(){if(e.isPlainObject(t)){var n=Object.keys(t),r=n.length>0?t[n[0]].identifier!==i:!1;r?(k=e.extend(!0,{},e.fn.form.settings,u),x=e.extend({},e.fn.form.settings.defaults,t),T.error(k.error.oldSyntax,D),T.verbose("Extending settings from legacy parameters",x,k)):(k=e.extend(!0,{},e.fn.form.settings,t),x=e.extend({},e.fn.form.settings.defaults,k.fields),T.verbose("Extending settings",x,k))}else k=e.fn.form.settings,x=e.fn.form.settings.defaults,T.verbose("Using default form validation",x,k);w=k.namespace,C=k.metadata,E=k.selector,S=k.className,R=k.error,A="module-"+w,F="."+w,O=z.data(A),T.refresh()},field:function(t){re
|