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