in packages/element/src/form/index.ts [27:95]
setup(props, { attrs, slots, listeners }) {
const top = useForm()
return () => {
const {
form,
component = 'form',
onAutoSubmit = listeners?.autoSubmit,
onAutoSubmitFailed = listeners?.autoSubmitFailed,
previewTextPlaceholder = slots?.previewTextPlaceholder,
} = props
const renderContent = (form: FormType) => {
return h(
PreviewText.Placeholder,
{
props: {
value: previewTextPlaceholder,
},
},
{
default: () => [
h(
FormLayout,
{
attrs: {
...attrs,
},
},
{
default: () => [
h(
component,
{
on: {
submit: (e: Event) => {
e?.stopPropagation?.()
e?.preventDefault?.()
form
.submit(onAutoSubmit as (e: any) => void)
.catch(onAutoSubmitFailed as (e: any) => void)
},
},
},
slots
),
],
}
),
],
}
)
}
if (form) {
return h(
FormProvider,
{ props: { form } },
{
default: () => renderContent(form),
}
)
}
if (!top.value) throw new Error('must pass form instance by createForm')
return renderContent(top.value)
}
},