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