Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .changeset/34607-dialog-undeclared-columns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@object-ui/plugin-form': patch
---

feat(plugin-form): a form dialog with no declared `columns` spreads a field-heavy form to three columns, and to four in a `full` dialog

Clause-②: no
Metadata-protocol: none

A record dialog whose form declares no `columns` drew every form two fields per row, however many fields it had. On a wide screen a long business form left most of the dialog empty. The dialog now picks its column count from the number of fields it shows:

- **Up to eight fields:** two per row, as before.
- **Nine or more fields:** three per row, in the standard dialog sizes.
- **Sixteen or more fields in a `full` dialog** (`modalSize: 'full'`): four per row.

The bounded `xl` dialog stops at three because its field area is already wider than the four-column breakpoint. Columns still follow the dialog's real width, so a narrow dialog and a phone show one column. Sections and the object's field groups that declare no `columns` get the same count. Long text, rich text, markdown, html and inline grid fields still take a whole row.

A declared `columns`, including `1`, is drawn as written, on the form and on each section. The dialog's inferred size (`lg` or `xl`) is unchanged. Full-page, tabbed and wizard forms are unchanged: a section with no `columns` still draws two per row there.

If your forms declare `columns: 2` only to keep the old dialog layout, you can remove it to get the wider layout.
28 changes: 23 additions & 5 deletions ui/packages/plugin-form/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,29 @@ A sectioned form renders as ONE grid, and two keys decide its shape:
| a section's `columns` | how densely THAT section fills the grid (via per-field `colSpan`) |

The view's `columns` wins; without it the grid takes the widest section's
density, and without either it is single-column. Every sectioned host resolves it
the same way — `ObjectForm` (simple), `ModalForm`, `TabbedForm`, `WizardForm` —
so one piece of metadata lays out identically wherever it is
rendered. (`WizardForm` has no widest-section fallback: its steps never share a
viewport, so each step keeps its own authored width.)
density. Every sectioned host resolves it through the same rule
(`sectionedGridLayout`) — `ObjectForm` (simple), `ModalForm`, `TabbedForm`,
`WizardForm`. (`WizardForm` has no widest-section fallback: its steps never share
a viewport, so each step keeps its own authored width.)

A declared `columns` — on the view or on a section, `1` included — is drawn as
written on every host. Where neither the view nor a section declares one, the
count is the renderer's choice, and it differs by host:

| Host | Undeclared count |
|---|---|
| page hosts (`ObjectForm`, `TabbedForm`, `WizardForm`) | 2 per row (`UNDECLARED_SECTION_COLUMNS`) |
| the form dialog (`ModalForm`) | by field count: 2 for up to eight fields, 3 from nine; 4 from sixteen in a `full` dialog (`dialogUndeclaredColumns`) |

The dialog's count applies to a flat form, to undeclared sections and to the
object's `fieldGroups` alike. A bounded dialog (`lg` / `xl`) stops at 3 because
the `xl` dialog's field area already reaches the four-column container tier;
the fourth column is the `full` dialog's.

Every count is a container-query grid, so it is an upper bound: the form draws
as many columns as its container is wide enough for, and one column below the
`@md` tier (a phone, a narrow drawer). Wide field kinds (textarea, rich text,
markdown, html, an inline `grid`) and `span: 'full'` fields take the whole row.

