ComfyCoders TranquilTools
Docs /Laravel Vue FormBuilder
Repository
v1

Columns

Fields stack below each other by default. Two places lay them out in columns instead, and both collapse to a single column below the md breakpoint.

On the whole form

Set the columns of the whole form in PHP with FormConfig::columns(n), 1 to 6 or 12; the schema carries them as columns:

public function configure(FormConfig $form): void
{
    $form->columns(2);
}

Or use the columns prop of <Form> (and FormRenderer), which wins over the schema:

<template>
    <Form :schema="form" :columns="3" />
</template>

A schema without columns (the default) leaves the form at one column, as before. FormConfig::columns() requires tranquil-tools/laravel-form-builder 1.6 and laravel-vue-form-builder 1.9; an older renderer ignores it.

A one-column form spaces its fields space-y-4 apart. A one-column form with its own FormConfig::class() lays out its fields itself instead: the fields are then direct children of the <form>, so a class such as ['grid', 'grid-cols-5', 'gap-4'] with ->wrapperClass('col-span-5') (or the older ->class()) on the fields, or space-y-6, works on them. A section in such a form is one cell of that layout too, so give it a ->wrapperClass('col-span-5') as well.

On a section

Section::make()->columns(n) lays out the fields of that section only, whatever the form does:

Section::make()
    ->title('Address')
    ->columns(3)
    ->fields([
        Text::make('street')->columnSpan(2),
        Text::make('number'),
        Text::make('postcode'),
        Text::make('city')->columnSpan(2),
    ]),

A nested section without ->columns() uses the columns of the section around it, or those of the form; ->columns(1) stacks its fields again. See Sections.

Spanning columns

Method Effect
->columnSpan(n) the field takes n columns (up to 12); more than there are means the whole row
->columnSpanFull() the field takes the whole row

These fields take the whole row by default: Textarea, Wysiwyg, Repeater, KeyValue, Button, Submit, DeleteButton and Section. Every other field, Display included, takes one column. A Hidden field takes no cell at all: it adds no row, no gap and no row break between the fields around it. ->columnSpan(n) overrides the default either way, so Textarea::make('notes')->columnSpan(1) sits next to another field; ->columnSpanFull() and fullWidth always take the whole row. A section spans the whole row and lays out its own fields in the columns of the form, or of the section around it, unless it sets ->columns().

From the Vue side, fullWidth and columnSpan in field-overrides do the same:

<Form :schema="form" :columns="2" :field-overrides="{ notes: { fullWidth: true } }" />

Breakpoints

Every grid is a single column below md. From md up to lg a wide grid shows fewer columns, so its fields keep room:

columns from md from lg
1 to 4 1 to 4 same as md
5 3 5
6 3 6
12 6 12

Other counts are rounded down to one of these: 7 to 11 become 6, more than 12 becomes 12, in PHP and in the renderer alike. In the narrower md grid a span shrinks in proportion and rounds up: in a 12-column grid ->columnSpan(3) takes 2 of the 6 columns from md and 3 from lg, ->columnSpan(8) takes 4 and 8.

The grid uses md:grid-cols-2 to md:grid-cols-6, lg:grid-cols-5, lg:grid-cols-6 and lg:grid-cols-12, and md:col-span-2 to md:col-span-6 and lg:col-span-2 to lg:col-span-12. They live in the package's Vue components, so the @source line from Installation picks them up.

Requires tranquil-tools/laravel-form-builder 1.5 and laravel-vue-form-builder 1.8 or newer for sections and spans; form-level columns 3 and 4 only need the renderer. Columns 5, 6 and 12 and spans above 4 need laravel-form-builder 1.18 and laravel-vue-form-builder 1.23; an older core cuts them back to 4.