Skip to content

Commit 78212c5

Browse files
committed
feat: add after-fields and before-fields slots
1 parent 41252ac commit 78212c5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

docs/content/2.customization/2.form.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ you want to provide submit or edit form feature.
2222

2323
## Slots
2424

25-
Sometimes you want to use completely different input component than specified in your zod schema.
26-
To do that you can insert custom components using slots.
25+
| Slot | Type | Description |
26+
|-----------------|---------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
27+
| `before-fields` | | Slot inside [`<UForm>`](https://ui.nuxt.com/components/form) before the list of [`<UFormField>`](https://ui.nuxt.com/components/form-field) |
28+
| `after-fields` | | Slot inside [`<UForm>`](https://ui.nuxt.com/components/form) after the list of [`<UFormField>`](https://ui.nuxt.com/components/form-field) |
29+
| `<field>` | `{ field: string, state: Ref<Record<string, any> }>`{lang=ts} | **Dynamic** slot for a specific field inside Zod schema. |
30+
31+
### Dynamic slots
32+
33+
For each field in your Zod schema, `<AutoForm>` generates a dynamic slot.
34+
You can use these slots to customize the input components for each field.
2735

2836
::code-collapse
2937
```vue [MyForm.vue]{11-25}

src/runtime/components/AutoForm.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ const submitButtonComponent = computed(() => {
136136
class="space-y-4"
137137
@submit="onSubmit"
138138
>
139+
<slot name="before-fields" />
140+
139141
<UFormField
140142
v-for="field in fields"
141143
:key="field.key"
@@ -155,6 +157,8 @@ const submitButtonComponent = computed(() => {
155157
</slot>
156158
</UFormField>
157159

160+
<slot name="after-fields" />
161+
158162
<div class="space-y-2">
159163
<div v-if="submitButtonComponent">
160164
<component :is="toRaw(submitButtonComponent)" v-bind="{ isButtonEnabled }" />

0 commit comments

Comments
 (0)