wishthis/semantic/dist/components/form.min.js

11 lines
27 KiB
JavaScript
Raw Normal View History

2022-01-13 13:00:31 +00:00
/*
2023-08-17 09:47:40 +00:00
* # Fomantic UI - 2.9.2
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
*
*/
2023-08-17 09:47:40 +00:00
!function(j,O,L){"use strict";function z(e){return"function"==typeof e&&"number"!=typeof e.nodeType}O=void 0!==O&&O.Math===Math?O:globalThis,j.fn.form=function(C){var w,V=j(this),A=V.selector||"",D=Date.now(),R=[],S=C,F="string"==typeof S,T=[].slice.call(arguments,1);return V.each(function(){var i,d,e,t,f,s,m,p,g,n,u,r,a,l,c,o=j(this),h=this,v=[],b=!1,y=!1,x=!1,k=["clean","clean"],E={initialize:function(){E.get.settings(),F?(void 0===c&&E.instantiate(),E.invoke(S)):(void 0!==c&&(c.invoke("destroy"),E.refresh()),E.verbose("Initializing form validation",o,f),E.bindEvents(),E.set.defaults(),f.autoCheckRequired&&E.set.autoCheck(),E.instantiate())},instantiate:function(){E.verbose("Storing instance of module",E),c=E,o.data(a,E)},destroy:function(){E.verbose("Destroying previous module",c),E.removeEvents(),o.removeData(a)},refresh:function(){E.verbose("Refreshing selector cache"),i=o.find(p.field),d=o.find(p.group),e=o.find(p.message),o.find(p.prompt),t=o.find(p.submit),o.find(p.clear),o.find(p.reset)},refreshEvents:function(){E.removeEvents(),E.bindEvents()},submit:function(){E.verbose("Submitting form",o),y=!0,o.trigger("submit")},attachEvents:function(e,t){t=t||"submit",j(e).on("click"+l,function(e){E[t](),e.preventDefault()})},bindEvents:function(){E.verbose("Attaching form events"),o.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&&o.on("keydown"+l,p.field,E.event.field.keydown),i.each(function(e,t){var t=j(t),n=t.prop("type"),n=E.get.changeEvent(n,t);t.on(n+l,E.event.field.change)}),f.preventLeaving&&j(O).on("beforeunload"+l,E.event.beforeUnload),i.on("change click keyup keydown blur",function(e){E.determine.isDirty()}),o.on("dirty"+l,function(e){f.onDirty.call()}),o.on("clean"+l,function(e){f.onClean.call()})},clear:function(){i.each(function(e,t){var t=j(t),n=t.parent(),r=t.closest(d),i=r.find(p.prompt),a=t.closest(p.uiCalendar),o=t.data(m.defaultValue)||"",l=t.is(p.checkbox),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(){i.each(function(e,t){var t=j(t),n=t.parent(),r=t.closest(d),i=t.closest(p.uiCalendar),a=r.find(p.prompt),o=t.data(m.defaultValue),l=t.is(p.checkbox),s=n.is(p.uiDropdown)&&E.can.useElement("dropdown"),u=0<i.length&&E.can.useElement("calendar"),c=r.hasClass(g.error);void 0!==o&&(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",t,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 j.each(s,function(e,t){E.validate.field(t,e,!0)||(n=!1)}),n},isDirty:function(e){var r=!1;i.each(function(e,t){var t=j(t),n=0<t.filter(p.checkbox).length?E.is.checkboxDirty(t):E.is.fieldDirty(t);t.data(f.metadata.isDirty,n),r=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"),j.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.toString()),e.val()),n=(null==e?e="":Array.isArray(e)&&(e=e.toString()),/^(true|false)$/i);return