From 69bc61557f6408d3a4afab8caa86e3ef98ddffa8 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 18:50:51 +0000 Subject: [PATCH 1/3] fix(console): the form page lays sections out by the form view's own columns FormPage resolves each section's fields-per-row through plugin-form's sectionedGridLayout, the rule the Setup canvas, the dialog and the record form share: the form view's columns is the grid width and caps a section's count, and an undeclared section takes the form's count. Claude-Session: https://claude.ai/code/session_01Q4EjjQ8nXPvFqzfN7vdwxR Co-authored-by: Claude --- .../FormPage.formViewChrome-26843.test.tsx | 42 ++++++++++++++++ .../console/src/components/FormPage.test.ts | 49 +++++++++++++------ ui/apps/console/src/components/FormPage.tsx | 34 ++++++++++--- ui/packages/plugin-form/src/autoLayout.ts | 12 ++++- ui/packages/plugin-form/src/core.ts | 2 + ui/packages/plugin-form/src/index.tsx | 2 + 6 files changed, 118 insertions(+), 23 deletions(-) diff --git a/ui/apps/console/src/components/FormPage.formViewChrome-26843.test.tsx b/ui/apps/console/src/components/FormPage.formViewChrome-26843.test.tsx index f559c133e0d..9d805433666 100644 --- a/ui/apps/console/src/components/FormPage.formViewChrome-26843.test.tsx +++ b/ui/apps/console/src/components/FormPage.formViewChrome-26843.test.tsx @@ -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'; @@ -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('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]); + }); + } +}); diff --git a/ui/apps/console/src/components/FormPage.test.ts b/ui/apps/console/src/components/FormPage.test.ts index 496eab92391..0e83637259e 100644 --- a/ui/apps/console/src/components/FormPage.test.ts +++ b/ui/apps/console/src/components/FormPage.test.ts @@ -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'; @@ -13,7 +13,7 @@ import { buildSections, FORM_RECORD_ID_PARAM, FORM_RECORD_OBJECT_PARAM, - normalizeColumns, + declaredSectionColumns, normalizeOptions, readCreatedRecordId, readFormRecordTarget, @@ -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) => + buildSections({ type: 'simple', ...form } as any, 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]); }); }); diff --git a/ui/apps/console/src/components/FormPage.tsx b/ui/apps/console/src/components/FormPage.tsx index 53ff534f738..4292746928f 100644 --- a/ui/apps/console/src/components/FormPage.tsx +++ b/ui/apps/console/src/components/FormPage.tsx @@ -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 @@ -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; @@ -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}`. */ @@ -857,8 +870,17 @@ export function buildSections( objectDef: objectSchema, }, ) ?? []) as unknown as Array>; + // 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 = diff --git a/ui/packages/plugin-form/src/autoLayout.ts b/ui/packages/plugin-form/src/autoLayout.ts index ca6bc3b8a18..329baca52db 100644 --- a/ui/packages/plugin-form/src/autoLayout.ts +++ b/ui/packages/plugin-form/src/autoLayout.ts @@ -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 @@ -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, }; @@ -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) => { diff --git a/ui/packages/plugin-form/src/core.ts b/ui/packages/plugin-form/src/core.ts index 405a11f90ef..22e5fd16eb4 100644 --- a/ui/packages/plugin-form/src/core.ts +++ b/ui/packages/plugin-form/src/core.ts @@ -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'; diff --git a/ui/packages/plugin-form/src/index.tsx b/ui/packages/plugin-form/src/index.tsx index c18822cafd2..4e79295fcc6 100644 --- a/ui/packages/plugin-form/src/index.tsx +++ b/ui/packages/plugin-form/src/index.tsx @@ -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'; From 4077b920ec666491216ea232a4ceb0a8ae045936 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 18:59:14 +0000 Subject: [PATCH 2/3] test(console): pin form columns on named and public forms; changeset and liveness citation Claude-Session: https://claude.ai/code/session_01Q4EjjQ8nXPvFqzfN7vdwxR Co-authored-by: Claude --- .changeset/37665-form-page-form-columns.md | 13 +++++++++++++ packages/spec/liveness/view.json | 3 ++- ui/apps/console/src/components/FormPage.test.ts | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .changeset/37665-form-page-form-columns.md diff --git a/.changeset/37665-form-page-form-columns.md b/.changeset/37665-form-page-form-columns.md new file mode 100644 index 00000000000..799f1833ff5 --- /dev/null +++ b/.changeset/37665-form-page-form-columns.md @@ -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. diff --git a/packages/spec/liveness/view.json b/packages/spec/liveness/view.json index c6ab9045e6c..e18fc5779da 100644 --- a/packages/spec/liveness/view.json +++ b/packages/spec/liveness/view.json @@ -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", diff --git a/ui/apps/console/src/components/FormPage.test.ts b/ui/apps/console/src/components/FormPage.test.ts index 0e83637259e..ec73e2024fe 100644 --- a/ui/apps/console/src/components/FormPage.test.ts +++ b/ui/apps/console/src/components/FormPage.test.ts @@ -40,7 +40,7 @@ describe('declaredSectionColumns', () => { 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) => - buildSections({ type: 'simple', ...form } as any, objectSchema).map((s) => s.columns); + buildSections({ type: 'simple', ...form } as Parameters[0], objectSchema).map((s) => s.columns); 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]); From e663051fa15416cfa94b5d9a32647e36640524c2 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 19:33:46 +0000 Subject: [PATCH 3/3] docs(plugin-form): name the console form page among the sectioned layout's readers Claude-Session: https://claude.ai/code/session_01Q4EjjQ8nXPvFqzfN7vdwxR Co-authored-by: Claude --- ui/packages/plugin-form/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/packages/plugin-form/README.md b/ui/packages/plugin-form/README.md index 91cef3e4301..2842a6f70b7 100644 --- a/ui/packages/plugin-form/README.md +++ b/ui/packages/plugin-form/README.md @@ -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