Skip to content

Slots and Children ​

Introduction ​

The Form component renders fields automatically from the PHP configuration. In Vue, it exposes named slots to replace a field, insert content around a field, and insert content around a fieldset. In React, it renders children after the generated fieldsets and accepts a structured slots render map to insert content around fields and fieldsets.

Default Slot ​

Content in the Vue default slot or in React children renders after all fieldsets:

vue
<Form :form="form">
    <template #default="{ form }">
        <p v-if="form.isDirty.value" class="text-sm text-iui-form-warning">
            You have unsaved changes.
        </p>
    </template>
</Form>
tsx
<Form form={form}>
    {(formInstance) => (
        formInstance.isDirty ? (
            <p className="text-iui-form-warning text-sm">
                You have unsaved changes.
            </p>
        ) : null
    )}
</Form>

The slot prop, or the argument of the React render function, is the return value of useForm. It gives you access to form.data, form.errors, form.processing, form.submit(), and everything documented in Manual Usage.

Adding Content Around the Form ​

Because the default slot renders after the fieldsets, you may combine it with wrapper markup to add headers, footers, or other surrounding content:

vue
<div>
    <h2 class="text-xl font-bold mb-4">Create User</h2>

    <Form :form="form">
        <template #default="{ form }">
            <div class="flex justify-between items-center mt-6 pt-6 border-t">
                <p class="text-sm text-iui-form-muted-foreground">
                    All fields marked with * are required.
                </p>
            </div>
        </template>
    </Form>
</div>
tsx
<div>
    <h2 className="mb-4 text-xl font-bold">Create User</h2>

    <Form form={form}>
        <div className="mt-6 flex items-center justify-between border-t pt-6">
            <p className="text-iui-form-muted-foreground text-sm">
                All fields marked with * are required.
            </p>
        </div>
    </Form>
</div>

Replacing Field Rendering ​

To replace one auto-rendered field in Vue while keeping the order defined in PHP, use a named slot that matches the field name plus -field:

vue
<Form :form="form">
    <template #email-field="{ field, value, error, setValue }">
        <div>
            <label class="mb-1 block text-sm font-medium">
                {{ field.label }}
            </label>

            <input
                class="block w-full rounded-md"
                :value="value ?? ''"
                @input="setValue($event.target.value)"
            />

            <p v-if="error" class="mt-1 text-sm text-iui-form-destructive">
                {{ error }}
            </p>
        </div>
    </template>
</Form>

The slot renders exactly where the field appears in the backend schema, including fields inside fieldsets. Without a matching slot, the default field component renders as usual.

Field replacement slots receive these props:

PropDescription
fieldThe serialized field configuration from PHP.
formThe useForm return value used by the generated form.
contextThe injected form context used by field components.
nameThe field name.
valueThe current form value for the field.
errorThe validation error for the field, if any.
errorsThe full form error object.
setValueUpdates the form value and clears the field error.
fieldClassLayout class the renderer would have passed to the default field wrapper.
inGridWhether the field is currently rendered in a multi-column fieldset grid.

React doesn't expose a field replacement renderer. For adjacent content, use the insertion render map below. To replace the generated field itself, use manual form rendering.

Inserting Content Around Fields ​

To add content right before or after one generated field without replacing it, use the #before-{name}-field and #after-{name}-field slots in Vue, or slots.fields[name].before and slots.fields[name].after in React. These insertion points render around the default field component. In Vue, they also render around a matching replacement slot, such as #email-field:

vue
<Form :form="form">
    <template #before-email-field="{ field }">
        <p class="text-sm text-iui-form-muted-foreground">
            We will use {{ field.label }} for account notifications.
        </p>
    </template>

    <template #after-email-field="{ value }">
        <p v-if="value" class="text-sm text-iui-form-muted-foreground">
            You can change this address later.
        </p>
    </template>
</Form>
tsx
<Form
    form={form}
    slots={{
        fields: {
            email: {
                before: ({ field }) => (
                    <p className="text-iui-form-muted-foreground text-sm">
                        We will use {field.label} for account notifications.
                    </p>
                ),
                after: ({ value }) =>
                    value ? (
                        <p className="text-iui-form-muted-foreground text-sm">
                            You can change this address later.
                        </p>
                    ) : null,
            },
        },
    }}
/>

Vue field insertion slots and React field renderers receive the field props listed above. The default field still renders between the before and after insertion points, unless you also provide the Vue replacement slot for that field.

Vue slot names use the serialized field name plus -field, while React field keys use the serialized field name directly. For a field name that isn't a valid static Vue slot name, use a dynamic slot name:

