@tarojs/components
Version:
1 lines • 3.33 kB
JavaScript
import{r as registerInstance,c as createEvent,h,g as getElement}from"./index-ab3c86da.js";var __classPrivateFieldSet=undefined&&undefined.__classPrivateFieldSet||function(e,t,r,i,n){if(i==="m")throw new TypeError("Private method is not writable");if(i==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof t==="function"?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return i==="a"?n.call(e,r):n?n.value=r:t.set(e,r),r};var __classPrivateFieldGet=undefined&&undefined.__classPrivateFieldGet||function(e,t,r,i){if(r==="a"&&!i)throw new TypeError("Private accessor was defined without a getter");if(typeof t==="function"?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?i:r==="a"?i.call(e):i?i.value:t.get(e)};var _Form_value;var Form=function(){function e(e){registerInstance(this,e);this.onSubmit=createEvent(this,"submit",7);_Form_value.set(this,{})}e.prototype.onButtonSubmit=function(e){e.stopPropagation();__classPrivateFieldSet(this,_Form_value,this.getFormValue(),"f");this.onSubmit.emit({value:__classPrivateFieldGet(this,_Form_value,"f")})};e.prototype.onButtonReset=function(e){e.stopPropagation();this.form.reset()};e.prototype.componentDidLoad=function(){var e=this;__classPrivateFieldSet(this,_Form_value,this.getFormValue(),"f");Object.defineProperty(this.el,"value",{get:function(){return __classPrivateFieldGet(e,_Form_value,"f")},configurable:true})};e.prototype.componentDidRender=function(){var e=this;if(!this.originalAppendChild){this.originalAppendChild=this.el.appendChild;this.originalInsertBefore=this.el.insertBefore;this.originalReplaceChild=this.el.replaceChild;this.originalRemoveChild=this.el.removeChild}if(!this.form){this.el.appendChild=this.originalAppendChild;this.el.insertBefore=this.originalInsertBefore;this.el.replaceChild=this.originalReplaceChild;this.el.removeChild=this.originalRemoveChild;return}this.el.appendChild=function(t){return e.form.appendChild(t)};this.el.insertBefore=function(t,r){return e.form.insertBefore(t,r)};this.el.replaceChild=function(t,r){return e.form.replaceChild(t,r)};this.el.removeChild=function(t){return e.form.removeChild(t)}};e.prototype.getFormValue=function(){var e=this.el;var t=[];var r=e.getElementsByTagName("input");for(var i=0;i<r.length;i++){t.push(r[i])}var n={};var a={};t.forEach((function(e){if(typeof e.name!=="string")return;if(e.className.indexOf("weui-switch")!==-1){n[e.name]=e.checked;return}if(e.type==="radio"){if(e.checked){a[e.name]=true;n[e.name]=e.value}else{if(!a[e.name]){n[e.name]=""}}return}if(e.type==="checkbox"){if(e.checked){if(a[e.name]){n[e.name].push(e.value)}else{a[e.name]=true;n[e.name]=[e.value]}}else{if(!a[e.name]){n[e.name]=[]}}return}n[e.name]=e.value}));var o=e.getElementsByTagName("textarea");var l=[];for(var s=0;s<o.length;s++){l.push(o[s])}l.forEach((function(e){if(typeof e.name!=="string")return;n[e.name]=e.value}));return n};e.prototype.render=function(){var e=this;return h("form",{ref:function(t){e.form=t}},h("slot",null))};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});return e}();_Form_value=new WeakMap;export{Form as taro_form_core};