DXForm
The canonical form renderer. Drive it with field definitions; add tabs when
you need a multi-tab editor. Flat and tabbed forms share one engine
(DXField), so every field type, conditional
field, per-field slot override, async option, and nested
repeater works the same in both.
It works with the fetch-based useForm composable (no Inertia required) and
accepts either a useForm return or a defineForm return (with the latter,
fields may be omitted).
Live Examples
Product Editor
A tabbed form with a conditional field and a custom stock editor. Press Save product: the demo server rejects it with a 422 carrying errors on two tabs, on the stock editor's rows and on a key no field renders. The form moves to the first tab with an error, and the summary above the button lists every message. Click a row to go to its field.
Horizontal layout
Setting layout="horizontal" moves every field's label to a left-hand column, including checkbox and repeater fields. A field can opt back into vertical with field.layout.
Props
| Name Click to sort ascending | Type | Required Click to sort ascending | Default | Description |
|---|---|---|---|---|
form | UseFormReturn<any> | DefineFormReturn<any> | Yes | - | Form instance from useForm, or the { form, fields } object from defineForm. |
fields | FieldDefinition[] | No | - | Field definitions. Optional when form is a defineForm return (taken from it). |
tabs | FormTab[] | No | - | Tab definitions. When omitted, a flat single-column form renders. |
context | Record<string, any> | No | - | Extra context merged under the live form data when evaluating predicates (label/hint/when/disabled). |
activeTab | number (v-model) | No | 0 | Active tab, as an index into the VISIBLE tabs. Two-way bindable via v-model:active-tab. The form tracks the tab by key, so the same tab stays shown when tabs reorder or an earlier one hides (the index is re-emitted), and an initial index other than 0 is honoured. |
autoErrorTab | boolean | No | true | After a failed submit (and for errors already on the form at mount), select the first visible tab holding a visible field with an error. Fixing a field never moves the tab. |
errorSummary | "footer" | "top" | "external" | false | No | "footer" | Where to list what the last failed submit returned: directly above the submit button ("footer"), above the fields ("top"), in a DXFormErrorSummary the host renders elsewhere ("external": DXForm shows neither a summary nor its alert), or nowhere (false, the form-level alert as before). See Validation errors below. |
errorSummaryTitle | string | No | "Couldn't save. Please check:" | The summary's heading when the failure has field errors. A failure with none (a message-only 422, a 500) is headed by the server's message instead. |
errorSummaryOtherTitle | string | No | "Other problems" | The summary's sub-heading over the rows no visible field owns, shown only when some rows are owned. |
scrollToError | boolean | No | true | After a failed submit, scroll the first field with an error into view once its tab is shown. Never moves focus. |
submitText | string | No | Submit | Submit button text. |
submitLoadingText | string | No | Submitting... | Submit button loading text. |
submitSavedText | string | No | Saved | Submit button label in the saved state (see Saved state below). |
savedState | boolean | No | true | After a successful form.post/put/patch, show the submit button as a disabled "✓ Saved" until any field changes. Set false for forms whose submit is not a save (search, filter). |
showSubmit | boolean | No | true | Show the submit button. |
card | boolean | No | false | Wrap a FLAT form in a card for a visual boundary (mirrors DXTable's card prop). Also forces the tabbed card on even when cardTabs is false. Off by default since DXForm is commonly embedded in a page card or modal already. |
cardTabs | boolean | No | true | Wrap a TABBED form's content in a card panel so the active tab reads as a finished panel connected to the tab strip (the standard Bootstrap card-with-tabs pattern) rather than floating on the bare page. Set false for bare tabs (e.g. inside a modal that already provides a boundary). Ignored for flat forms — use card for those. |
layout | "vertical" | "horizontal" | "auto" | No | "vertical" | Form-wide field layout. "horizontal" puts the label to the left of the input whatever the container width (with the default label column, from the sm viewport breakpoint up; a numeric labelCols keeps it at every width). "auto" picks horizontal or vertical from the width of the form's own container (see Container-driven layout below). Overridable per-field via field.layout. |
layoutThreshold | number | No | 640 | Container width (px) at or above which layout: "auto" goes horizontal. Ignored for the explicit layouts. |
labelCols | number | { sm?, md?, lg?, xl? } | No | 45% from sm up | Label column width for horizontal layout (mirrors BFormGroup's labelCols). Overridable per-field via field.labelCols. Omitted breakpoints collapse to vertical below that width. When neither the form nor the field sets it, the label is --dx-form-label-width (45%) wide from sm up and stacks above the input below sm. |
Events
| Name Click to sort ascending | Parameters | Description |
|---|---|---|
submit | none | Emitted when the form is submitted (run your form.post/put in the handler). |
Slots
Per-field slots are keyed by field key, e.g. #value(price) or #hint(sku).
#valuevs#span: a labelled custom control is a normal field plus a#value(<key>)slot — it keeps the form’s label column and grid, no re-derived col classes. Reserve#span(<key>)(withspan: true) for genuinely full-width, label-less blocks (a sub-table, an activity log).
| Name Click to sort ascending | Description | Scoped Props |
|---|---|---|
value(<key>) | Replace a field's input control with custom markup. On a plaintext field the content is wrapped in .dx-form-plaintext so display-only content lines up with the label (see Display-only values). | - |
span(<key>) | Full-width custom block for a field marked span: true. | - |
info(<key>) | Rich info block rendered always-visible below the field (not the label popover). | - |
info-popover(<key>) | Rich body for the label’s hover/focus info popover (lists, bold, paragraphs). Overrides the plain field.info text. | - |
hint(<key>) | Override the hint text rendered below the field. | - |
repeater-row(<key>) | Custom row layout for a repeater field. | - |
switch-list-item(<key>) | Extra content beside a switch-list row's toggle (e.g. a notes input bound to your own model). | - |
password-actions(<key>) | Extra controls beside a password field, after its input and reveal (eye) toggle (they wrap below it when the row is narrow) — e.g. a Generate button that calls update(...) and setRevealed(true). See DXField: Password actions. | - |
field(<key>) | Fully replace a field's rendering (including its label), bypassing DXField entirely. Supersedes field-before/field-after for the same key. Rendered exactly as you write it, with no wrapper. Bind targetAttrs (v-bind="targetAttrs") on the element holding your control so a failed submit can scroll to it and a summary row can focus it; without it auto-scroll moves on to the next error and the summary row focuses the field's tab button instead. | - |
field-before(<key>) | Content rendered directly above a field (e.g. a quick-create button above a select). | - |
field-after(<key>) | Content rendered directly below a field. | - |
tab-content(<key>) | Replace the entire body of a tab. | - |
tab-before(<key>) | Content rendered before a tab's fields. | - |
tab-after(<key>) | Content rendered after a tab's fields. | - |
footer | Content rendered after the form body. | - |
Display-only values
In a horizontal row the label column is padded so its text lines up with the text inside an input box. A row whose value has no form control (a badge, a line of text, a link, a timestamp, a short list, a small table, a flex row of text) needs nothing: the row is baseline-aligned, so the value’s first line of text sits on the label’s, whatever markup you put in the slot:
<DXForm :form="form" :fields="fields" layout="horizontal">
<template #value(connection)>
<span class="badge text-bg-secondary">Not connected</span>
</template>
</DXForm>
- A stack of lines aligns its first line; the rest follow below.
- A table aligns its first row’s text; a badge is centred on the line.
- Inputs, selects, checkboxes, switches, radios, file inputs and buttons need nothing either. A row that holds any of them keeps the input alignment, so display text placed above a button sits at the top of the row; put the text beside the label in its own row instead.
- Content with no text at all (an image, an icon) puts its bottom edge on the label’s baseline.
.dx-form-plaintext(since 0.42.0) still works and is now redundant inside a horizontal form; a field withplaintext: truestill wraps its#value(<key>)slot in it.
Saved state
The submit button is a DXSaveButton.
After a successful submit through the form’s own methods (form.post,
put, patch…, read from form.wasSuccessful) it changes to a disabled
✓ Saved in the same navy (only the label and the disabled state change), and changing any field turns it back into the normal Save button.
While the request is in flight it shows the usual busy state
(submitLoadingText).
- Writes made by the save itself (an
onSuccessthat copies the response into the form,resetOnSuccess, or code straight afterawait form.post()) do not count as changes. - An edit made while the request is in flight is not in the payload, so the button stays Save when that request succeeds.
- A failed save leaves the normal Save button.
- Forms that submit with something other than the form’s own submit methods
never see a success, so they keep the plain button. Set
:saved-state="false"for a form whose submit is not a save, such as a search.
Validation errors
When a submit through the form’s own methods (form.post, put, patch…)
fails, DXForm lists everything the server returned in one alert, directly
above the submit button: a heading, then one row per validation message with
a readable label (“Price (line 1): Must be positive.”).
-
The heading is “Couldn’t save. Please check:” (
errorSummaryTitle) when the failure has field errors. Laravel’s default 422 message (the first error plus “(and 3 more errors)”) would only repeat the first row, so it is not shown then. A failure with no field errors (a message-only 422, a 500, a network failure) is headed by the server’s message. -
Rows for fields on the form come first, as buttons. Rows no visible field owns follow as plain text under “Other problems” (
errorSummaryOtherTitle), a sub-heading shown only when both kinds are present. -
It is built from
form.submitFailure, so it stays while the user edits (fixing a field does not remove its row or bring back a generic message) and disappears when the next submit starts or one succeeds. -
Keys with no rendered field, keys on hidden fields and message-only failures (
errors: {}) are listed too, as plain text, so a 422 is never invisible. -
A row naming a visible field is a button: it selects the field’s tab, scrolls to the field and focuses its input (for a repeater row, that row’s field; a field’s info button is never focused instead; an async editor is waited for). A
field(<key>)slot is reached only if it binds thetargetAttrsslot prop on the element holding its control (<div v-bind="targetAttrs">…</div>). The form looks for that marker when it needs it, anywhere inside the form (aTeleportinto the form counts, one out of it does not), so content that marks itself after loading is found. When the row’s field renders no marker (an unmarked slot), clicking the row still selects its tab and moves focus to the tab’s button. -
A field taller than the window (a long explanation above its input) is scrolled by its input, centred, so the input is never left below the fold (by its first button when it has no input, such as a picker).
-
The form also takes the user to the first problem: it selects the first tab holding an error (
autoErrorTab) and scrolls the field into view (scrollToError), including on alazytab. ApreserveErrorsresubmit that returns the same errors does this again. -
While the summary shows a failure, the form-level alert does not render, so there is one alert, never two.
:error-summary="false"turns the summary off and restores the old alert exactly;error-summary="top"puts it above the fields instead.
Errors on nested keys (errorKeys)
An error key belongs to the field whose key equals it, or the field whose key
is a dot prefix of it (lines.0.price belongs to a lines repeater). A field
rendered under another name, such as a span field showing a custom order-line
editor, claims keys with errorKeys, where * matches one dot segment. Its
tab is then selected, its rows in the summary carry its label, and a row click
scrolls to it:
const fields: FieldDefinition[] = [
{ key: 'customer', type: 'text', label: 'Customer' },
// A span field whose slot edits form.data.lines:
{ key: 'order_lines', type: 'text', label: 'Order lines', span: true,
errorKeys: ['lines.*', 'lines.*.*'] },
];
const tabs: FormTab[] = [
{ key: 'general', label: 'General', fieldKeys: ['customer'] },
{ key: 'lines', label: 'Lines', fieldKeys: ['order_lines'] },
];
// A 422 with { "lines.0.price": ["Must be positive."] } selects "Lines".
Naming a row in the summary (rowLabel)
An error on a row (lines.1.price) is listed under its sub-field’s label and line number:
“Price (line 2): Must be positive.” When each row has a name of its own, give
the field a rowLabel and the summary lists that row under its name instead,
with no line number: “Chaucer Ale (Pint): Must be positive.” It is called with
the row (model.lines[1], or {} when the model has no such row) and its
0-based index: the row’s current position while it exists, or the position
it failed at once it has been removed (the same index “(line N)” counts). Return undefined, null or "" for a row with no name yet
(or let it throw) and that row keeps “Price (line 2)”. It works on a
repeater and on a span field that renders its own rows, for any key
nested under the field’s key. It changes only the label: the owning field,
the tab chosen and what a click on the row focuses are the same as without
it.
const fields: FieldDefinition[] = [
{
key: 'lines',
type: 'repeater',
label: 'Order lines',
rowLabel: (line) => line.product_name || undefined,
fields: [{ key: 'price', type: 'currency', label: 'Price' }],
},
];
A summary outside the form
When the submit control lives outside DXForm (a modal footer, a sticky
action bar), set error-summary="external" and render
DXFormErrorSummary beside the
button. Pass the form’s own resolved rows (errorTargets) and let a row click
drive the form through its exposed focusErrorTarget, so the summary and the
form agree on every row. "external" tells DXForm another summary lists the
failure, so it renders neither its own summary nor its form-level alert
(false would bring that alert back for a message-only failure, or once the
last field error is fixed: two alerts). DXTable’s create/edit modal does
exactly this.
<template>
<DXForm ref="formRef" :form="form" :fields="fields" :tabs="tabs"
:show-submit="false" error-summary="external" @submit="save" />
<footer>
<DXFormErrorSummary
:form="form" :fields="fields" :tabs="tabs"
:targets="formRef?.errorTargets ?? null"
@select-target="formRef?.focusErrorTarget($event)"
/>
<DButton variant="primary" @click="save">Save</DButton>
</footer>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { DButton, DXForm, DXFormErrorSummary } from '@omnitend/dashboard-for-laravel';
const formRef = ref<InstanceType<typeof DXForm> | null>(null);
// form, fields and tabs as for any DXForm.
const save = () => form.post('/api/orders').catch(() => {});
</script>
Container-driven layout
layout="horizontal" is unconditional, and that is a problem on a dashboard:
Bootstrap’s breakpoints are media queries, so they only ever see the
window. A page narrowed by the persistent sidebar — or a form inside a modal —
can have very little room while the viewport is wide, and no breakpoint fires.
The label/input split then cramps the labels and truncates the controls.
layout="auto" measures the form’s own container instead and stacks to
vertical below layoutThreshold:
<DXForm :form="form" :fields="fields" layout="auto" />
The default threshold is 640px. With the default 45% label column, 640 leaves
the label ~275px of text and the control column ~341px. Raise layoutThreshold
if your controls need more room, or set a narrower labelCols.
Notes:
vertical(the default) andhorizontalare unchanged and unconditional. No existing form changes appearance;autois opt-in.- Before the first measurement — and when server-rendering — the form renders vertical. A stacked form is legible at any width, so it is the safe thing to show when the width is not yet known.
- The crossing has a small hysteresis band, so a form that gains a scrollbar when it stacks cannot flip back and forth at the boundary.
- Per-field
field.layoutstill wins, and aspan: truefield is always full-width.
The measurement itself is available on its own — see useContainerWidth if you need to drive something else (a table that becomes cards, a column that collapses) off the same signal.
Field definitions
Each field is a FieldDefinition. Supported type values:
| Type | Renders |
|---|---|
text, email, password, number, url, tel, date, datetime-local, datetime, time | Native input |
textarea | Multi-line input |
select | Dropdown (sync options or async optionsLoader). Add searchable: true for a type-to-filter select that still models the option’s value |
autocomplete | Free-text input with a <datalist> of suggestions (sync options or async optionsLoader); accepts values not in the list |
radio | Radio group (single value from options) |
checkbox | Single checkbox (boolean) |
checkbox-group | Multiple checkboxes — “pick any of N” — from options; the model is an array of the checked option values (default the field to []) |
switch-list | A list of labelled toggle rows (allergens, feature flags, opt-ins) from options — each row a real form-grid group with a compact track switch. Same array model as checkbox-group. switchVariant: 'neutral' is usually right for lists (a wall of red-off toggles over-signals); per-row extras via #switch-list-item(<key>) |
currency, percentage | Numeric input with a £/% affix |
image, file | File input (image shows a preview) |
component | Renders your field.component (escape hatch) |
repeater | Nested, repeatable sub-form (see DXRepeater) |
Common options beyond key/type/label:
| Name Click to sort ascending | Type | Required Click to sort ascending | Default | Description |
|---|---|---|---|---|
label / hint | string | (model) => string | No | - | Static or model-derived label and hint text. |
info | string | (model) => string | No | - | PLAIN-TEXT help shown in the label's hover/focus popover — markup does not render, so links and lists are lost. For rich help (links, bulleted lists, bold), use the #info-popover(<key>) slot instead (or #info(<key>) for an always-visible block below the field). |
when | boolean | (model) => boolean | No | true | Conditional visibility, evaluated reactively against the live model. |
readonly | boolean | (model) => boolean | No | false | Render the field read-only — still a bordered, non-editable control. |
plaintext | boolean | (model) => boolean | No | false | Display the value as static text instead of a control (no border, no input box). Implies read-only for every type: anything backed by a real input (text family, textarea, currency, percentage, autocomplete) renders as static text; select/radio/checkbox/switch/file are disabled instead. |
revealable | boolean | No | true | Only for type: "password" — show the reveal (eye) toggle that switches the input between masked and plain text. Set false for a bare password input. |
disabled / disabledWhen | boolean | (model) => boolean | No | false | Disable the field, statically or from the model. |
searchable | boolean | No | false | For a select field: type to filter a long option list while the model still holds option.value (an id). Use for hundreds of options — a plain select is unusable at that size, and the autocomplete type models the typed text, so it cannot back a foreign key |
options / optionsLoader | FieldOption[] | (model) => Promise<FieldOption[]> | No | - | Select/radio options, synchronous or async. Set reloadOptionsOnChange to refetch on model change. |
submit | boolean | No | true | Include the field's value in the submitted payload. Set false for a PRESENTATIONAL field (a header, an alert, an explanatory block via span) that lays the form out but holds no data — DXTable's edit modal seeds its form from every editFields key, so those would otherwise be POSTed alongside the real ones |
rowLabel | (row, index) => string | null | undefined | No | - | For a repeater (or a span field rendering its own rows): the row's own name, which replaces "<label> (line N)" in the error summary. Empty or undefined keeps the line-number label. See "Naming a row in the summary" above. |
span | boolean | No | false | Render full-width, delegating content to the #span(<key>) slot. Also always bypasses horizontal layout's column split. |
layout / labelCols | "vertical" | "horizontal" / number | { sm?, md?, lg?, xl? } | No | - | Per-field override of DXForm's layout/labelCols props. |
append / prepend | string | (model) => string | No | - | Short unit text in an input-group cell after / before the input: "Online notice" with append "minutes", rather than "Online notice (minutes)" in the label. For number, text, email, url and tel fields; on a percentage, append replaces the "%" cell; on a currency, append is the unit the price is per ("per case") and prepend is not used (the symbol is currencySymbol). The input's aria-describedby names the cells. A plaintext field shows the value and its unit as text ("120 minutes"; nothing when empty). A field with neither renders exactly as before, with no input group. |
currencySymbol / accept / step / min / max | string | number | No | - | Type-specific options (currency symbol, file accept, numeric bounds). |
A FormTab is { key, label?, fieldKeys, when?, lazy? }. Tabs whose when
is false — or that have no visible fields and no custom tab slot — are hidden
automatically.
Extended Component
This is a custom component that extends beyond simple Bootstrap Vue Next wrappers, providing additional functionality specific to Laravel dashboards.