UNPKG

1.87 kBJavaScriptView Raw
1import{r as t,c as s,h as i,g as h}from"./p-059912fd.js";let e=class{constructor(i){t(this,i),this.onSubmit=s(this,"submit",7),this.value={}}watchSlotParent(t){if(this.orginalAppendChild||(this.orginalAppendChild=this.el.appendChild,this.orginalInsertBefore=this.el.insertBefore,this.orginalReplaceChild=this.el.replaceChild,this.orginalRemoveChild=this.el.removeChild),!t)return this.el.appendChild=this.orginalAppendChild,this.el.insertBefore=this.orginalInsertBefore,this.el.replaceChild=this.orginalReplaceChild,void(this.el.removeChild=this.orginalRemoveChild);this.el.appendChild=s=>t.appendChild(s),this.el.insertBefore=(s,i)=>t.insertBefore(s,i),this.el.replaceChild=(s,i)=>t.replaceChild(s,i),this.el.removeChild=s=>t.removeChild(s)}onButtonSubmit(t){t.stopPropagation(),this.value=this.getFormValue(),this.onSubmit.emit({value:this.value})}onButtonReset(t){t.stopPropagation(),this.form.reset()}componentDidLoad(){this.value=this.getFormValue(),Object.defineProperty(this.el,"value",{get:()=>this.value,configurable:!0})}componentDidRender(){this.setSlotParent(this.form)}getFormValue(){const t=this.el,s=[],i=t.getElementsByTagName("input");for(let t=0;t<i.length;t++)s.push(i[t]);const h={},e={};s.forEach((t=>{-1===t.className.indexOf("weui-switch")?"radio"!==t.type?"checkbox"!==t.type?h[t.name]=t.value:t.checked?e[t.name]?h[t.name].push(t.value):(e[t.name]=!0,h[t.name]=[t.value]):e[t.name]||(h[t.name]=[]):t.checked?(e[t.name]=!0,h[t.name]=t.value):e[t.name]||(h[t.name]=""):h[t.name]=t.checked}));const r=t.getElementsByTagName("textarea"),o=[];for(let t=0;t<r.length;t++)o.push(r[t]);return o.forEach((t=>{h[t.name]=t.value})),h}setSlotParent(t){this.slotParent=t}render(){return i("form",{ref:t=>{t&&(this.form=t)}},i("slot",null))}get el(){return h(this)}static get watchers(){return{slotParent:["watchSlotParent"]}}};export{e as taro_form_core}
\No newline at end of file