The grid is applied to the field container **inside** the form, never wrapped
around the `<form>` (which would put the whole form in cell 1 and leave the other
Expand Down
129 changes: 78 additions & 51 deletions ui/packages/plugin-form/src/ModalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
filterSystemFields,
inferColumns,
inferModalSize,
dialogUndeclaredColumns,
sectionedFormColumns,
sectionedGridLayout,
CONTAINER_GRID_COLS,
Expand Down Expand Up @@ -310,25 +311,30 @@ const modalSizeClasses: Record<string, string> = {
};

/**
* How many fields per row the dialog draws where the author declared no
* `columns` (objectui#12521): two from the container's `@md` tier up, one
* below it, so the phone sheet keeps its single column. It rides the spec's
* own `columns` / `colSpan` path, so every field takes one cell — fields of
* one kind share one width — while a wide kind (`isWideFieldType`: textarea,
* rich text, markdown, html, an inline `grid`) and a `span: 'full'` field take
* the whole row. Line items never reach this grid: they arrive as `subforms`,
* which the master-detail arm below lays out across the dialog.
* The least grid the dialog draws where the author declared no `columns`
* (objectui#12521): two from the container's `@md` tier up, one below it, so
* the phone sheet keeps its single column. A field-heavy form draws more —
* three in a bounded dialog, four in a `full` one — by
* `dialogUndeclaredColumns` (objectstack-ai/objectstack#34607), whose
* docblock carries the rule and the measured tier.
*
* It applies to a flat form with no `columns`. A SECTION that declares no
* `columns` — the object's `fieldGroups` among them — gets the same count
* through the one sectioned-form rule, `sectionedGridLayout`
* (`UNDECLARED_SECTION_COLUMNS`), which every page host shares
* (objectui#12592): an undeclared section density is the renderer's choice,
* and a declared one — `1` included — is drawn as written (the
* section-`columns` fork on objectui#12521, ruled 6204264665).
* Every undeclared count rides the spec's own `columns` / `colSpan` path, so
* every field takes one cell — fields of one kind share one width — while a
* wide kind (`isWideFieldType`: textarea, rich text, markdown, html, an inline
* `grid`) and a `span: 'full'` field take the whole row. Line items never
* reach this grid: they arrive as `subforms`, which the master-detail arm
* below lays out across the dialog.
*
* The flat default is dialog-only on purpose: a flat page form, a drawer and
* the detail view keep `inferColumns`, which they mirror between them.
* It applies to a flat form with no `columns`, and to a SECTION that declares
* no `columns` — the object's `fieldGroups` among them — through the one
* sectioned-form rule, `sectionedGridLayout`, handed the dialog's count: an
* undeclared section density is the renderer's choice, and a declared one —
* `1` included — is drawn as written (the section-`columns` fork on
* objectui#12521, ruled 6204264665).
*
* The count is dialog-only on purpose: a sectioned page form keeps
* `UNDECLARED_SECTION_COLUMNS`, and a flat page form, a drawer and the detail
* view keep `inferColumns`, which they mirror between them.
*/
const DIALOG_DEFAULT_COLUMNS = UNDECLARED_SECTION_COLUMNS;

Expand Down Expand Up @@ -461,55 +467,71 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
[schema.sections, schema.objectName, schema.formType, objectSchema, dataSource],
);

// The fields a flat or field-group layout draws: system fields dropped, and
// in create mode the server-computed ones too — what `applyAutoLayout`
// filters (it filters again; the filters are idempotent). `customFields` is
// already merged into `formFields` (objectui#10073).
const layoutPool = useMemo(() => {
const fs = filterSystemFields(formFields, objectSchema);
return schema.mode === 'create' ? filterAutoGeneratedFields(fs, objectSchema) : fs;
}, [formFields, objectSchema, schema.mode]);

// Field-group fallback (object-designer metadata): when the caller passes no
// explicit sections, honor the object's declared `fieldGroups` the same way
// ObjectForm's simple path does — one section per group, with flat-path
// auto-layout parity (system/auto-generated fields filtered, the dialog's
// default columns, wide fields spanning the row). An explicit curated
// `sections` list from a form view always wins over this fallback.
// undeclared count, wide fields spanning the row). An explicit curated
// `sections` list from a form view always wins over this fallback. The
// groups carry no `columns` of their own: the arm that draws them reads the
// form's declared count, else the dialog's (objectstack-ai/objectstack#34607).
const derivedSections = useMemo(() => {
// `customFields` does NOT switch the fallback off (objectui#10073): the
// members are merged into `formFields` above, and ObjectForm derives its
// groups over that same merged pool.
if (schema.sections?.length) return null;
let fs = filterSystemFields(formFields, objectSchema);
if (schema.mode === 'create') fs = filterAutoGeneratedFields(fs, objectSchema);
const sections = deriveFieldGroupSections(fs, (objectSchema as any)?.fieldGroups, ungroupedLabel);
if (!sections) return null;
const columns = (clampColumns(schema.columns) ?? DIALOG_DEFAULT_COLUMNS) as 1 | 2 | 3 | 4;
const sections = deriveFieldGroupSections(layoutPool, (objectSchema as any)?.fieldGroups, ungroupedLabel);
// A member's definition reaches a group's body through `buildSectionFields`,
// the route an explicit section's takes (objectui#10254).
return sections.map((s) => ({ ...s, columns })) as ModalFormSectionConfig[];
}, [schema.sections, schema.columns, schema.mode, formFields, objectSchema, ungroupedLabel]);
return sections ? (sections as ModalFormSectionConfig[]) : null;
}, [schema.sections, layoutPool, objectSchema, ungroupedLabel]);

const effectiveSections = resolvedSections?.length ? resolvedSections : (derivedSections ?? undefined);

// Compute auto-layout for flat fields (no sections) to determine inferred columns
// (`customFields` does not switch it off: the members are merged into
// `formFields`, and ObjectForm auto-lays-out that merged list — objectui#10073.)
// A form that declares no `columns` lays out at the dialog's default
// (objectui#12521) through the same explicit-columns route an authored
// `columns` takes, so `applyAutoLayout` never infers 3–4 columns here.
const flatColumns = schema.columns ?? DIALOG_DEFAULT_COLUMNS;
const autoLayoutResult = useMemo(() => {
if (effectiveSections?.length) return null;
return applyAutoLayout(formFields, objectSchema, flatColumns, schema.mode);
}, [formFields, objectSchema, flatColumns, schema.mode, effectiveSections]);
// How many fields the dialog lays out — the input to its size and to its
// undeclared column count.
const layoutFieldCount = effectiveSections?.length
? effectiveSections.reduce((n, s) => n + (Array.isArray(s.fields) ? s.fields.length : 0), 0)
: layoutPool.length;

