Form
A composite wrapper built from FormProvider, FormLayout, and a native
formtag. It helps you assemble forms quickly while preserving Enter-to-submit behavior and centralized layout control.
Note
The component prop has been renamed to tag and moved to the FormLayout component.
Form Example
<script>
import { createForm } from '@silver-formily/core'
import {
Form,
FormButtonGroup,
FormItem,
Input,
Select,
Submit,
} from '@silver-formily/element-plus'
import { createSchemaField } from '@silver-formily/vue'
const form = createForm()
const fields = createSchemaField({ components: { Input, Select, FormItem } })
export default {
// eslint-disable-next-line vue/no-reserved-component-names
components: { FormButtonGroup, Submit, Form, ...fields },
data() {
return {
form,
}
},
methods: {
log(value) {
console.log(value)
return new Promise((resolve) => {
setTimeout(() => {
console.log('mock request success')
resolve(value)
}, 5000)
})
},
},
}
</script>
<template>
<Form
:form="form"
:label-col="6"
:wrapper-col="10"
@auto-submit="log"
@auto-submit-failed="log('failed')"
>
<SchemaField>
<SchemaStringField
name="input"
title="Input"
x-decorator="FormItem"
x-component="Input"
:x-validator="[{ min: 5 }, { format: 'url' }]"
:required="true"
/>
<SchemaStringField
name="select"
title="Select"
x-decorator="FormItem"
x-component="Select"
:x-validator="[{ min: 2 }]"
:enum="[
{ label: 'Option One', value: 'one' },
{ label: 'Option Two', value: 'two' },
{ label: 'Option Three', value: 'three' },
]"
:required="true"
/>
</SchemaField>
<FormButtonGroup align-form-item>
<Submit>Submit</Submit>
</FormButtonGroup>
</Form>
</template>查看源码
Note: If you want Enter-to-submit behavior, do not attach a
submithandler directly to the Submit component. Doing so bypasses the Form-level auto-submit flow. This constraint prevents submit logic from being scattered across multiple places and becoming inconsistent or hard to debug.
API
Most props are inherited from FormLayout. The following are the extra props exposed by the Form component.
| Prop | Type | Description | Default |
|---|---|---|---|
form | Form | Form instance | - |
previewTextPlaceholder | string | Placeholder shown in read-pretty mode | N/A |
onAutoSubmit | (values: any) => any | Callback triggered by Enter-to-submit | - |
onAutoSubmitFailed | (feedbacks) => void | Validation failure callback for Enter-to-submit | - |