1 |
- import{x as S,y as V,z as h,W as y,d as A,ae as T,aJ as x,af as C,i as M,al as N,K as _}from"./index.7bb55078.js";const[k,I]=S("form"),K={colon:Boolean,disabled:Boolean,readonly:Boolean,showError:Boolean,labelWidth:V,labelAlign:String,inputAlign:String,scrollToError:Boolean,validateFirst:Boolean,submitOnEnter:h,validateTrigger:y("onBlur"),showErrorMessage:h,errorMessageAlign:String};var O=A({name:k,props:K,emits:["submit","failed"],setup(i,{emit:r,slots:c}){const{children:s,linkChildren:g}=T(x),o=e=>e?s.filter(t=>e.includes(t.name)):s,v=e=>new Promise((t,n)=>{const a=[];o(e).reduce((F,w)=>F.then(()=>{if(!a.length)return w.validate().then(m=>{m&&a.push(m)})}),Promise.resolve()).then(()=>{a.length?n(a):t()})}),p=e=>new Promise((t,n)=>{const a=o(e);Promise.all(a.map(l=>l.validate())).then(l=>{l=l.filter(Boolean),l.length?n(l):t()})}),b=e=>{const t=s.find(n=>n.name===e);return t?new Promise((n,a)=>{t.validate().then(l=>{l?a(l):n()})}):Promise.reject()},d=e=>typeof e=="string"?b(e):i.validateFirst?v(e):p(e),P=e=>{typeof e=="string"&&(e=[e]),o(e).forEach(n=>{n.resetValidation()})},u=(e,t)=>{s.some(n=>n.name===e?(n.$el.scrollIntoView(t),!0):!1)},B=()=>s.reduce((e,t)=>(e[t.name]=t.formValue.value,e),{}),f=()=>{const e=B();d().then(()=>r("submit",e)).catch(t=>{r("failed",{values:e,errors:t}),i.scrollToError&&t[0].name&&u(t[0].name)})},E=e=>{N(e),f()};return g({props:i}),C({submit:f,validate:d,scrollToField:u,resetValidation:P}),()=>{var e;return M("form",{class:I(),onSubmit:E},[(e=c.default)==null?void 0:e.call(c)])}}});const j=_(O);export{j as F};
|