// The dialog's size when the author declared none (objectui#12521): bounded
// — `lg` or `xl`, never `full` — and chosen from the grid that renders and
// the field count, so a short form is not stretched across a wide dialog.
// An authored `modalSize` (including `'full'`) is used as written.
// — `lg` or `xl`, never `full` — and chosen from the declared grid and the
// field count, so a short form is not stretched across a wide dialog. An
// authored `modalSize` (including `'full'`) is used as written. An
// undeclared grid is at least `DIALOG_DEFAULT_COLUMNS` wide whatever the
// size, so the size reads that floor and never the count it then bounds
// (objectstack-ai/objectstack#34607).
const effectiveModalSize = useMemo(() => {
if (schema.modalSize) return schema.modalSize;
const columns = effectiveSections?.length
? sectionedFormColumns(schema.columns, effectiveSections.map((s) => s.columns))
: (autoLayoutResult?.columns ?? DIALOG_DEFAULT_COLUMNS);
const fieldCount = effectiveSections?.length
? effectiveSections.reduce((n, s) => n + (Array.isArray(s.fields) ? s.fields.length : 0), 0)
: (autoLayoutResult?.fields.length ?? 0);
return inferModalSize(Math.min(columns, inferColumns(fieldCount)));
}, [schema.modalSize, schema.columns, autoLayoutResult, effectiveSections]);
? sectionedFormColumns(schema.columns, effectiveSections.map((s) => s.columns), DIALOG_DEFAULT_COLUMNS)
: (clampColumns(schema.columns) ?? DIALOG_DEFAULT_COLUMNS);
return inferModalSize(Math.min(columns, inferColumns(layoutFieldCount)));
}, [schema.modalSize, schema.columns, effectiveSections, layoutFieldCount]);

// The count an undeclared form or section draws in THIS dialog
// (objectstack-ai/objectstack#34607): from the field count, bounded by the
// dialog's size — `dialogUndeclaredColumns`.
const undeclaredColumns = dialogUndeclaredColumns(layoutFieldCount, effectiveModalSize);

// Compute auto-layout for flat fields (no sections). A form that declares no
// `columns` lays out at the dialog's undeclared count through the same
// explicit-columns route an authored `columns` takes, so `applyAutoLayout`
// never runs the page's inference here.
const flatColumns = schema.columns ?? undeclaredColumns;
const autoLayoutResult = useMemo(() => {
if (effectiveSections?.length) return null;
return applyAutoLayout(formFields, objectSchema, flatColumns, schema.mode);
}, [formFields, objectSchema, flatColumns, schema.mode, effectiveSections]);

const sizeClass = modalSizeClasses[effectiveModalSize] || modalSizeClasses.default;

Expand Down Expand Up @@ -964,13 +986,18 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
sec.name ? sectionLabel(schema.objectName, sec.name, sec.label || sec.name) : sec.label;

// The form is ONE grid. Its width is the explicit form `columns`, else the
// widest section's count, an undeclared section counting two
// (objectui#12521, #12592); each section then lays ITS fields out at its
// widest section's count, an undeclared section counting the dialog's
// undeclared count (objectui#12521, #12592; objectstack-ai/objectstack#34607);
// each section then lays ITS fields out at its
// own count within that grid via colSpan (objectstack-ai/objectstack#2578), exactly like the
// full-page sectioned form — by the one sectioned-form rule, which
// switches to a 12-track grid when the sections' counts do not all fit
// the widest one (objectui#12548). It is handed the AUTHORED counts.
const sectionGrid = sectionedGridLayout(schema.columns, sections.map((sec) => sec.columns));
const sectionGrid = sectionedGridLayout(
schema.columns,
sections.map((sec) => sec.columns),
undeclaredColumns,
);
const formColumns = sectionGrid.columns;
const containerFieldClass = sectionGrid.fieldContainerClass;

Expand Down Expand Up @@ -1083,7 +1110,7 @@ const ModalFormBody: React.FC<ModalFormProps> = ({
// DrawerForm), so every group's fields share a single react-hook-form
// instance and the footer submit collects them all.
if (derivedSections?.length) {
const columns = (Number(derivedSections[0]?.columns) || 1) as 1 | 2 | 3 | 4;
const columns = (clampColumns(schema.columns) ?? undeclaredColumns) as 1 | 2 | 3 | 4;
const allFields: FormField[] = [];
derivedSections.forEach((section, index) => {
// FLS first, so a group whose every field is non-readable drops its
Expand Down
Loading
Loading