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
13 changes: 13 additions & 0 deletions .changeset/37665-form-page-form-columns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@object-ui/plugin-form': patch
'@object-ui/console': patch
---

fix(console): a named or public form lays its sections out by the form view's own `columns`, as its Setup preview does

Clause-②: no
Metadata-protocol: none

- A form view's `columns` (the form body's column count) was drawn by the Setup preview and ignored by the published form: `/forms/:name` and `/f/:slug` read only each section's `columns`, defaulting to two. A form saved with `columns: 3` and undeclared sections previewed three across and published two across; a form with `columns: 1` and a `columns: 2` section previewed one column and published two.
- The form page now resolves each section's fields per row through `@object-ui/plugin-form`'s `sectionedGridLayout`, the rule the Setup canvas, the record dialog and the record form already share: the form view's `columns` is the grid width and caps a section's count, and a section that declares none takes the form's count. A form view without `columns` draws exactly as before.
- `@object-ui/plugin-form`: `sectionedGridLayout` and its `SectionedGridLayout` type are exported from the package root and from `/core`, and the layout gains `sectionColumns(declared)`, the count one section draws, for a host that draws each section on a grid of its own.
3 changes: 2 additions & 1 deletion packages/spec/liveness/view.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@
},
"columns": {
"status": "live",
"note": "objectui: ModalForm.tsx:247-258 / DrawerForm.tsx:478 applyAutoLayout column count."
"verifiedAt": "2026-11-26",
"note": "RE-CITED 2026-11-26 (#37665, ruling A on #37638): the form view's `columns` is the grid width of a sectioned form, capping each section's count; an undeclared section takes it. Readers: ui/apps/console/src/components/FormPage.tsx#buildSections, the named (`/forms/:name`) and public (`/f/:slug`) form page, and the Setup preview canvas, ui/packages/app-shell/src/views/metadata-admin/previews/ViewPreview.tsx#buildFormPreviewSchema handing it to ui/packages/plugin-form/src/ObjectForm.tsx; both resolve through ui/packages/plugin-form/src/autoLayout.ts#sectionedGridLayout. The previous ModalForm / DrawerForm citation was stale: those hosts no longer receive a stored form view."
},
"title": {
"status": "live",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
*
* CONTROL: a form view authoring neither keeps the page's own `Submit` /
* `Cancel` and opens blank.
*
* objectstack-ai/objectstack#37665 — the same class, one key: the form view's
* own `columns` is the grid width, as the Setup canvas draws it, on both
* routes. CONTROL: a form without it keeps the per-section layout.
*/

import { describe, expect, it, vi, afterEach } from 'vitest';
Expand Down Expand Up @@ -156,3 +160,41 @@ describe('the two helpers, directly', () => {
expect(readPrefill(fields, search, { title: 'Stored' }, { title: 'T' })).toStrictEqual({ title: 'Stored', channel: 'phone' });
});
});

/** Fields per row of each section grid, read off its class (`sm:grid-cols-N`; none = one). */
function sectionGridCounts(container: HTMLElement): number[] {
return Array.from(container.querySelectorAll<HTMLElement>('div.grid.grid-cols-1.gap-4')).map((el) => {
const m = /(?:^|\s)sm:grid-cols-(\d)(?:\s|$)/.exec(el.className);
return m ? Number(m[1]) : 1;
});
}

const TWO_SECTIONS = [{ fields: ['title'] }, { fields: ['channel'] }];

describe('FormPage lays sections out by the form view\'s own columns (#37665)', () => {
for (const [route, url] of [
['named', '/forms/showcase_inquiry.intake'],
['public', '/f/intake'],
] as const) {
it(`${route}: form \`columns: 1\` draws a \`columns: 2\` section in one column`, async () => {
vi.stubGlobal('fetch', stubFetch({ columns: 1, sections: [{ columns: 2, fields: ['title', 'channel'] }] }));
const { container } = renderAt(url);
await waitFor(() => expect(input('title')).not.toBeNull());
expect(sectionGridCounts(container)).toEqual([1]);
});

it(`${route}: form \`columns: 3\` draws undeclared sections three across`, async () => {
vi.stubGlobal('fetch', stubFetch({ columns: 3, sections: TWO_SECTIONS }));
const { container } = renderAt(url);
await waitFor(() => expect(input('title')).not.toBeNull());
expect(sectionGridCounts(container)).toEqual([3, 3]);
});

it(`${route}: CONTROL — no form \`columns\`: a declared section as written, an undeclared one at two`, async () => {
vi.stubGlobal('fetch', stubFetch({ sections: [{ columns: 1, fields: ['title'] }, { fields: ['channel'] }] }));
const { container } = renderAt(url);
await waitFor(() => expect(input('title')).not.toBeNull());
expect(sectionGridCounts(container)).toEqual([1, 2]);
});
}
});
49 changes: 33 additions & 16 deletions ui/apps/console/src/components/FormPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Pure-function tests for FormPage helpers. These cover the bulk of
* the renderer's spec-merging logic — buildSections, readPrefill,
* normalizeColumns, normalizeOptions — without needing a DOM.
* declaredSectionColumns, normalizeOptions — without needing a DOM.
*/

