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

11 lines
28 KiB
JavaScript
Raw Permalink Normal View History

2022-01-13 13:00:31 +00:00
/*
* # Fomantic UI - 2.9.3
2022-01-13 13:00:31 +00:00
* https://github.com/fomantic/Fomantic-UI
2023-08-17 09:47:40 +00:00
* https://fomantic-ui.com/
2022-01-13 13:00:31 +00:00
*
2023-08-17 09:47:40 +00:00
* Copyright 2023 Contributors
2022-01-13 13:00:31 +00:00
* Released under the MIT license
2023-08-17 09:47:40 +00:00
* https://opensource.org/licenses/MIT
2022-01-13 13:00:31 +00:00
*
*/
!function(j,z,$){"use strict";function I(e){return"function"==typeof e&&"number"!=typeof e.nodeType}z=void 0!==z&&z.Math===Math?z:globalThis,j.fn.form=function(V){var A,D=j(this),F=j(z),R=Date.now(),S=[],T=V,L="string"==typeof T,O=[].slice.call(arguments,1);return D.each(function(){var i,f,e,t,m,c,g,p,h,n,u,r,a,l,o,s,d,v=j(this),b=this,y=[],x=!1,k=!1,E=!1,C=["clean","clean"],w={initialize:function(){w.get.settings(),v.addClass(h.initial),L?(void 0===d&&w.instantiate(),w.invoke(T)):(void 0!==d&&(d.invoke("destroy"),w.refresh()),w.verbose("Initializing form validation",v,m),w.bindEvents(),w.set.defaults(),m.autoCheckRequired&&w.set.autoCheck(),w.instantiate())},instantiate:function(){w.verbose("Storing instance of module",w),d=w,v.data(a,w)},destroy:function(){w.verbose("Destroying previous module",d),w.removeEvents(),v.removeData(a)},refresh:function(){w.verbose("Refreshing selector cache"),i=v.find(p.field),f=v.find(p.group),e=v.find(p.message),v.find(p.prompt),t=v.find(p.submit),v.find(p.clear),v.find(p.reset)},refreshEvents:function(){w.removeEvents(),w.bindEvents()},submit:function(e){w.verbose("Submitting form",v),k=!0,v.trigger("submit"),e&&e.preventDefault()},attachEvents:function(e,t){t=t||"submit",j(e).on("click"+l,function(e){w[t](),e.preventDefault()}),o=e,s=t},bindEvents:function(){w.verbose("Attaching form events"),v.on("submit"+l,w.validate.form).on("blur"+l,p.field,w.event.field.blur).on("click"+l,p.submit,w.submit).on("click"+l,p.reset,w.reset).on("click"+l,p.clear,w.clear),i.on("invalid"+l,w.event.field.invalid),m.keyboardShortcuts&&v.on("keydown"+l,p.field,w.event.field.keydown),i.each(function(e,t){var t=j(t),n=t.prop("type"),n=w.get.changeEvent(n,t);t.on(n+l,w.event.field.change)}),m.preventLeaving&&F.on("beforeunload"+l,w.event.beforeUnload),i.on("change"+l+" click"+l+" keyup"+l+" keydown"+l+" blur"+l,function(e){w.determine.isDirty()}),v.on("dirty"+l,function(e){m.onDirty.call()}),v.on("clean"+l,function(e){m.onClean.call()}),o&&w.attachEvents(o,s)},clear:function(){i.each(function(e,t){var t=j(t),n=t.parent(),r=t.closest(f),i=r.find(p.prompt),a=t.closest(p.uiCalendar),o=t.data(g.defaultValue)||"",l=t.is(p.checkbox),s=n.is(p.uiDropdown)&&w.can.useElement("dropdown"),u=0<a.length&&w.can.useElement("calendar");r.hasClass(h.error)&&(w.verbose("Resetting error on field",r),r.removeClass(h.error),i.remove()),s?(w.verbose("Resetting dropdown value",n,o),n.dropdown("clear",!0)):l?t.prop("checked",!1):u?a.calendar("clear"):(w.verbose("Resetting field value",t,o),t.val(""))}),w.remove.states()},reset:function(){i.each(function(e,t){var t=j(t),n=t.parent(),r=t.closest(f),i=t.closest(p.uiCalendar),a=r.find(p.prompt),o=t.data(g.defaultValue),l=t.is(p.checkbox),s=n.is(p.uiDropdown)&&w.can.useElement("dropdown"),u=0<i.length&&w.can.useElement("calendar"),c=t.is(p.file),d=r.hasClass(h.error);void 0!==o&&(d&&(w.verbose("Resetting error on field",r),r.removeClass(h.error),a.remove()),s?(w.verbose("Resetting dropdown value",n,o),n.dropdown("restore defaults",!0)):l?(w.verbose("Resetting checkbox value",t,o),t.prop("checked",o)):u?i.calendar("set date",o):(w.verbose("Resetting field value",t,o),t.val(c?"":o)))}),w.remove.states()},determine:{isValid:function(){var r=!0;return i.each(function(e,t){var t=j(t),n=w.get.validation(t)||{},t=w.get.identifier(n,t);w.validate.field(n,t,!0)||(r=!1)}),r},isDirty:function(e){var r=!1;i.each(function(e,t){var t=j(t),n=0<t.filter(p.checkbox).length?w.is.checkboxDirty(t):w.is.fieldDirty(t);t.data(m.metadata.isDirty,n),r=r||n}),r?w.set.dirty():w.set.clean()}},is:{bracketedRule:function(e){return e.type&&e.type.match(m.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"):w.is.blank(e))},blank:function(e){return""===String(e.val()).trim()},valid:function(e,n){var r=!0;return e?(w.verbose("Checking if field is valid",e),w.validate.field(c[e],e,!!n)):(w.verbose("Checking if form is valid"),j.each(c,function(e,t){w.is.valid(e,n)||(r=!1)}),r)},dirty:function(){return E},clean:fu