Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit ccddd11

Browse files
fix(plugin-form): a create form preselects the option a field marks default: true (objectui#11914) (#11944)
Fixes #11914 Clause-②: no ## What changes A create form preselects the option a field's option list marks `default: true`, when the field declares no `defaultValue`. This is the rule the server's insert path applies when a create omits the field. The objectstack tutorial's Create Ticket form now opens with Priority = Low and Status = Open, and submits without a manual pick. **Where.** The fix is in `packages/plugin-form/src/schemaDefaults.ts`, in `schemaDefaultValues`. That is the one function every object-form container seeds a create form through (`ObjectForm` directly; `ModalForm`, `DrawerForm`, `TabbedForm`, `SplitForm` and `WizardForm` through `seedCreateValues`). A new module-private `optionListDefault` reads the option list. No second derivation was added in the select widget. ## Measured first, on `main` `f1781be3a` (H0) The new pin was run against the unchanged source. It rendered the console's create dialog (the global `ModalForm`) on the tutorial's ticket object, verbatim. 11 of 17 tests failed. The main failure: `AssertionError: expected 'Select an option' to contain 'Low'`. On `main`, `schemaDefaultValues` returns `{}` for that object, so the premise holds on current `main`. The module docblock said it deliberately ignored the option flag "because the server reads `defaultValue` alone". That stopped being true when the engine began falling back to the marked option (objectstack#7246). Bound: H0 rendered the real `ModalForm`, `ObjectForm` and field widgets with React Testing Library. It did not drive a booted console in a browser against a live backend. ## The rule: the engine's, read client-side (H1, H2, H3) This is a read-only check of objectstack `ObjectQL.applyFieldDefaults` / `resolveOptionDefault` and its test `engine-select-option-default.test.ts`. The client applies the same rule: | Declared | Server stores on omit | Create form now opens with | |---|---|---| | option `default: true`, no `defaultValue` | the marked option | the marked option | | static `defaultValue` + option flag | `defaultValue` | `defaultValue` (unchanged) | | runtime `defaultValue` (`NOW()`, `current_user`, CEL) + option flag | the resolved token | empty, key omitted (unchanged; the flag is NOT seeded in its place) | | `defaultValue: null` + option flag | the marked option (`== null` presence test) | the marked option | | several marked, single-valued | the first | the first | | marked on a multi-valued field (`isMultiValueField`: `multiselect`, or `select` + `multiple`) | every marked option, as an array | every marked option, as an array | | `multiple: true` on a type outside the multi sets | a scalar | a scalar | | option value spelled `current_user` | that literal | that literal | | marked option with no value | nothing | nothing | The client asks `@objectstack/spec`'s `isMultiValueField` for the arity, which is the engine's own predicate. It never reads `multiple` raw. Only the canonical `default` key is read: the spec's alias layer normalizes `isDefault` / `selected` before metadata is served. What does not change: - A caller seed (`initialData` / `initialValues`) and the user's own pick still win. - Edit forms are never seeded: they show the stored record. - `omitServerResolvedDefaults` and `isRequiredInForm` are untouched. An option value is a static literal, so it is submitted like any other seeded value, and a required field the user clears is still refused. ## Public surface: unchanged `schemaDefaultValues` and `seedCreateValues` are not on the package entry. They now take a package-local `SeedSchemaLike`, derived from the published `FieldDefaultsSchemaLike` plus `options` / `multiple`. The published `FieldDefaultsSchemaLike` keeps exactly its three pinned members (`parameterTypesNameable-7324.test.ts` passes). No export, prop, type member or `packages/i18n` key changes. That is why the PR declares `Clause-②: no`. ## Pins and ablation `packages/plugin-form/src/__tests__/optionDefaultSeed-11914.test.tsx`, 19 tests: - `schemaDefaultValues` unit cases for every row of the table above, plus the control: options that mark nothing seed nothing. - `ModalForm` (console create dialog), on the tutorial ticket object: - Priority and Status are preselected and submitted without a pick; - control: a select that marks nothing stays on its placeholder; - the user's pick through the control wins; - a caller seed wins; - a `multiselect` preselects every marked option (`aria-pressed`); - an edit form over a row that leaves the key absent is not seeded. - `ObjectForm` (page-mode create): preselected on create, not applied on edit. **Ablation**, run after the fix was committed: `scripts/ablation-replace.mjs` (objectstack) replaced `const fromOptions = optionListDefault(f);` with an `undefined` assignment. - The mutation landed: anchor x1 to x0, blob `a8807e5e` to `bd538283`. - The pin turned red: 11 failed, 6 passed. These are the same 11 that failed on `main`. - The restore is proven: blob equals HEAD, and `git diff HEAD` is empty. - The tests import source through the root vitest alias, so no `dist/` is on the measured path. ## Eager closure (Bundle Analysis) `plugin-form` is eager, so this was measured under the verify lock. The console `vite build` ran twice from the same worktree, plus `check-eager-closure-budget.mjs`. The head build was at `27be779f7`. The base build was the same tree with `schemaDefaults.ts` reverted to `f1781be3a`; the restore was proven by blob. | | eager gzip bytes | gate verdict | |---|---|---| | base (`f1781be3a`) | 3,385,951 | green, headroom 0.4 KB | | head | 3,386,104 | green, headroom 0.3 KB | | **delta** | **+153 gzip** (+379 raw) | | The growth is in the `plugin-form` chunk (+154 gzip). Other chunks moved by 1 to 3 bytes from hashed import names. The `vendor-objectstack` chunk did not move, so `isMultiValueField` was already in the closure. The change is kept minimal. Note: `main` `19a7348` is already a few bytes over the 3307.0 KB ceiling (the seat's main-red card, objectui#11937). This PR's `Bundle Analysis` is expected red until that card's change lands. It is not addressed here, and `scripts/check-eager-closure-budget.mjs` is untouched. ## Docs `packages/plugin-form/README.md`, "What a create form opens with": - The table row "an option's `default: true`: empty" is replaced. - So is the paragraph that said only the field-level `defaultValue` is read. Both sentences became false with this change. **This file is outside the claim's file surface.** It was edited because the code change made a published sentence false, and the objectui `AGENTS.md` docs-driven rule (#2) applies. The report names it as a deviation; it can be dropped from the branch if the seat rules otherwise. No sentence under `content/docs/**` or `skills/**` covers select defaults on create forms. A grep for the option flag and for create-form defaults found only `defaultValue` docs about other components. ## Acceptance notes (not changed here) - **The second form chain.** `apps/console/src/components/FormPage.tsx` serves `/forms/:name` and `/f/:slug`. It seeds through its own `readPrefill`, which still reads `defaultValue` alone, so an option-default select there would still open empty. This is a reading of the code, not a measured failure. It is outside this claim's surface (`apps/console`). Sharing the rule would need a published helper, which would be a `Clause-②` question. Carrier: none named; left to the seat. - Kanban `InlineQuickAdd` and the calendar's quick-create payload read `defaultValue` the same way. They were not measured, and no carrier is named. ## Gates, at head `6da0e6e0b` - `pnpm exec vitest run` on: - the new pin; - the five existing tests that import `schemaDefaults` (`createDefaults`, `currentUserDefault`, `entrySurface-6059`, `initialRecordMerge-9760`, `parameterTypesNameable-7324`); - `column-identity.ratchet.test.ts`. Result: `Test Files 7 passed (7)`, `Tests 141 passed (141)`. - `pnpm --filter @object-ui/plugin-form type-check` (`tsc --noEmit && tsc -p tsconfig.test.json`) exits 0, after building the `@object-ui/plugin-form^...` closure. `--listFiles` counts the new test once. - `pnpm exec eslint` on the two touched source/test files: 2 files, 0 errors, 0 warnings. ESLint config has no type-aware linting, so untouched files cannot change verdict. - All exit 0: - `node scripts/check-changeset-presence.mjs` - `node scripts/check-changeset-no-major.mjs` - `node scripts/check-changeset-overwrite.mjs` - `pnpm check:changeset-claims` - `pnpm check:pending-changeset-literals` - `pnpm check:spec-symbols` - `pnpm check:new-line-citations` (0 new) - `pnpm check:control-bytes` - `node scripts/check-test-path-roots.mjs` - `node scripts/check-vi-mock-override-shape.mjs` - `node scripts/check-doc-links.mjs` - Not run locally (CI): the repo-wide `pnpm lint` / `pnpm check`, `readme-exports` (no export list changed) and `doc-snippet-types` (no code fence added). Changeset: `.changeset/11914-select-option-default.md`, `@object-ui/plugin-form` patch. Session: `https://claude.ai/code/session_01MgfduSkFrfM3eorB3UGfAU` --- _Generated by [Claude Code](https://claude.ai/code/session_01MgfduSkFrfM3eorB3UGfAU)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent e44f9bc commit ccddd11

4 files changed

Lines changed: 489 additions & 26 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@object-ui/plugin-form': patch
3+
---
4+
5+
A create form preselects the option a field's option list marks `default: true` (objectui#11914).
6+
7+
A `select` field that declares no `defaultValue` but marks one option `default: true` opened on the "Select an option" placeholder in every object-form container, the console's create dialog included. The server stores the marked option when a create omits the field, so the objectstack tutorial's Create Ticket form showed Priority and Status empty and could not be submitted until the user picked the values the metadata had already chosen.
8+
9+
The create form now reads the option list the way the server's insert path does:
10+
11+
- only when the field declares no `defaultValue`. A field-level default, static or runtime, always wins, and the option flag is then not seeded;
12+
- a single-valued field takes the first marked option;
13+
- a multi-valued field (`multiselect`, or `select` with `multiple: true`) takes every marked option, as an array.
14+
15+
A value the caller seeds or the user picks still wins. Edit forms are unchanged: they show the stored record.
16+
17+
Nothing is added to the package entry: no export, prop or type member.

‎packages/plugin-form/README.md‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ the form looks validated while validating nothing.
273273
### What a create form opens with
274274

275275
A create form has no persisted record, so its opening values come from the
276-
object schema's declared field `defaultValue`s. Every object-form container
276+
object schema's declared defaults: a field's `defaultValue`, or the option its
277+
option list marks `default: true`. Every object-form container
277278
(`ObjectForm`, `ModalForm`, `DrawerForm`, `TabbedForm`, `SplitForm`,
278279
`WizardForm`) resolves them the same way, through `schemaDefaults`:
279280

@@ -282,20 +283,22 @@ object schema's declared field `defaultValue`s. Every object-form container
282283
| `defaultValue: 'draft'` (any static literal) | `draft`, preselected and submittable | the value is known; making the user pick it is busywork, and on a status-like field every wrong option is one click away |
283284
| `defaultValue: 'NOW()'` / `'current_user'` (a runtime token) | empty | the token is an *instruction*, not a value. The server resolves it at insert — but only for fields that arrive empty, so seeding the literal text would suppress it |
284285
| `defaultValue: cel\`today()\`` (an Expression envelope) | empty | same reason: the server evaluates it per insert |
285-
| an option's `default: true` | empty | see below |
286+
| an option's `default: true`, and no `defaultValue` | that option, preselected and submittable | the server stores the marked option when the field is omitted; see below |
286287
| nothing | empty | no default is invented |
287288

288289
`initialData` / `initialValues` passed by the caller always outrank a schema
289290
default — a lookup prefill or a "duplicate this record" seed is the more
290291
specific instruction.
291292

292-
Only the **field-level** `defaultValue` is read, never a select option's
293-
`default: true`, even though `@objectstack/spec`'s `SelectOptionSchema` declares
294-
that key. The server's insert path resolves `defaultValue` and nothing else, so
295-
a form that also seeded from option-level `default` would preselect values the
296-
server would never have applied on its own — a renderer-side second default
297-
contract (AGENTS.md #0.1). If option-level `default` is meant to mean "the
298-
initial value", that belongs at the producer.
293+
An option's `default: true` is read the way the server's insert path reads it
294+
(`ObjectQL.applyFieldDefaults`, which falls back to the marked option), so the
295+
form preselects exactly what omitting the field would store:
296+
297+
- only when the field declares no `defaultValue` — a field-level default,
298+
static or runtime, always wins, and the flag is then not seeded at all;
299+
- a single-valued field takes the **first** marked option;
300+
- a multi-valued field (`@objectstack/spec`'s `isMultiValueField`: `multiselect`,
301+
or `select` with `multiple: true`) takes **every** marked option, as an array.
299302

300303
**Edit forms are never seeded.** An edit form shows the row as the server holds
301304
it; folding a default in over a column the record leaves unset would arm a

0 commit comments

Comments
 (0)