Sections
A Section structures a long form: a heading, an optional description and the fields that belong under it. It is a
layout element, not a field: it holds no value and submits nothing of its own.
use TranquilTools\FormBuilder\Fields\Section;
public function fields(): array
{
return [
Section::make()
->title('Contact details')
->description('We only use these to confirm the booking.')
->fields([
Text::make('name')->required(),
Email::make('email')->required(),
]),
Section::make()
->title('Stay')
->fields([
Date::make('arrival_on')->required(),
Number::make('guests')->rules('integer', 'min:1'),
]),
Submit::make(),
];
}
- The fields inside a section are ordinary top-level fields: they keep their own names, their rules end up in
getRules()andvalidate(), andfill()fills them. ->description()escapes a string; pass anHtmlStringfor markup, like->help().- A section without fields is a plain heading between other fields.
- Sections can be nested, and conditions (
->if()) work on a section and across sections. A section with->if('action', 'rebook')excludes every field inside it from validation and from the payload while it is hidden. - In a two-column form a section spans both columns and lays out its own fields in two columns, unless it sets its own
->columns(). ->wrapperClass('...')(or the older->class('...')) replaces the classes of the section element (defaultspace-y-4).->inputClass()has no effect on a section.
Columns
->columns(n) puts the fields of a section side by side, in 1 to 6 or 12 columns. Below the md breakpoint they
stack in a single column again, and 5, 6 and 12 columns show fewer columns up to the lg breakpoint, see
Columns. A field takes more than one column with ->columnSpan(n), or the whole row with
->columnSpanFull():
Section::make()
->title('Address')
->columns(3)
->fields([
Text::make('street')->columnSpan(2),
Text::make('number'),
Text::make('postcode'),
Text::make('city')->columnSpan(2),
Textarea::make('directions'), // a textarea spans the row by default
]),
- A span larger than the number of columns is cut back to the full row.
Textarea,Wysiwyg,Repeater,KeyValue,Button,Submit,DeleteButtonand nested sections take the full row unless they set a->columnSpan()of their own.Displayand every other field take one column. AHiddenfield takes no cell.- A nested section without
->columns()uses the columns of the section around it;->columns(1)stacks its fields again.
See Columns for columns on the whole form.
Requires tranquil-tools/laravel-form-builder 1.5 and laravel-vue-form-builder 1.8 or newer; 5, 6 and 12 columns
need laravel-form-builder 1.18 and laravel-vue-form-builder 1.23.
Steps
To split a long form into steps that are shown one at a time, use Step instead of Section. See
Steps.
