Blocks
The Blocks field lets users build a list of mixed content blocks. In a Repeater, every item uses the same schema. A block instead stores a type and renders the schema of that type.
Submitted values use this shape:
[
{
"type": "hero",
"data": {
"headline": "Launch faster",
"summary": "Build forms from PHP and render them in your frontend."
}
}
]Basic Usage
use InertiaUI\Forms\Fields\Blocks;
use InertiaUI\Forms\Fields\BlockSet;
use InertiaUI\Forms\Fields\Textarea;
use InertiaUI\Forms\Fields\TextInput;
Blocks::make('content')
->sets([
BlockSet::make('hero')
->label('Hero')
->schema([
TextInput::make('headline')->required(),
Textarea::make('summary')->rows(3),
]),
BlockSet::make('quote')
->label('Quote')
->schema([
Textarea::make('quote')->required(),
TextInput::make('author'),
]),
])
->default([
[
'type' => 'hero',
'data' => [
'headline' => 'Launch faster',
'summary' => 'Build forms from PHP and render them in your frontend.',
],
],
]);The field adds the array validation rule automatically.
All shared field methods remain available. See Form Class, Model Binding, Validation, Conditional Visibility, Authorization, and Styling.
Block Sets
Each BlockSet defines one available block type:
BlockSet::make('callout')
->label('Callout')
->description('Short notice with a tone')
->icon('C')
->schema([
TextInput::make('title')->required(),
TextInput::make('tone')->default('info'),
]);The name you pass to BlockSet::make() is trimmed and serialized as the block type, so keep it stable once users have saved data. Every set in one Blocks field must have a unique, non-empty type. Without the label method, the type is converted to title case. The description method adds text to the chooser, and the description is also the fallback for the block header. Without the icon method, the chooser shows the first character of the label.
BlockSet is PHP configuration rather than a separate frontend component. Vue and React receive each serialized set through Blocks.
To assemble a form's block types one at a time, you may call the set method instead of sets:
Blocks::make('content')
->set(BlockSet::make('hero')->schema([
TextInput::make('headline')->required(),
]))
->set(BlockSet::make('quote')->schema([
Textarea::make('quote')->required(),
]));Searching and Grouping the Add Chooser
The add chooser supports search, category filters, and label sorting. You may enable each one independently:
Blocks::make('content')
->searchable()
->groupFilter()
->sortByLabel()
->sets([
BlockSet::make('hero')
->label('Hero')
->description('Page introduction')
->group('Content')
->schema([TextInput::make('headline')]),
]);Search matches all typed words across the label and description, ignoring case and accents. Group filters work alongside search.
These options are off by default. Without sortByLabel, sets appear in their configured order. Direct components accept the matching searchable, groupFilter, and sortByLabel props.
Retiring a Block Set
To keep a set and its schema while preventing users from adding new instances, pass false to the set's addable method:
BlockSet::make('hero_v1')
->addable(false)
->schema([TextInput::make('headline')->required()]);Existing items remain editable and keep their validation rules. Retired sets can't be added through the chooser or the controller. To make the server also reject new instances, add application validation.
Initial Values and Block Defaults
To set the initial block array when no model value exists, use the inherited Blocks::default() method. Each item must use the submitted { type, data } shape shown above.
Schema field defaults are used when a block is added. You may also provide set-level defaults:
BlockSet::make('hero')
->default([
'eyebrow' => 'Featured',
])
->schema([
TextInput::make('eyebrow'),
TextInput::make('headline')->required(),
]);Schema field defaults are collected first, and then BlockSet::default() overrides matching keys. A known block loaded from a model, Blocks::default(), value, or defaultValue lets its supplied data override those set defaults, and any missing keys are backfilled. Unknown types keep their submitted data so the UI may report them, but Laravel's structural type rule rejects them.
Header Preview
To show live data in the collapsed block header, use the preview method:
BlockSet::make('hero')
->preview('headline', 'eyebrow')
->schema([
TextInput::make('eyebrow'),
TextInput::make('headline')->required(),
]);The first argument is the title field. The second argument is the optional description field.
To configure only one side of the header preview, use the previewTitle or previewDescription method:
BlockSet::make('hero')
->previewTitle('headline')
->previewDescription('eyebrow');Preview strings are reduced to plain text for the header, while numeric 0 and boolean false are preserved. A missing or empty preview title falls back to the set label plus the one-based block position. A missing description preview falls back to the set description.
Launch checklistHeroFeatured
Featured
Limits and Validation
Blocks validate the number of blocks, both in total and per type, as well as the structure and nested fields of every submitted block.
Limits
To limit the total number of blocks, use the minItems and maxItems methods of the Blocks field:
Blocks::make('content')
->minItems(1)
->maxItems(3)
->sets([
BlockSet::make('hero')->schema([
TextInput::make('headline')->required(),
]),
]);To limit a specific block type, call maxItems on the set:
BlockSet::make('hero')
->maxItems(1);A set at its maximum remains visible in the chooser, but it's disabled. On submit, Blocks::maxItems() adds a normal Laravel max: rule to the top-level content array. BlockSet::maxItems() adds custom per-type validation that counts the submitted blocks by type and fails when the set exceeds its own maximum.
Limits must be zero or greater, and the field minimum must not exceed its maximum. A maximum of 0 disables additions for the field or set. Passing null clears a configured limit.
Hero 1Hero
Quote 2Quote
Nested Validation
Blocks validate their structure, and then validate the nested schema fields of the submitted block type at each request index:
Blocks::make('content')
->maxItems(10)
->sets([
BlockSet::make('hero')
->maxItems(1)
->schema([
TextInput::make('headline')->required(),
]),
BlockSet::make('quote')->schema([
Textarea::make('quote')->required(),
]),
]);A request with a hero at index 0 and a quote at index 1 validates these rules:
use Illuminate\Validation\Rule;
$rules = [
'content' => ['array', 'max:10', /* per-set max validation */],
'content.*' => ['array'],
'content.*.type' => ['required', 'string', Rule::in(['hero', 'quote'])],
'content.*.data' => ['required', 'array'],
'content.0.data.headline' => ['required'],
'content.1.data.quote' => ['required'],
];Unknown block types fail the structural type rule. Each submitted item must be an array with a data array, and the content.N.data.* rules are resolved from the set that matches content.N.type. A block set with maxItems() also validates that per-type limit against the top-level content value. See Blocks Nested Validation for the validation-first reference.
Conditional visibility inside a block is evaluated with that block's data as the local data and the complete form as the root data. Hidden nested fields receive exclude rules, and unauthorized schema fields are omitted from each serialized set.
Controls
You may customize the add button text and the builder controls:
// $sets is an array of BlockSet instances...
Blocks::make('content')
->sets($sets)
->addButtonText('Add Section')
->reorderable()
->collapsible()
->collapsed();Drag-to-reorder, adding, deleting, and collapsing are enabled by default. To disable them, use reorderable(false), addable(false), deletable(false), or collapsible(false).
Without addButtonText, the component uses its translated add-block label. Calling collapsed also enables collapsing.
Launch fasterHeroStart with the main message.
Start with the main message.
The final review was straightforward.QuoteOperations team
Operations team
Large Builders and Lazy Content
The lazy method renders the fields of an item when it's first expanded:
// $sets is an array of BlockSet instances...
Blocks::make('content')
->sets($sets)
->collapsed()
->lazy();Unopened items still submit their values and are validated normally. Once opened, the fields stay mounted when collapsed, which preserves editor state and active uploads. Direct components accept the lazy prop.
Adding Blocks Programmatically
The component ref exposes a typed BlocksController with an addBlock(type): boolean method. The following examples receive a Blocks field definition that contains a hero set:
<script setup lang="ts">
import type { BlocksController, BlocksProps } from '@inertiaui/form-vue'
import { Blocks } from '@inertiaui/form-vue/components'
import { ref } from 'vue'
defineProps<{ field: BlocksProps }>()
const blocks = ref<BlocksController | null>(null)
</script>
<template>
<button type="button" @click="blocks?.addBlock('hero')">Add hero</button>
<Blocks ref="blocks" v-bind="field" />
</template>import type { BlocksController, BlocksProps } from '@inertiaui/form-react'
import { Blocks } from '@inertiaui/form-react/components'
import { useRef } from 'react'
export default function BlocksControllerExample({ field }: { field: BlocksProps }) {
const blocks = useRef<BlocksController | null>(null)
return (
<>
<button type="button" onClick={() => blocks.current?.addBlock('hero')}>
Add hero
</button>
<Blocks ref={blocks} {...field} />
</>
)
}A successful call adds the block with its defaults and focuses its first focusable field. The method returns false for unknown or retired types, disabled additions, or a reached item limit.
To drive an external picker, use the ref of the mounted component. Calling useBlocks separately creates an independent builder.
Using the Component Directly
Blocks is exported from each stack's components subpath. Pass the serialized sets and bind the block array directly. Vue uses v-model, and React uses a controlled value with onValueChange.
<script setup lang="ts">
import type { BlockItemValue, BlocksField } from '@inertiaui/form-vue'
import { Blocks } from '@inertiaui/form-vue/components'
import { ref } from 'vue'
const sets: BlocksField['sets'] = [
{
type: 'hero',
label: 'Hero',
description: 'Top section for the page',
icon: 'H',
maxItems: 1,
preview: { title: 'headline', description: 'eyebrow' },
defaultData: { eyebrow: 'Featured' },
schema: [
{
component: 'TextInput',
name: 'eyebrow',
label: 'Eyebrow',
inputType: 'text',
required: false,
precognitive: false,
disabled: false,
readonly: false,
autofocus: false,
clearable: false,
copyable: false,
viewable: false,
},
{
component: 'TextInput',
name: 'headline',
label: 'Headline',
inputType: 'text',
required: true,
precognitive: false,
disabled: false,
readonly: false,
autofocus: false,
clearable: false,
copyable: false,
viewable: false,
},
],
},
]
const content = ref<BlockItemValue[] | null>([
{ type: 'hero', data: { eyebrow: 'Featured', headline: 'Launch faster' } },
])
const error = ref<string | null>(null)
const partClasses = {
item: 'ring-zinc-200',
addButton: 'border-zinc-300',
dropdown: 'max-w-md',
}
</script>
<template>
<Blocks
v-model="content"
id="page-content"
name="content"
label="Content"
help="Build the public page sections."
:error="error"
:invalid="!!error"
required
:precognitive="false"
:disabled="false"
:sets="sets"
:min-items="1"
:max-items="5"
:reorderable="true"
:addable="true"
:deletable="true"
:collapsible="true"
:collapsed="false"
add-button-text="Add section"
badge="Page"
tooltip="Each section keeps its own field schema."
help-position="below"
layout="stacked"
control-position="start"
label-class="font-medium"
help-class="text-zinc-500"
error-class="text-red-600"
wrapper-class="max-w-3xl"
control-class="bg-white"
class="space-y-3"
:part-classes="partClasses"
:label-sr-only="false"
/>
</template>import { useState } from 'react'
import type { BlockItemValue, BlocksField } from '@inertiaui/form-react'
import { Blocks } from '@inertiaui/form-react/components'
const sets: BlocksField['sets'] = [
{
type: 'hero',
label: 'Hero',
description: 'Top section for the page',
icon: 'H',
maxItems: 1,
preview: { title: 'headline', description: 'eyebrow' },
defaultData: { eyebrow: 'Featured' },
schema: [
{
component: 'TextInput',
name: 'eyebrow',
label: 'Eyebrow',
inputType: 'text',
required: false,
precognitive: false,
disabled: false,
readonly: false,
autofocus: false,
clearable: false,
copyable: false,
viewable: false,
},
{
component: 'TextInput',
name: 'headline',
label: 'Headline',
inputType: 'text',
required: true,
precognitive: false,
disabled: false,
readonly: false,
autofocus: false,
clearable: false,
copyable: false,
viewable: false,
},
],
},
]
const partClasses = {
item: 'ring-zinc-200',
addButton: 'border-zinc-300',
dropdown: 'max-w-md',
}
export default function ContentBuilder() {
const [content, setContent] = useState<BlockItemValue[] | null>([
{ type: 'hero', data: { eyebrow: 'Featured', headline: 'Launch faster' } },
])
const [error] = useState<string | null>(null)
return (
<Blocks
value={content}
onValueChange={setContent}
id="page-content"
name="content"
label="Content"
help="Build the public page sections."
error={error}
invalid={Boolean(error)}
required
precognitive={false}
disabled={false}
sets={sets}
minItems={1}
maxItems={5}
reorderable
addable
deletable
collapsible
collapsed={false}
addButtonText="Add section"
badge="Page"
tooltip="Each section keeps its own field schema."
helpPosition="below"
layout="stacked"
controlPosition="start"
labelClass="font-medium"
helpClass="text-zinc-500"
errorClass="text-red-600"
wrapperClass="max-w-3xl"
controlClass="bg-white"
class="space-y-3"
partClasses={partClasses}
labelSrOnly={false}
/>
)
}Blocks is a composite control and doesn't forward arbitrary native attributes or listeners to one inner element. See Native Attributes and Events.
Accessibility
The add button exposes its chooser with aria-expanded and aria-controls, and Escape or an outside interaction closes it. Chooser options are buttons, and sets at their limit remain visible but disabled. Every block has keyboard move buttons in addition to pointer dragging. Reorders are announced live, and focus follows a moved block. Collapsible blocks use native details and summary semantics. Deleting a block opens a labeled confirmation dialog, which keeps focus inside it and restores focus when it closes.