vue
<template #[`user.email-field`]="slotProps">
    <!-- ... -->
</template>

<template #[`before-user.email-field`]="slotProps">
    <!-- ... -->
</template>
tsx
<Form
    form={form}
    slots={{
        fields: {
            'user.email': {
                before: ({ name }) => (
                    <p className="text-iui-form-muted-foreground text-sm">
                        Extra detail for {name}.
                    </p>
                ),
            },
        },
    }}
/>

Inserting Content Around Fieldsets ​

To add content right before or after a generated fieldset, use the #before-{id}-fieldset and #after-{id}-fieldset slots in Vue, or slots.fieldsets[id].before and slots.fieldsets[id].after in React. Targeting a fieldset requires an explicit id, which you set with the Fieldset id method. Fieldsets aren't targeted by legend text or array position:

php
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\TextInput;

Fieldset::make()
    ->id('account')
    ->legend('Account')
    ->fields([
        TextInput::make('email')->label('Email'),
    ]);
vue
<Form :form="form">
    <template #before-account-fieldset="{ fieldset }">
        <p class="text-sm text-iui-form-muted-foreground">
            {{ fieldset.legend }} details
        </p>
    </template>

    <template #after-account-fieldset="{ id }">
        <p class="text-sm text-iui-form-muted-foreground">
            End of {{ id }}.
        </p>
    </template>
</Form>
tsx
<Form
    form={form}
    slots={{
        fieldsets: {
            account: {
                before: ({ fieldset }) => (
                    <p className="text-iui-form-muted-foreground text-sm">
                        {fieldset.legend} details
                    </p>
                ),
                after: ({ id }) => (
                    <p className="text-iui-form-muted-foreground text-sm">
                        End of {id}.
                    </p>
                ),
            },
        },
    }}
/>

Fieldset insertion slots and renderers receive these props:

PropDescription
fieldsetThe serialized fieldset configuration from PHP.
formThe useForm return value used by the generated form.
contextThe injected form context used by field components.
idThe explicit fieldset id.
fieldClassLayout class when provided by the fieldset renderer.
inGridWhether the fieldset uses a multi-column grid.

For complete control over every field and the form shell itself, use manual form rendering. Manual Form Rendering shows the provider setup and the direct component pattern for both Vue and React.

Mixing Auto-Render and Custom Content ​

You may use the default slot to add custom content alongside the auto-rendered fields. The auto-rendered fieldsets appear first, followed by your slot content:

vue
<Form :form="form">
    <template #default="{ form }">
        <!-- This appears after all auto-rendered fields -->
        <div class="bg-iui-form-info-subtle rounded-iui-form-lg p-4 mt-4">
            <h3 class="font-medium text-iui-form-info-foreground">Preview</h3>
            <p>Name: {{ form.data.name }}</p>
            <p>Email: {{ form.data.email }}</p>
        </div>
    </template>
</Form>

Wizard Additional Content ​

The Vue Wizard component provides a default slot with both form and wizard props. In React, the Wizard component accepts an equivalent render function as children:

vue
<Wizard :form="form">
    <template #default="{ form, wizard }">
        <p class="text-sm text-iui-form-muted-foreground mt-4">
            Step {{ wizard.currentStep.value + 1 }} of {{ wizard.totalSteps.value }}
        </p>
    </template>
</Wizard>
tsx
<Wizard form={form}>
    {(generatedForm, wizard) => <p>Step {wizard.currentStep + 1} of {wizard.totalSteps}</p>}
</Wizard>

The Vue field and fieldset insertion slots and the React slots render map work around the active wizard step content the same way they work in Form.

Using Individual Input Components ​

Direct input components are exported from @inertiaui/form-vue/components and @inertiaui/form-react/components, and you may use them in manual form layouts. RichText is exported from the richtext subpath of each package, so Tiptap stays out of the general component barrel. With form context in the component tree, these components bind to the form data automatically. Pass the serialized field config into the component:

vue
<script setup lang="ts">
import { SubmitButton, Textarea, TextInput } from '@inertiaui/form-vue/components'
</script>

<template>
    <TextInput v-bind="form.getField('name')" />
</template>
tsx
import { SubmitButton, Textarea, TextInput } from '@inertiaui/form-react/components'

export function CustomLayout({ form }) {
    return <TextInput {...form.getField('name')} />
}

Direct components give you the pre-built inputs in a custom layout that the auto-rendering Form component doesn't support. For components that don't use useForm or serialized form.getField(...) payloads, see Standalone Components.