You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
1.7 KiB

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