Field widths
Every form lays its fields out on a grid of 12 columns. A field takes one of six widths: a quarter, a third, a half, two thirds, three quarters or the full row. Rows fill up on their own, so three thirds share one row and two halves the next, and no more than four fields ever sit side by side.
The layout config value decides how many of those widths a project offers:
layout | Widths |
|---|---|
flexible | All six (the default) |
two_columns | Halves and the full row |
full_width | The full row only |
It applies everywhere: the builder only offers those widths, and stored widths,
including those set in code, round to the nearest one when a form is shown, so a
third reads as a half in two_columns.
In the builder, the width on a field's toolbar opens a picker with all six. A
new field takes the room left on the row it lands on, so a field dropped next to
two thirds becomes a third. Dropped against a field on a full row, it shares that
row: next to one field both become halves, next to two all three become thirds.
Dropped between two rows, or near the top or bottom edge of one, it gets a row of
its own. Moving a field works the same way, and the row it leaves closes up. The
canvas shows where the field lands and how wide everything becomes while it is
dragged. In code, pass the width
to span():
use VanOns\FilamentFormBuilder\Enums\FieldWidth;
TextInputField::make('voornaam')->span(FieldWidth::HALF);Rows stay full. When a field on a full row changes width, the others follow at the widths closest to their own: making the first of three thirds a half turns the other two into quarters. Fields at the end that no longer fit move to a row of their own right below, which they fill, so the rows below stay as they were. A field that is deleted or moved away leaves its room to the others on its row, and a copy shares its original's row or gets one of its own below.
Each field type has a minimum width, below which the builder offers nothing: a third for titles, text blocks, text areas, uploads and checkboxes, half for reCAPTCHA and Turnstile, a quarter for the rest. The submit button always takes the full row, so it sits on a row of its own. A type of your own sets its own:
public static function minWidth(): FieldWidth
{
return FieldWidth::HALF;
}A field is stored with its span in columns (column_span, 3 to 12). A value
that is no width of its own reads as the widest width that fits it, one below
the minimum as the minimum, and an empty one as the full row.
$field->getWidth() returns the FieldWidth, $field->getColumnSpan() the
number of columns.
Styling forms on the site
A form loads form-builder.js, for its conditions, and a minimal stylesheet,
once per page however many forms it has. Both come from
php artisan filament:assets. The stylesheet lays the fields out on the grid,
stacks them on a narrow screen and gives labels, inputs, errors and the button
a plain look. Every rule in it sits in :where(), so any rule of the site's own
wins, and a few custom properties on .ffb-form set its colours:
.ffb-form {
--ffb-background: #fff;
--ffb-border: #d4d4d8;
--ffb-muted: #71717a;
--ffb-error: #b91c1c;
--ffb-button: #18181b;
--ffb-button-text: #fff;
--ffb-radius: 0.375rem;
}To style forms entirely yourself, set styles to false in the config. The
markup has a class for everything a site styles:
| Class | On |
|---|---|
ffb-form | The form |
ffb-field | The wrapper of every field, a fieldset for choices |
ffb-label | The label, or the legend of a choice field |
ffb-required | The star after a required field's label |
ffb-description | The description below a field, or a choice field's legend |
ffb-check | The label around a checkbox or an option, input first |
ffb-options | The options of a choice field |
ffb-error | A validation message, inside the field's wrapper |
ffb-title | A title's heading |
ffb-text | A text block |
ffb-submit | The submit button |
ffb-message | The thank-you message after a submission; with ffb-message-error, the message that the session had expired |
ffb-step | A step, a fieldset with its title in ffb-step-title |
ffb-step-nav | The previous, next and submit buttons below the steps; the first two are ffb-step-button |
ffb-progress-steps | The steps by title; each ffb-progress-step has data-state done, current or upcoming, and a done step before the current one is a ffb-progress-step-link button |
ffb-progress-bar | The bar; ffb-progress-fill is as wide as --ffb-progress |
A field with an error also has aria-invalid="true". The grid comes from the
wrapper's custom properties, which a stylesheet of your own picks up the same
way:
.ffb-form {
display: grid;
grid-template-columns: repeat(12, minmax(0, 1fr));
}
.ffb-field {
grid-column: var(--form-builder-column-start, auto) / span var(--form-builder-column-span, 12);
}The fields an editor builds form a block of their own: the first of them starts
a new row, and so does the first field from code after them. Their wrapper
carries --form-builder-column-start: 1 and data-form-builder-new-row. The
span is also available as data-form-builder-column-span for projects that
would rather select on attributes than custom properties.
