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