import { describe, expect, it } from 'vitest';
Expand All @@ -13,7 +13,7 @@ import {
buildSections,
FORM_RECORD_ID_PARAM,
FORM_RECORD_OBJECT_PARAM,
normalizeColumns,
declaredSectionColumns,
normalizeOptions,
readCreatedRecordId,
readFormRecordTarget,
Expand All @@ -23,24 +23,41 @@ import {
resolveSubmitBehavior,
} from './FormPage';

describe('normalizeColumns', () => {
it('passes through valid numeric literals', () => {
expect(normalizeColumns(1)).toBe(1);
expect(normalizeColumns(2)).toBe(2);
expect(normalizeColumns(3)).toBe(3);
expect(normalizeColumns(4)).toBe(4);
describe('declaredSectionColumns', () => {
it('reads the spec\'s string arm as the number its parse transforms it to', () => {
expect(declaredSectionColumns('1')).toBe(1);
expect(declaredSectionColumns('4')).toBe(4);
});

it('parses numeric strings', () => {
expect(normalizeColumns('1')).toBe(1);
expect(normalizeColumns('4')).toBe(4);
it('passes anything else through as written, defaulting nothing', () => {
expect(declaredSectionColumns(3)).toBe(3);
expect(declaredSectionColumns(undefined)).toBeUndefined();
expect(declaredSectionColumns('5')).toBe('5');
expect(declaredSectionColumns('foo')).toBe('foo');
});
});

describe('buildSections — a section draws what the shared layout rule answers (#37665)', () => {
const objectSchema = { name: 'lead', fields: { a: { type: 'text' }, b: { type: 'text' } } };
const counts = (form: Record<string, unknown>) =>
buildSections({ type: 'simple', ...form } as Parameters<typeof buildSections>[0], objectSchema).map((s) => s.columns);

it('defaults to 2 for invalid or missing values', () => {
expect(normalizeColumns(undefined)).toBe(2);
expect(normalizeColumns(0)).toBe(2);
expect(normalizeColumns(5)).toBe(2);
expect(normalizeColumns('foo')).toBe(2);
it('the form view\'s `columns: 1` caps a `columns: 2` section at one', () => {
expect(counts({ columns: 1, sections: [{ columns: 2, fields: ['a', 'b'] }] })).toEqual([1]);
});

it('the form view\'s `columns: 3` is what an undeclared section draws', () => {
expect(counts({ columns: 3, sections: [{ fields: ['a'] }, { fields: ['b'] }] })).toEqual([3, 3]);
});

it('a declared section narrower than the form keeps its own count', () => {
expect(counts({ columns: 3, sections: [{ columns: 1, fields: ['a'] }, { fields: ['b'] }] })).toEqual([1, 3]);
});

it('CONTROL: no form `columns` — each section as declared, an undeclared one at two', () => {
expect(
counts({ sections: [{ columns: 1, fields: ['a'] }, { columns: '3', fields: ['b'] }, { fields: [] }] }),
).toEqual([1, 3, 2]);
});
});

Expand Down
34 changes: 28 additions & 6 deletions ui/apps/console/src/components/FormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ import {
omitServerResolvedDefaults,
optionListDefault,
resolveSectionGroupReferences,
sectionedGridLayout,
} from '@object-ui/plugin-form/core';
// ADR-0059's published door for a host that renders field widgets OUTSIDE the
// form renderer: `resolveFormWidgetType` + `getLazyFieldWidget` hand back the
Expand Down Expand Up @@ -631,6 +632,14 @@ interface RenderableSection {
* and the renderer draws it as it arrives, the way `ObjectForm` draws its own.
*/
description?: string;
/**
* Fields per row this section DRAWS (objectstack-ai/objectstack#37665): the
* answer of `@object-ui/plugin-form`'s `sectionedGridLayout`, the rule the
* Setup canvas, the dialog and the record form share. The form view's own
* `columns` is the grid width and caps the section's count; an undeclared
* section takes the form's count; with neither declared it is the shared
* undeclared count, which is what this page always drew.
*/
columns: 1 | 2 | 3 | 4;
collapsible: boolean;
collapsed: boolean;
Expand Down Expand Up @@ -663,11 +672,15 @@ interface RenderableSection {

// ─── Helpers ─────────────────────────────────────────────────────────

/** Coerce a `columns` literal into a numeric 1..4. */
export function normalizeColumns(c: unknown): 1 | 2 | 3 | 4 {
const n = typeof c === 'string' ? parseInt(c, 10) : (c as number);
if (n === 1 || n === 2 || n === 3 || n === 4) return n;
return 2;
/**
* A section's DECLARED `columns`, as the shared layout rule reads it: the
* spec's `'1'`–`'4'` string arm as the number `FormSectionSchema`'s parse
* transforms it to (a document that reached this page without that parse
* still says what its author wrote), anything else as written. Nothing is
* defaulted here: an undeclared count resolves in `sectionedGridLayout`.
*/
export function declaredSectionColumns(c: unknown): unknown {
return typeof c === 'string' && /^[1-4]$/.test(c) ? Number(c) : c;
}

/** Normalize field options from various Object schema shapes into `{value,label}`. */
Expand Down Expand Up @@ -857,8 +870,17 @@ export function buildSections(
objectDef: objectSchema,
},
) ?? []) as unknown as Array<FormSectionSpec & Pick<ObjectFormSection, 'visibleWhenFault'>>;
// objectstack-ai/objectstack#37665: the form view's own `columns` is the
// grid width and every section's count is resolved against it by the one
// rule the Setup canvas draws with, so the published page and its preview
// agree. Each section here is a grid of its own, so the page reads the
// per-section count rather than the shared field grid.
const grid = sectionedGridLayout(
form.columns,
sections.map((sec) => declaredSectionColumns(sec.columns)),
);
return sections.map((sec) => {
const cols = normalizeColumns(sec.columns);
const cols = grid.sectionColumns(declaredSectionColumns(sec.columns)) as 1 | 2 | 3 | 4;
const fields: RenderableField[] = [];
for (const entry of sec.fields ?? []) {
const override: FormFieldSpec =
Expand Down
5 changes: 4 additions & 1 deletion ui/packages/plugin-form/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,10 @@ The view's `columns` wins; without it the grid takes the widest section's
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 viewport, so each step keeps its own authored width.) The console's named and
public form page (`/forms/:name`, `/f/:slug`) draws each section on a grid of its
own and reads the same rule's per-section count, `sectionColumns(declared)`: the
view's `columns` caps a section, and an undeclared section takes it.

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
Expand Down
12 changes: 11 additions & 1 deletion ui/packages/plugin-form/src/autoLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,21 @@ export interface SectionedGridLayout {
columns: 1 | 2 | 3 | 4;
/** The field container's grid classes; `undefined` for a one-column form. */
fieldContainerClass: string | undefined;
/**
* How many fields per row ONE section draws, given its DECLARED `columns`
* (`undefined` when none): its own count, else the form's, else the
* undeclared count, clamped to {@link columns}. A host that draws each
* section on a grid of its own reads this instead of the shared field grid.
*/
sectionColumns: (sectionColumns?: unknown) => number;
/** Lay one section's fields out at that section's DECLARED `columns` (`undefined` when none). */
layOut: (fields: FormField[], sectionColumns?: unknown) => FormField[];
}

/**
* The ONE layout rule of a sectioned form — `ModalForm`, `ObjectForm`,
* `TabbedForm` and `WizardForm` all call it (objectui#12548).
* `TabbedForm` and `WizardForm` all call it (objectui#12548), and the
* console's named and public form page reads its {@link SectionedGridLayout.sectionColumns}.
*
* Every section shares the form's single field grid (one form, one
* react-hook-form instance — #2153/#2959), and every authored section must
Expand Down Expand Up @@ -518,6 +526,7 @@ export function sectionedGridLayout(
return {
columns: grid,
fieldContainerClass: containerGridColsFor(grid),
sectionColumns: density,
layOut: (fields, declared) =>
grid > 1 ? applyAutoColSpan(fields, grid, density(declared)) : fields,
};
Expand All @@ -526,6 +535,7 @@ export function sectionedGridLayout(
return {
columns: grid,
fieldContainerClass: TWELVE_TRACK_GRID_COLS,
sectionColumns: density,
layOut: (fields, declared) => {
const d = density(declared);
return fields.map((field) => {
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/plugin-form/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export {
isAutoGeneratedFieldType,
containerGridColsFor,
filterSystemFields,
sectionedGridLayout,
} from './autoLayout';
export type { SectionedGridLayout } from './autoLayout';
export { resolveInlineMode } from './deriveMasterDetail';
export type { InlineMode } from './deriveMasterDetail';
export { omitServerResolvedDefaults, optionListDefault } from './schemaDefaults';
Expand Down
2 changes: 2 additions & 0 deletions ui/packages/plugin-form/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export {
filterCreateModeFields,
filterSystemFields,
filterAutoGeneratedFields,
sectionedGridLayout,
} from './autoLayout';
export type { SectionedGridLayout } from './autoLayout';
export { TabbedForm } from './TabbedForm';
export type { TabbedFormProps, TabbedFormSchema, FormSectionConfig } from './TabbedForm';
export { WizardForm } from './WizardForm';
Expand Down
Loading