Fieldsets
Fieldsets group related fields together, with an optional legend, description, and grid layout. A fieldset with a legend renders as an HTML <fieldset> element with a <legend>. A fieldset without a legend renders as a <div>, so it doesn't add an unnamed fieldset to the accessibility tree.
Defining Fieldsets
To group fields, wrap them in a Fieldset and give it a legend:
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\TextInput;
use InertiaUI\Forms\Form;
class RegistrationForm extends Form
{
protected ?string $actionRoute = 'register';
public function fields(): array
{
return [
Fieldset::make()
->legend('Personal Information')
->fields([
TextInput::make('first_name')->required(),
TextInput::make('last_name')->required(),
TextInput::make('email')
->email()
->required(),
]),
];
}
}Legend and Description
You may add a description below the legend to give the group extra context:
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\TextInput;
Fieldset::make()
->legend('Shipping Address')
->description('Where should we send your order?')
->fields([
TextInput::make('street'),
TextInput::make('city'),
TextInput::make('state'),
TextInput::make('zip'),
]);The frontend renderers output a string description as escaped text, so a string that looks like markup is displayed as text. Only an Htmlable value renders as HTML, as described in Text and HTML Rendering.
Fields Outside Fieldsets
Fields you return outside of any Fieldset are wrapped in one automatically. For example, this form wraps its fields in an explicit fieldset:
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\Submit;
use InertiaUI\Forms\Fields\TextInput;
use InertiaUI\Forms\Form;
class ContactForm extends Form
{
public function fields(): array
{
return [
Fieldset::make()->fields([
TextInput::make('name'),
TextInput::make('email'),
]),
Submit::make('Save'),
];
}
}Returning the same fields without the Fieldset produces an equivalent form:
use InertiaUI\Forms\Fields\Submit;
use InertiaUI\Forms\Fields\TextInput;
use InertiaUI\Forms\Form;
class ContactForm extends Form
{
public function fields(): array
{
return [
TextInput::make('name'),
TextInput::make('email'),
Submit::make('Save'),
];
}
}You may mix fieldsets and loose fields freely. Consecutive loose fields are grouped into the same generated fieldset:
use InertiaUI\Forms\Fields\Combobox;
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\Submit;
use InertiaUI\Forms\Fields\TextInput;
use InertiaUI\Forms\Fields\Textarea;
use InertiaUI\Forms\Form;
class ArticleForm extends Form
{
public function fields(): array
{
return [
TextInput::make('title'), // Generated fieldset 1
TextInput::make('slug'), // Generated fieldset 1
Fieldset::make() // Explicit fieldset 2
->legend('Details')
->columns(2)
->fields([
Combobox::make('category')->options([
'news' => 'News',
'guides' => 'Guides',
]),
Combobox::make('status')->options([
'draft' => 'Draft',
'published' => 'Published',
]),
]),
Textarea::make('body'), // Generated fieldset 3
Submit::make('Publish'), // Generated fieldset 3
];
}
}Arranging Fields
Each fieldset lays out its own fields, so a form may combine several fieldsets with different layouts, and a fieldset may contain other fieldsets.
Grid Layout with Columns
To arrange fields in a CSS grid, you may use the columns method. Its value is the maximum number of columns. The grid drops to fewer columns automatically when the container is too narrow:
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\TextInput;
Fieldset::make()
->legend('Address')
->columns(2)
->fields([
TextInput::make('first_name'), // Column 1
TextInput::make('last_name'), // Column 2
TextInput::make('street'), // Column 1
TextInput::make('city'), // Column 2
TextInput::make('state'), // Column 1
TextInput::make('zip'), // Column 2
]);Fields flow left to right, then top to bottom. This fieldset uses up to three columns:
use InertiaUI\Forms\Fields\Combobox;
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\TextInput;
$states = [
'CA' => 'California',
'NY' => 'New York',
'TX' => 'Texas',
];
Fieldset::make()
->columns(3)
->fields([
TextInput::make('city'),
Combobox::make('state')->options($states),
TextInput::make('zip'),
]);Multiple Fieldsets
A form may contain several fieldsets, each with its own layout:
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\Submit;
use InertiaUI\Forms\Fields\TextInput;
use InertiaUI\Forms\Fields\Textarea;
use InertiaUI\Forms\Fields\Toggle;
use InertiaUI\Forms\Form;
class ProfileForm extends Form
{
public function fields(): array
{
return [
Fieldset::make()
->legend('Account')
->fields([
TextInput::make('username')->required(),
TextInput::make('email')
->email()
->required(),
]),
Fieldset::make()
->legend('Profile')
->columns(2)
->fields([
TextInput::make('first_name'),
TextInput::make('last_name'),
Textarea::make('bio')->rows(3),
]),
Fieldset::make()
->legend('Preferences')
->fields([
Toggle::make('notifications'),
Toggle::make('newsletter'),
]),
Submit::make('Save'),
];
}
}Nested Fieldsets
A fieldset may contain other fieldsets alongside its regular fields:
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\TextInput;
Fieldset::make('Account')
->fields([
TextInput::make('name')->required(),
Fieldset::make('Address')
->columns(2)
->fields([
TextInput::make('street')->required(),
TextInput::make('city')->required(),
]),
]);Nesting doesn't change field names or model binding. Hiding a parent fieldset hides its nested fields and excludes them from validation. In a wizard, nested fieldsets stay inside their parent step.
Conditional Fieldsets
Fieldsets support the same conditional visibility methods as fields. Hiding a fieldset removes it together with all of its children. Server-side validation also excludes each child field while the parent fieldset is hidden:
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\TextInput;
Fieldset::make()
->legend('Phone Details')
->visibleWhen('contact_method', 'phone')
->clearWhenHidden()
->fields([
TextInput::make('phone_number')->required(),
TextInput::make('phone_extension'),
]);The clearWhenHidden method resets the child values after the fieldset hides. Leave it off when the child values should stay.
Customizing Fieldsets
A fieldset accepts its own CSS classes and HTML id, and it may render through a wrapper component of your own.
Custom CSS Classes
To add CSS classes to a fieldset, pass them to the class method:
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\Toggle;
Fieldset::make()
->legend('Settings')
->class('rounded-lg bg-zinc-50 p-6')
->fields([
Toggle::make('notifications'),
]);Fieldset ID
The id method sets the HTML id attribute of the rendered fieldset wrapper. This is useful for anchor links or for targeting the fieldset from JavaScript:
use InertiaUI\Forms\Fields\Fieldset;
use InertiaUI\Forms\Fields\TextInput;
Fieldset::make()
->id('billing-section')
->legend('Billing Information')
->fields([
TextInput::make('billing_email')->email(),
]);Custom Wrapper Component
To wrap a fieldset in your own component, such as a card, extend Fieldset and return the component's name from the getWrapperComponent method:
namespace App\Fields;
use InertiaUI\Forms\Fields\Fieldset;
class CardFieldset extends Fieldset
{
public function getWrapperComponent(): ?string
{
return 'CardFieldset';
}
}You may then use the subclass like any other fieldset:
use App\Fields\CardFieldset;
use InertiaUI\Forms\Fields\TextInput;
CardFieldset::make('Billing Information')
->columns(2)
->fields([
TextInput::make('company'),
TextInput::make('vat_id'),
]);Register the wrapper component the same way as a custom field. It receives the fieldset's props, and the rendered field grid as React children or as Vue's default slot. Apply both class and wrapperClass so the wrapper keeps its styling and placement when it's nested:
import { cn, registerFieldComponents } from '@inertiaui/form-react'
import type { FieldsetConfig } from '@inertiaui/form-react'
import type { ReactNode } from 'react'
type CardFieldsetProps = FieldsetConfig & { wrapperClass?: FieldsetConfig['class']; children?: ReactNode }
function CardFieldset({ legend, description, id, class: className, wrapperClass, children }: CardFieldsetProps) {
return (
<section id={id ?? undefined} className={cn('rounded-lg border p-6', className, wrapperClass)}>
<h2>{legend}</h2>
{description && <p>{description}</p>}
{children}
</section>
)
}
registerFieldComponents({ CardFieldset })<script setup lang="ts">
import type { FieldsetConfig } from '@inertiaui/form-vue'
defineOptions({ inheritAttrs: false })
defineProps<FieldsetConfig & { wrapperClass?: FieldsetConfig['class'] }>()
</script>
<template>
<section :id="id ?? undefined" :class="['rounded-lg border p-6', $props.class, wrapperClass]">
<h2>{{ legend }}</h2>
<p v-if="description">{{ description }}</p>
<slot />
</section>
</template>import { registerFieldComponents } from '@inertiaui/form-vue'
import CardFieldset from './CardFieldset.vue'
registerFieldComponents({ CardFieldset })To pass additional props to the wrapper, extend the toArray method in your subclass and merge them into parent::toArray().
Using the Component Directly
The root Vue and React packages export the Fieldset component. Pass it the serialized fieldset shape, including its fields array. The component reads visibility and child values from the surrounding form context, and renders each child through FieldRenderer:
<script setup lang="ts">
import { Fieldset } from '@inertiaui/form-vue'
import type { FormField } from '@inertiaui/form-vue'
const fields: FormField[] = [
{
component: 'TextInput',
name: 'billing_email',
label: 'Billing email',
inputType: 'email',
required: true,
precognitive: false,
disabled: false,
readonly: false,
autofocus: false,
clearable: false,
copyable: false,
viewable: false,
},
]
const trackFocus = () => {}
</script>
<template>
<Fieldset
:fields="fields"
legend="Billing"
description="Invoice contact details"
:columns="2"
id="billing-section"
class="rounded-lg bg-zinc-50 p-6"
wrapper-class="ring-1 ring-zinc-200"
:visibility="{ field: 'billing_method', operator: '=', value: 'invoice' }"
clear-when-hidden
data-testid="billing-fieldset"
@focusin="trackFocus"
/>
</template>import { Fieldset } from '@inertiaui/form-react'
import type { FormField } from '@inertiaui/form-react'
const fields: FormField[] = [
{
component: 'TextInput',
name: 'billing_email',
label: 'Billing email',
inputType: 'email',
required: true,
precognitive: false,
disabled: false,
readonly: false,
autofocus: false,
clearable: false,
copyable: false,
viewable: false,
},
]
export function BillingFieldset() {
const trackFocus = () => {}
return (
<Fieldset
fields={fields}
legend="Billing"
description="Invoice contact details"
columns={2}
id="billing-section"
class="rounded-lg bg-zinc-50 p-6"
wrapperClass="ring-1 ring-zinc-200"
visibility={{ field: 'billing_method', operator: '=', value: 'invoice' }}
clearWhenHidden
data-testid="billing-fieldset"
onFocus={trackFocus}
/>
)
}The component reads the fields, legend, description, columns, id, class, wrapperClass, wrapperComponent, visibility, and clearWhenHidden props. Native attributes and listeners go to the rendered <fieldset>, or to the fallback <div>. Visibility and child values require the surrounding form context.
The Form and Wizard components, or an outer FieldRenderer, apply clearWhenHidden once a visible fieldset becomes hidden. The Fieldset component on its own only renders or hides the group.