11 lines
26 KiB
JavaScript
11 lines
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,u,i,a,l,c,h=$(this),v=this,b=[],y=!1,o=!1,x=!1,k=["clean","clean"],E={initialize:function(){E.get.settings(),T?(c===L&&E.instantiate(),E.invoke(R)):(c!==L&&(c.invoke("destroy"),E.refresh()),E.verbose("Initializing form validation",h,f),E.bindEvents(),E.set.defaults(),f.autoCheckRequired&&E.set.autoCheck(),E.instantiate())},instantiate:function(){E.verbose("Storing instance of module",E),c=E,h.data(a,E)},destroy:function(){E.verbose("Destroying previous module",c),E.removeEvents(),h.removeData(a)},refresh:function(){E.verbose("Refreshing selector cache"),n=h.find(p.field),d=h.find(p.group),t=h.find(p.message),h.find(p.prompt),e=h.find(p.submit),h.find(p.clear),h.find(p.reset)},submit:function(){E.verbose("Submitting form",h),o=!0,h.submit()},attachEvents:function(e,t){t=t||"submit",$(e).on("click"+l,function(e){E[t](),e.preventDefault()})},bindEvents:function(){E.verbose("Attaching form events"),h.on("submit"+l,E.validate.form).on("blur"+l,p.field,E.event.field.blur).on("click"+l,p.submit,E.submit).on("click"+l,p.reset,E.reset).on("click"+l,p.clear,E.clear),f.keyboardShortcuts&&h.on("keydown"+l,p.field,E.event.field.keydown),n.each(function(e,t){var n=$(t),t=n.prop("type"),t=E.get.changeEvent(t,n);n.on(t+l,E.event.field.change)}),f.preventLeaving&&$(I).on("beforeunload"+l,E.event.beforeUnload),n.on("change click keyup keydown blur",function(e){E.determine.isDirty()}),h.on("dirty"+l,function(e){f.onDirty.call()}),h.on("clean"+l,function(e){f.onClean.call()})},clear:function(){n.each(function(e,t){var n=$(t),r=n.parent(),i=n.closest(d),a=i.find(p.prompt),o=n.closest(p.uiCalendar),l=n.data(m.defaultValue)||"",s=r.is(p.uiCheckbox),u=r.is(p.uiDropdown)&&E.can.useElement("dropdown"),t=0<o.length&&E.can.useElement("calendar");i.hasClass(g.error)&&(E.verbose("Resetting error on field",i),i.removeClass(g.error),a.remove()),u?(E.verbose("Resetting dropdown value",r,l),r.dropdown("clear",!0)):s?n.prop("checked",!1):t?o.calendar("clear"):(E.verbose("Resetting field value",n,l),n.val(""))}),E.remove.states()},reset:function(){n.each(function(e,t){var n=$(t),r=n.parent(),i=n.closest(d),a=n.closest(p.uiCalendar),o=i.find(p.prompt),l=n.data(m.defaultValue),s=r.is(p.uiCheckbox),u=r.is(p.uiDropdown)&&E.can.useElement("dropdown"),c=0<a.length&&E.can.useElement("calendar"),t=i.hasClass(g.error);l!==L&&(t&&(E.verbose("Resetting error on field",i),i.removeClass(g.error),o.remove()),u?(E.verbose("Resetting dropdown value",r,l),r.dropdown("restore defaults",!0)):s?(E.verbose("Resetting checkbox value",r,l),n.prop("checked",l)):c?a.calendar("set date",l):(E.verbose("Resetting field value",n,l),n.val(l)))}),E.remove.states()},determine:{isValid:function(){var n=!0;return $.each(s,function(e,t){E.validate.field(t,e,!0)||(n=!1)}),n},isDirty:function(e){var r=!1;n.each(function(e,t){var n=$(t),t=0<n.filter(p.checkbox).length?E.is.checkboxDirty(n):E.is.fieldDirty(n);n.data(f.metadata.isDirty,t),r|=t}),r?E.set.dirty():E.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"):E.is.blank(e))},blank:function(e){return""===String(e.val()).trim()},valid:function(e,n){var r=!0;return e?(E.verbose("Checking if field is valid",e),E.validate.field(s[e],e,!!n)):(E.verbose("Checking if form is valid"),$.each(s,function(e,t){E.is.valid(e,n)||(r=!1)}),r)},dirty:function(){return x},clean:function(){return!x},fieldDirty:function(e){var t=e.data(m.defaultValue);null==t?t="":Array.isArray(t)&&(t=t.toString());var n=e.val();null==n?n="":Array.isArray(n)&&(n=n.toStr
|