You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openpower.foundation_sw_dev/themes/openpowerfoundation/static/lib/semantic-ui/components/form.min.js

1 line
20 KiB
JavaScript

!function(e,t,n,r){"use strict";t=void 0!==t&&t.Math==Math?t:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),e.fn.form=function(t){var i,a=e(this),o=a.selector||"",l=(new Date).getTime(),s=[],u=arguments[0],c=arguments[1],d="string"==typeof u,f=[].slice.call(arguments,1);return a.each(function(){var p,m,g,h,v,b,y,x,k,E,w,C,V,R,S,F,A=e(this),T=this,D=[],O=!1;(F={initialize:function(){F.get.settings(),d?(S===r&&F.instantiate(),F.invoke(u)):(S!==r&&S.invoke("destroy"),F.verbose("Initializing form validation",A,v),F.bindEvents(),F.set.defaults(),F.instantiate())},instantiate:function(){F.verbose("Storing instance of module",F),S=F,A.data(V,F)},destroy:function(){F.verbose("Destroying previous module",S),F.removeEvents(),A.removeData(V)},refresh:function(){F.verbose("Refreshing selector cache"),p=A.find(x.field),m=A.find(x.group),g=A.find(x.message),A.find(x.prompt),h=A.find(x.submit),A.find(x.clear),A.find(x.reset)},submit:function(){F.verbose("Submitting form",A),A.submit()},attachEvents:function(t,n){n=n||"submit",e(t).on("click"+R,function(e){F[n](),e.preventDefault()})},bindEvents:function(){F.verbose("Attaching form events"),A.on("submit"+R,F.validate.form).on("blur"+R,x.field,F.event.field.blur).on("click"+R,x.submit,F.submit).on("click"+R,x.reset,F.reset).on("click"+R,x.clear,F.clear),v.keyboardShortcuts&&A.on("keydown"+R,x.field,F.event.field.keydown),p.each(function(){var t=e(this),n=t.prop("type"),r=F.get.changeEvent(n,t);e(this).on(r+R,F.event.field.change)})},clear:function(){p.each(function(){var t=e(this),n=t.parent(),r=t.closest(m),i=r.find(x.prompt),a=t.data(y.defaultValue)||"",o=n.is(x.uiCheckbox),l=n.is(x.uiDropdown);r.hasClass(k.error)&&(F.verbose("Resetting error on field",r),r.removeClass(k.error),i.remove()),l?(F.verbose("Resetting dropdown value",n,a),n.dropdown("clear")):o?t.prop("checked",!1):(F.verbose("Resetting field value",t,a),t.val(""))})},reset:function(){p.each(function(){var t=e(this),n=t.parent(),i=t.closest(m),a=i.find(x.prompt),o=t.data(y.defaultValue),l=n.is(x.uiCheckbox),s=n.is(x.uiDropdown),u=i.hasClass(k.error);o!==r&&(u&&(F.verbose("Resetting error on field",i),i.removeClass(k.error),a.remove()),s?(F.verbose("Resetting dropdown value",n,o),n.dropdown("restore defaults")):l?(F.verbose("Resetting checkbox value",n,o),t.prop("checked",o)):(F.verbose("Resetting field value",t,o),t.val(o)))})},determine:{isValid:function(){var t=!0;return e.each(b,function(e,n){F.validate.field(n,e,!0)||(t=!1)}),t}},is:{bracketedRule:function(e){return e.type&&e.type.match(v.regExp.bracket)},shorthandFields:function(e){var t=e[Object.keys(e)[0]];return F.is.shorthandRules(t)},shorthandRules:function(t){return"string"==typeof t||e.isArray(t)},empty:function(e){return!e||0===e.length||(e.is('input[type="checkbox"]')?!e.is(":checked"):F.is.blank(e))},blank:function(t){return""===e.trim(t.val())},valid:function(t){var n=!0;return t?(F.verbose("Checking if field is valid",t),F.validate.field(b[t],t,!1)):(F.verbose("Checking if form is valid"),e.each(b,function(e,t){F.is.valid(e)||(n=!1)}),n)}},removeEvents:function(){A.off(R),p.off(R),h.off(R),p.off(R)},event:{field:{keydown:function(t){var n=e(this),r=t.which,i=n.is(x.input),a=n.is(x.checkbox),o=n.closest(x.uiDropdown).length>0,l=13;r==27&&(F.verbose("Escape key pressed blurring field"),n.blur()),t.ctrlKey||r!=l||!i||o||a||(O||(n.one("keyup"+R,F.event.field.keyup),F.submit(),F.debug("Enter pressed on input submitting form")),O=!0)},keyup:function(){O=!1},blur:function(t){var n=e(this),r=n.closest(m),i=F.get.validation(n);r.hasClass(k.error)?(F.debug("Revalidating field",n,i),i&&F.validate.field(i)):"blur"==v.on&&i&&F.validate.field(i)},change:function(t){var n=e(this),r=n.closest(m),i=F.get.validation(n);i&&("change"==v.on||r.hasClass(k.error)&&v.revalidate)&&(clearTimeout(F.timer),F.timer=setTimeout(function(){F.debug("Revalidating field",n,F.get.validation(n)),F.validate.field(i)},v.delay))}}},get:{ancillaryValue:function(e){return!(!e.type||!e.value&&!F.is.bracketedRule(e))&&(e.value!==r?e.value:e.type.match(v.regExp.bracket)[1]+"