wishthis/node_modules/fomantic-ui/dist/components/form.min.js

11 lines
26 KiB
JavaScript
Raw Normal View History

2022-01-13 13:00:31 +00:00
/*
2022-04-07 07:06:43 +00:00
* # Fomantic UI - 2.9.0-beta.274+23f6671
2022-01-13 13:00:31 +00:00
* https://github.com/fomantic/Fomantic-UI
* http://fomantic-ui.com/
*
2022-04-07 07:06:43 +00:00
* Copyright 2022 Contributors
2022-01-13 13:00:31 +00:00
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
2022-04-07 07:06:43 +00:00
!function(O,$,I,L){"use strict";O.isFunction=O.isFunction||function(e){return"function"==typeof e&&"number"!=typeof e.nodeType},$=void 0!==$&&$.Math==Math?$:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),O.fn.form=function(C){var w,V=O(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=O(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)},refreshEvents:function(){E.removeEvents(),E.bindEvents()},submit:function(){E.verbose("Submitting form",h),o=!0,h.submit()},attachEvents:function(e,t){t=t||"submit",O(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 t=O(t),n=t.prop("type"),n=E.get.changeEvent(n,t);t.on(n+l,E.event.field.change)}),f.preventLeaving&&O($).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 t=O(t),n=t.parent(),r=t.closest(d),i=r.find(p.prompt),a=t.closest(p.uiCalendar),o=t.data(m.defaultValue)||"",l=n.is(p.uiCheckbox),s=n.is(p.uiDropdown)&&E.can.useElement("dropdown"),u=0<a.length&&E.can.useElement("calendar");r.hasClass(g.error)&&(E.verbose("Resetting error on field",r),r.removeClass(g.error),i.remove()),s?(E.verbose("Resetting dropdown value",n,o),n.dropdown("clear",!0)):l?t.prop("checked",!1):u?a.calendar("clear"):(E.verbose("Resetting field value",t,o),t.val(""))}),E.remove.states()},reset:function(){n.each(function(e,t){var t=O(t),n=t.parent(),r=t.closest(d),i=t.closest(p.uiCalendar),a=r.find(p.prompt),o=t.data(m.defaultValue),l=n.is(p.uiCheckbox),s=n.is(p.uiDropdown)&&E.can.useElement("dropdown"),u=0<i.length&&E.can.useElement("calendar"),c=r.hasClass(g.error);o!==L&&(c&&(E.verbose("Resetting error on field",r),r.removeClass(g.error),a.remove()),s?(E.verbose("Resetting dropdown value",n,o),n.dropdown("restore defaults",!0)):l?(E.verbose("Resetting checkbox value",n,o),t.prop("checked",o)):u?i.calendar("set date",o):(E.verbose("Resetting field value",t,o),t.val(o)))}),E.remove.states()},determine:{isValid:function(){var n=!0;return O.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 t=O(t),n=0<t.filter(p.checkbox).length?E.is.checkboxDirty(t):E.is.fieldDirty(t);t.data(f.metadata.isDirty,n),r|=n}),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"),O.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),e=(null==t?t="":Array.isArray(t)&&(t=t.toStri