From 2cef14e8ccdb2b28dca55142ee9070005cb98c05 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 17:55:06 +0000 Subject: [PATCH 1/9] wip(fields): run lookupAutofill only on a lookup a record form stamped Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- .../form-field-channel-census-12130.test.tsx | 5 +- .../fields/src/widgets/LookupField.tsx | 52 ++++++++++++++++--- .../fields/src/widgets/lookupAutofill.ts | 46 +++++++++++++--- .../plugin-form/src/recordFormStamp.ts | 10 ++-- 4 files changed, 94 insertions(+), 19 deletions(-) diff --git a/ui/examples/schema-catalog/test/form-field-channel-census-12130.test.tsx b/ui/examples/schema-catalog/test/form-field-channel-census-12130.test.tsx index a24368cab4c..f8b44493d05 100644 --- a/ui/examples/schema-catalog/test/form-field-channel-census-12130.test.tsx +++ b/ui/examples/schema-catalog/test/form-field-channel-census-12130.test.tsx @@ -351,7 +351,10 @@ const LEDGER: Readonly> = { lookupAutofill: { readers: [LOOKUP], why: 'RUNTIME-ONLY (objectstack#28245) — object-field metadata (the spec\'s `FieldSchema.lookupAutofill`) read off the ' - + 'resolved `field` stash: which fields a pick fills is a fact about the object, not about one form.', + + 'resolved `field` stash: which fields a pick fills is a fact about the object, not about one form. Honoured only ' + + 'in a record form, which stamps the lookup (`withLookupAutofillTargets`), and in a line-item grid column; the key ' + + 'written on a standalone form node\'s field is read and not executed (the pick fills nothing, and a development ' + + 'build names the field), per ruling 7138010812.', }, recordBeingEdited: { readers: ['entry@fields/src/widgets/lookupRecordReference.ts'], diff --git a/ui/packages/fields/src/widgets/LookupField.tsx b/ui/packages/fields/src/widgets/LookupField.tsx index 4bbced04c66..dcd4a5b4265 100644 --- a/ui/packages/fields/src/widgets/LookupField.tsx +++ b/ui/packages/fields/src/widgets/LookupField.tsx @@ -69,6 +69,25 @@ import { ScanFieldButton, useFieldScanOffered } from './ScanFieldButton.js'; /** The record a host that edits none hands `{ $record }` resolution: nothing to read. */ const NO_EDITED_RECORD: Readonly> = Object.freeze({}); +const warnedAutofillRefused = new Set(); + +/** + * The development-build warning for a `lookupAutofill` this host does not + * run, said once per field: the pick then fills no other field, and the + * warning says why, so the author who wrote the key on a standalone form + * finds where it is honoured. + */ +function warnAutofillRefused(field: string): void { + if ((globalThis as { process?: { env?: { NODE_ENV?: string } } }).process?.env?.NODE_ENV === 'production') return; + if (warnedAutofillRefused.has(field)) return; + warnedAutofillRefused.add(field); + console.warn( + `[LookupField] lookupAutofill on "${field || '(unnamed)'}" is not executed here: a pick fills other fields only ` + + 'in a record form (the object\'s own lookup field) and in a line-item grid column. Declare lookupAutofill on ' + + 'the object field and draw the object\'s form; on a standalone form node the key is ignored.', + ); +} + export interface LookupOption { value: string | number; label: string; @@ -1222,9 +1241,24 @@ export function LookupField({ value, onChange, field, readonly, error: fieldErro * no `onSelectRecord` and supplies `onAutofill`, the writer for the sibling * fields of the record being edited. A host that owns the pick (the line-item * grid) applies the pairs itself. + * + * The pairs are an object fact, honoured where the object is read: a record + * form says so by the stamp it puts on every lookup declaring them + * (`withLookupAutofillTargets`, read by `readLookupAutofillTargets`). A + * lookup without that stamp — a standalone `form` node whose field carries + * the key written by hand — fills nothing, and a development build names + * the field once. */ - const autofillPairs: readonly LookupAutofillPair[] | undefined = + const declaredPairs: readonly LookupAutofillPair[] | undefined = !multiple && !onSelectRecord && props.onAutofill ? fieldMeta?.lookupAutofill : undefined; + const autofillTargets = declaredPairs?.length ? readLookupAutofillTargets(fieldMeta) : undefined; + const autofillPairs: readonly LookupAutofillPair[] | undefined = autofillTargets ? declaredPairs : undefined; + const refusedAutofillField = declaredPairs?.length && !autofillTargets + ? String(props.name || lookupField?.name || fieldMeta?.name || '') + : undefined; + useEffect(() => { + if (refusedAutofillField !== undefined) warnAutofillRefused(refusedAutofillField); + }, [refusedAutofillField]); const onAutofill = props.onAutofill; /** @@ -1238,10 +1272,12 @@ export function LookupField({ value, onChange, field, readonly, error: fieldErro * for the parent the record holds, as the amount box itself does. */ const { currency: homeCurrency } = useLocalization(); - const autofillTargets = autofillPairs?.length ? readLookupAutofillTargets(fieldMeta) : undefined; + // A stamp that names no target (the schema had not loaded, or no target is + // a field of the object) judges no currency: every value copies as before. + const currencyTargets = autofillTargets && Object.keys(autofillTargets).length > 0 ? autofillTargets : undefined; const followingTarget = useMemo( - () => (autofillTargets ? Object.values(autofillTargets).find((d) => recordCurrencyPath(d as never)) : undefined), - [autofillTargets], + () => (currencyTargets ? Object.values(currencyTargets).find((d) => recordCurrencyPath(d as never)) : undefined), + [currencyTargets], ); const { record: editedRecordForCurrency, state: followedParentState } = useFollowedParentRead( followingTarget as never, @@ -1254,17 +1290,17 @@ export function LookupField({ value, onChange, field, readonly, error: fieldErro // (`targetCurrencyUnread`). const followedParentPending = followedParentState === 'pending'; const followedParentUnread = followedParentState === 'unread'; - const autofillCurrency = !!autofillTargets; + const autofillCurrency = !!currencyTargets; /** The currency context of a pick of `row` (`crossCurrencyRefusal`), or none without stamped targets. */ const currencyFor = useCallback( (row: Record): AutofillCurrencyContext | undefined => { - if (!autofillTargets) return undefined; + if (!currencyTargets) return undefined; const sourceFields = (refObjectSchema as { fields?: Record } | null)?.fields; return { home: homeCurrency, sourceCurrency: (source, v) => pickedAmountCurrencyOf(sourceFields?.[source] as never, v, row), targetCurrency: (target, writes) => { - const def = autofillTargets[target]; + const def = currencyTargets[target]; if (followedParentUnread && recordCurrencyPath(def as never)) { return amountCurrencyOf(def as never) ? { kind: 'unread' } : undefined; } @@ -1272,7 +1308,7 @@ export function LookupField({ value, onChange, field, readonly, error: fieldErro }, }; }, - [autofillTargets, refObjectSchema, homeCurrency, editedRecordForCurrency, followedParentUnread], + [currencyTargets, refObjectSchema, homeCurrency, editedRecordForCurrency, followedParentUnread], ); /** What the last fill left empty, for the record it picked; said under the field. */ const [withheldFill, setWithheldFill] = useState<{ picked: string; items: readonly WithheldAutofill[] } | null>(null); diff --git a/ui/packages/fields/src/widgets/lookupAutofill.ts b/ui/packages/fields/src/widgets/lookupAutofill.ts index faf38ecb05a..83b9b5ba924 100644 --- a/ui/packages/fields/src/widgets/lookupAutofill.ts +++ b/ui/packages/fields/src/widgets/lookupAutofill.ts @@ -375,17 +375,42 @@ export function withheldAutofillMessage( * targets under, on the lookup's own field metadata: the widget receives one * field, not the object, and a target's currency is its definition's. The * same hand-off shape as `FOLLOWED_PARENT_OBJECT_KEY` (`currency.ts`). + * + * The stamp is also the record form's statement that the lookup is drawn + * for the record being edited, and so the one thing that lets a pick fill + * other fields at all ({@link readLookupAutofillTargets}): `lookupAutofill` + * is a fact about the object, honoured in a record form and a line-item grid + * column, and a pick in any other host fills nothing. + * + * ⛔ Only a stamp {@link withLookupAutofillTargets} issued counts: a value + * under this key that arrived as data (written by hand on a standalone form + * node's field, or anywhere else) is no stamp, whatever its shape. */ export const LOOKUP_AUTOFILL_TARGETS_KEY = 'lookupAutofillTargets'; +/** + * Every target map {@link withLookupAutofillTargets} issued. Membership is + * what makes the stamp the record form's statement rather than a document's: + * nothing parsed from JSON is ever in it. A copy of the field def keeps the + * map it carries, so the stamp survives every spread between the form and + * the widget. + */ +const ISSUED_TARGET_STAMPS = new WeakSet(); + /** * `def` with the definitions of its `lookupAutofill` targets stamped, read * off `fields` (the edited object's field map), each carrying the parent * object it follows when its currency follows a parent (ADR-0144 D2 as * amended). `labels` names each field as the form shows it (translated); * a target the form draws carries that name as its `label`, so a note about - * it names the field the way the form does. `def` itself when it declares no - * pairs or `fields` names none of its targets. + * it names the field the way the form does. Only a host that edits one + * record of the object calls this: the record form. + * + * A lookup that declares pairs is stamped even when `fields` names none of + * its targets (the schema is still loading, the form has no metadata source, + * a target is not a field of the map): the map is then empty, the pick + * copies with no currency to judge, and the stamp still says the lookup is + * drawn by a record form. `def` itself when it declares no pairs. */ export function withLookupAutofillTargets( def: T, @@ -393,22 +418,29 @@ export function withLookupAutofillTargets( labels?: Readonly>, ): T { const pairs = (def as { lookupAutofill?: unknown }).lookupAutofill; - if (!Array.isArray(pairs) || pairs.length === 0 || !fields) return def; + if (!Array.isArray(pairs) || pairs.length === 0) return def; const targets: Record = {}; for (const pair of pairs as LookupAutofillPair[]) { - const target = fields[pair?.target]; + const target = fields?.[pair?.target]; if (!target || typeof target !== 'object') continue; const stamped = withFollowedParentObject(target, fields); const shown = labels?.[pair.target]; targets[pair.target] = typeof shown === 'string' && shown !== '' ? { ...stamped, label: shown } : stamped; } - return Object.keys(targets).length > 0 ? { ...def, [LOOKUP_AUTOFILL_TARGETS_KEY]: targets } : def; + const stamp = Object.freeze(targets); + ISSUED_TARGET_STAMPS.add(stamp); + return { ...def, [LOOKUP_AUTOFILL_TARGETS_KEY]: stamp }; } -/** The target definitions a form stamped on `field`, or `undefined`. */ +/** + * The target definitions a record form stamped on `field` + * ({@link withLookupAutofillTargets}), possibly none, or `undefined` when no + * record form stamped it. A value under the key that + * {@link withLookupAutofillTargets} did not issue is no stamp. + */ export function readLookupAutofillTargets(field: unknown): Readonly>> | undefined { const value = (field as Record | null | undefined)?.[LOOKUP_AUTOFILL_TARGETS_KEY]; - return value && typeof value === 'object' && !Array.isArray(value) + return value && typeof value === 'object' && ISSUED_TARGET_STAMPS.has(value) ? (value as Record>) : undefined; } diff --git a/ui/packages/plugin-form/src/recordFormStamp.ts b/ui/packages/plugin-form/src/recordFormStamp.ts index 49d03fbcb6b..14d85243a29 100644 --- a/ui/packages/plugin-form/src/recordFormStamp.ts +++ b/ui/packages/plugin-form/src/recordFormStamp.ts @@ -31,14 +31,18 @@ * pick copies an amount only into a target in the same currency * (objectstack#36249), and a target's currency is its definition's. A * target the form draws carries the name the form shows for it, so the - * note about a target it did not fill names it the same way. + * note about a target it did not fill names it the same way. The stamp is + * written on every lookup declaring pairs, an empty one when the field map + * names none of its targets: it is also the form's statement that the pick + * may fill at all. * - The hosts this reaches are every record-form layout: `ObjectForm`'s * simple and sectioned arms, `TabbedForm`, `WizardForm`, `ModalForm` and * `DrawerForm`, and the forms drawn through `ObjectForm` (`MasterDetailForm`'s * header and line form, `EmbeddableForm`). A line-item grid judges its own * picks (`GridField`). A standalone `form` node drawn outside these hosts - * holds no object field map, is not stamped, and its lookup copies as it - * always did. + * holds no object field map and is not stamped, so a `lookupAutofill` + * written by hand on its field fills nothing: the pairs are an object fact, + * run where the object is read. */ import { RECORD_BEING_EDITED_KEY, withLookupAutofillTargets, withRecordBeingEdited } from '@object-ui/fields'; From 8ad28010b878645f8284d664f7d3dd9e121c927c Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 18:07:53 +0000 Subject: [PATCH 2/9] test(plugin-form): pin the standalone-form refusal, the record form and the grid column Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- ...ookupAutofillStandaloneForm-36923.test.tsx | 278 ++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 ui/packages/plugin-form/src/__tests__/lookupAutofillStandaloneForm-36923.test.tsx diff --git a/ui/packages/plugin-form/src/__tests__/lookupAutofillStandaloneForm-36923.test.tsx b/ui/packages/plugin-form/src/__tests__/lookupAutofillStandaloneForm-36923.test.tsx new file mode 100644 index 00000000000..b8772c7d132 --- /dev/null +++ b/ui/packages/plugin-form/src/__tests__/lookupAutofillStandaloneForm-36923.test.tsx @@ -0,0 +1,278 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * objectstack#36923 — `lookupAutofill` is an object fact, run where the object + * is read: a record form and a line-item grid column. A `lookupAutofill` + * written by hand on a field of a standalone `form` node is not run (ruling + * record 7138010812): the pick sets the lookup and copies nothing into other + * fields, and a development build names the field once. + * + * The widget tells a record form apart by the stamp the record form puts on + * every lookup that declares pairs (`withLookupAutofillTargets`, applied by + * `stampRecordFormFields` in the one step every layout draws through). The + * stamp is written even when the field map names none of the targets, and + * only a stamp the form issued counts: the key written as data is none. + * + * Pinned: a bare form node's pick fills nothing and warns once; a forged + * stamp opts nothing in; a record form still fills a same-currency amount and + * still withholds a cross-currency one (the cross-currency rule); a line-item + * grid column still fills. + */ +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { render, waitFor, fireEvent, screen, act, cleanup } from '@testing-library/react'; +import React from 'react'; + +import '@object-ui/components'; +import { + registerAllFields, + GridField, + preloadGridField, + LOOKUP_AUTOFILL_TARGETS_KEY, + readLookupAutofillTargets, + withLookupAutofillTargets, +} from '@object-ui/fields'; +import { SchemaRenderer, SchemaRendererContext, SchemaRendererProvider } from '@object-ui/react'; +import { LocalizationProvider } from '@object-ui/i18n'; +import { ObjectForm } from '../ObjectForm'; +import { stampRecordFormFields } from '../recordFormStamp'; + +registerAllFields(); + +afterEach(() => { + cleanup(); + vi.restoreAllMocks(); +}); + +const PAIRS = [ + { target: 'unit_price', source: 'list_price' }, + { target: 'description', source: 'summary' }, +]; + +const SCHEMAS: Record = { + fx_quote: { + name: 'fx_quote', + fields: { + currency_code: { type: 'text', label: 'Currency' }, + product: { type: 'lookup', label: 'Product', reference: 'fx_product', lookupAutofill: PAIRS }, + unit_price: { + type: 'currency', + label: 'Unit Price', + currencyConfig: { currencyMode: 'record', currencyField: 'currency_code' }, + }, + description: { type: 'text', label: 'Description' }, + }, + }, + fx_product: { + name: 'fx_product', + fields: { + name: { type: 'text', label: 'Name' }, + list_price: { type: 'currency', label: 'List Price' }, + summary: { type: 'text', label: 'Summary' }, + }, + }, +}; + +const PRODUCTS = [ + { id: 'p1', name: 'Widget', list_price: 100, summary: 'A widget' }, + { id: 'p2', name: 'Gadget', list_price: 250, summary: 'A gadget' }, +]; + +const makeDS = () => ({ + getObjectSchema: vi.fn(async (name: string) => SCHEMAS[name]), + find: vi.fn(async (_name: string, params?: { $filter?: { id?: { $in?: unknown[] } } }) => { + const wanted = params?.$filter?.id?.$in; + const rows = PRODUCTS.filter((r) => !wanted || wanted.includes(r.id)); + return { data: rows.map((r) => ({ ...r })), total: rows.length }; + }), + findOne: vi.fn(async (_name: string, id: string) => { + const row = PRODUCTS.find((r) => r.id === id); + return row ? { ...row } : null; + }), + create: vi.fn(async (_o: string, d: Record) => ({ id: 'q1', ...d })), + update: vi.fn(), +}); + +const valueOf = (c: HTMLElement, name: string) => + (c.querySelector(`input[name="${name}"]`) as HTMLInputElement | null)?.value ?? ''; + +async function settle(): Promise { + for (let i = 0; i < 6; i++) { + await act(async () => { + await new Promise((r) => setTimeout(r, 0)); + }); + } +} + +async function pick(trigger: HTMLElement, title: string): Promise { + await act(async () => { + fireEvent.click(trigger); + }); + const option = await waitFor(() => { + const el = screen.getAllByRole('option').find((o) => (o.getAttribute('title') ?? o.textContent ?? '').includes(title)); + if (!el) throw new Error(`${title} not offered`); + return el; + }, { timeout: 3000 }); + await act(async () => { + fireEvent.click(option); + }); + await settle(); +} + +/** The development-build warnings that name `field` as a `lookupAutofill` not run. */ +const refusals = (warn: ReturnType, field: string) => + warn.mock.calls.filter(([m]) => typeof m === 'string' && m.includes(`lookupAutofill on "${field}" is not executed`)); + +function renderBareForm(lookup: Record) { + const ds = makeDS(); + const view = render( + + + , + ); + return { ds, container: view.container, rerender: view.rerender }; +} + +describe('a standalone form node does not run a lookupAutofill written on its field (objectstack#36923)', () => { + it('a pick sets the lookup and copies nothing into other fields; a development build names the field once', async () => { + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + const { container } = renderBareForm({ + name: 'bare_product', + label: 'Product', + type: 'lookup', + reference: 'fx_product', + lookupAutofill: PAIRS, + }); + await pick(await screen.findByTestId('lookup-trigger-bare_product'), 'Widget'); + + await waitFor(() => expect(screen.getByTestId('lookup-trigger-bare_product').textContent).toContain('Widget')); + expect(valueOf(container, 'unit_price')).toBe(''); + expect(valueOf(container, 'description')).toBe(''); + expect(screen.queryByTestId('lookup-autofill-withheld')).toBeNull(); + + // A second pick: still nothing copied, and the field is named once only. + await pick(screen.getByTestId('lookup-trigger-bare_product'), 'Gadget'); + expect(valueOf(container, 'description')).toBe(''); + expect(refusals(warn, 'bare_product')).toHaveLength(1); + }); + + it('a lookupAutofillTargets key written by hand is no stamp: the pick still copies nothing', async () => { + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + const { container } = renderBareForm({ + name: 'forged_product', + label: 'Product', + type: 'lookup', + reference: 'fx_product', + lookupAutofill: PAIRS, + [LOOKUP_AUTOFILL_TARGETS_KEY]: { description: { type: 'text' }, unit_price: { type: 'number' } }, + }); + await pick(await screen.findByTestId('lookup-trigger-forged_product'), 'Widget'); + + await waitFor(() => expect(screen.getByTestId('lookup-trigger-forged_product').textContent).toContain('Widget')); + expect(valueOf(container, 'unit_price')).toBe(''); + expect(valueOf(container, 'description')).toBe(''); + expect(refusals(warn, 'forged_product')).toHaveLength(1); + }); +}); + +describe('the record-form stamp is the test, and it is written even when no target is in the field map (objectstack#36923)', () => { + const lookup = { name: 'product', type: 'lookup', reference: 'fx_product', lookupAutofill: PAIRS }; + + it('a lookup declaring pairs is stamped with no field map, and with a map that names none of its targets', () => { + for (const fields of [null, undefined, { other: { type: 'text' } }]) { + const targets = readLookupAutofillTargets(withLookupAutofillTargets(lookup, fields)); + expect(targets).toEqual({}); + } + const [stamped] = stampRecordFormFields([lookup], undefined) ?? []; + expect(readLookupAutofillTargets(stamped)).toEqual({}); + }); + + it('control: a field without pairs is not stamped, and the key written as data reads as no stamp', () => { + const plain = { name: 'account', type: 'lookup', reference: 'account' }; + expect(withLookupAutofillTargets(plain, SCHEMAS.fx_quote as never)).toBe(plain); + expect(readLookupAutofillTargets({ ...lookup, [LOOKUP_AUTOFILL_TARGETS_KEY]: {} })).toBeUndefined(); + }); +}); + +describe('a record form keeps running the object lookupAutofill, the cross-currency rule included (objectstack#36923)', () => { + function renderQuote(initialValues: Record) { + const ds = makeDS(); + const view = render( + + + + + , + ); + return { container: view.container }; + } + + it('a USD quote: the price and the description fill, with no note and no warning', async () => { + const warn = vi.spyOn(console, 'warn'); + const { container } = renderQuote({ currency_code: 'USD' }); + await pick(await screen.findByTestId('lookup-trigger-product'), 'Widget'); + + await waitFor(() => expect(valueOf(container, 'description')).toBe('A widget')); + await waitFor(() => expect(valueOf(container, 'unit_price')).toBe('100')); + expect(screen.queryByTestId('lookup-autofill-withheld')).toBeNull(); + expect(refusals(warn, 'product')).toHaveLength(0); + }); + + it('a EUR quote: the description fills, the price stays empty and the form says why', async () => { + const { container } = renderQuote({ currency_code: 'EUR' }); + await pick(await screen.findByTestId('lookup-trigger-product'), 'Widget'); + + await waitFor(() => expect(valueOf(container, 'description')).toBe('A widget')); + const note = await screen.findByTestId('lookup-autofill-withheld'); + expect(note.querySelector('[data-withheld-target="unit_price"]')).not.toBeNull(); + expect(valueOf(container, 'unit_price')).toBe(''); + }); +}); + +describe('a line-item grid column keeps running its pairs (objectstack#36923)', () => { + it('a cell pick fills the declared target', async () => { + await preloadGridField(); + const ds = makeDS(); + function Host() { + const [rows, setRows] = React.useState[]>([{ product: null, unit_price: null }]); + return ( + + []) => setRows(next)} + field={{ columns: [ + { name: 'product', type: 'lookup', reference: 'fx_product' }, + { name: 'unit_price', type: 'number' }, + ] } as never} + lookupAutofill={{ product: [{ target: 'unit_price', source: 'list_price' }] }} + /> + {JSON.stringify(rows)} + + ); + } + render(); + await pick(screen.getAllByTestId('lookup-trigger')[0], 'Widget'); + await waitFor(() => + expect(JSON.parse(screen.getByTestId('rows').textContent || '[]')[0]).toMatchObject({ product: 'p1', unit_price: 100 }), + ); + }); +}); From 5d21bceded01f757a8127bcabbe1432e242b8b04 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 18:09:15 +0000 Subject: [PATCH 3/9] chore(changeset): the standalone-form lookupAutofill refusal Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- ...36923-standalone-form-lookupautofill-refused.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .changeset/36923-standalone-form-lookupautofill-refused.md diff --git a/.changeset/36923-standalone-form-lookupautofill-refused.md b/.changeset/36923-standalone-form-lookupautofill-refused.md new file mode 100644 index 00000000000..f88db894a2e --- /dev/null +++ b/.changeset/36923-standalone-form-lookupautofill-refused.md @@ -0,0 +1,14 @@ +--- +'@object-ui/fields': patch +--- + +fix(fields): a `lookupAutofill` written by hand on a standalone form node's field is not run + +Clause-②: no +Metadata-protocol: none + +`lookupAutofill` is a fact about the object, and it runs where the object is read: in a record form and in a line-item grid column. A lookup on a standalone `form` node whose field carries `lookupAutofill` written by hand now fills nothing when a record is picked. The lookup itself is still set. Before, such a pick copied values into the other fields without the cross-currency rule, so an amount could be copied into a field in another currency with no note. A development build now warns once, naming the field and saying where the key is honoured. + +Record forms and grid columns behave as before, the cross-currency rule included. The widget recognises a record form by the stamp the record form puts on its lookups (`withLookupAutofillTargets`). That stamp is now written on every lookup that declares pairs, including when no target is a field of the loaded object, and only a stamp the record form issued counts. A `lookupAutofillTargets` key written as data is ignored. + +No metadata key is added or changed. Fix: declare `lookupAutofill` on the object's lookup field and draw the object's form. From 3cd52cd374f12abc9a38bddf46d2b3e5b0f6aaba Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 18:12:51 +0000 Subject: [PATCH 4/9] test(plugin-form): type the warning-call filter Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- .../src/__tests__/lookupAutofillStandaloneForm-36923.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/packages/plugin-form/src/__tests__/lookupAutofillStandaloneForm-36923.test.tsx b/ui/packages/plugin-form/src/__tests__/lookupAutofillStandaloneForm-36923.test.tsx index b8772c7d132..d75d0823620 100644 --- a/ui/packages/plugin-form/src/__tests__/lookupAutofillStandaloneForm-36923.test.tsx +++ b/ui/packages/plugin-form/src/__tests__/lookupAutofillStandaloneForm-36923.test.tsx @@ -125,8 +125,8 @@ async function pick(trigger: HTMLElement, title: string): Promise { } /** The development-build warnings that name `field` as a `lookupAutofill` not run. */ -const refusals = (warn: ReturnType, field: string) => - warn.mock.calls.filter(([m]) => typeof m === 'string' && m.includes(`lookupAutofill on "${field}" is not executed`)); +const refusals = (warn: { mock: { calls: unknown[][] } }, field: string) => + warn.mock.calls.filter(([m]: unknown[]) => typeof m === 'string' && m.includes(`lookupAutofill on "${field}" is not executed`)); function renderBareForm(lookup: Record) { const ds = makeDS(); From 6c1dfb34e0f4ce0235a921d545ec7f8f6556f9e5 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 18:25:30 +0000 Subject: [PATCH 5/9] test(plugin-form): a production build says nothing about the refused lookupAutofill Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- ...ookupAutofillStandaloneForm-36923.test.tsx | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ui/packages/plugin-form/src/__tests__/lookupAutofillStandaloneForm-36923.test.tsx b/ui/packages/plugin-form/src/__tests__/lookupAutofillStandaloneForm-36923.test.tsx index d75d0823620..e38a0cb67f0 100644 --- a/ui/packages/plugin-form/src/__tests__/lookupAutofillStandaloneForm-36923.test.tsx +++ b/ui/packages/plugin-form/src/__tests__/lookupAutofillStandaloneForm-36923.test.tsx @@ -172,6 +172,27 @@ describe('a standalone form node does not run a lookupAutofill written on its fi expect(refusals(warn, 'bare_product')).toHaveLength(1); }); + it('a production build copies nothing and says nothing', async () => { + vi.stubEnv('NODE_ENV', 'production'); + try { + const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); + const { container } = renderBareForm({ + name: 'prod_product', + label: 'Product', + type: 'lookup', + reference: 'fx_product', + lookupAutofill: PAIRS, + }); + await pick(await screen.findByTestId('lookup-trigger-prod_product'), 'Widget'); + + await waitFor(() => expect(screen.getByTestId('lookup-trigger-prod_product').textContent).toContain('Widget')); + expect(valueOf(container, 'description')).toBe(''); + expect(refusals(warn, 'prod_product')).toHaveLength(0); + } finally { + vi.unstubAllEnvs(); + } + }); + it('a lookupAutofillTargets key written by hand is no stamp: the pick still copies nothing', async () => { const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); const { container } = renderBareForm({ From ac3310d1cba19a34776ba12a982a5453b6eb1ce0 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 19:45:46 +0000 Subject: [PATCH 6/9] fix(fields): name the refused lookupAutofill field from the entry, not the field meta Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- ui/packages/fields/src/widgets/LookupField.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/packages/fields/src/widgets/LookupField.tsx b/ui/packages/fields/src/widgets/LookupField.tsx index dcd4a5b4265..01485cad8d7 100644 --- a/ui/packages/fields/src/widgets/LookupField.tsx +++ b/ui/packages/fields/src/widgets/LookupField.tsx @@ -1254,7 +1254,7 @@ export function LookupField({ value, onChange, field, readonly, error: fieldErro const autofillTargets = declaredPairs?.length ? readLookupAutofillTargets(fieldMeta) : undefined; const autofillPairs: readonly LookupAutofillPair[] | undefined = autofillTargets ? declaredPairs : undefined; const refusedAutofillField = declaredPairs?.length && !autofillTargets - ? String(props.name || lookupField?.name || fieldMeta?.name || '') + ? String(props.name || lookupField?.name || '') : undefined; useEffect(() => { if (refusedAutofillField !== undefined) warnAutofillRefused(refusedAutofillField); From 41cd6dada272abba9af6448c2ad1586b0667add0 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 19:49:59 +0000 Subject: [PATCH 7/9] chore(changeset): declare the readLookupAutofillTargets narrowing Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- .../36923-standalone-form-lookupautofill-refused.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.changeset/36923-standalone-form-lookupautofill-refused.md b/.changeset/36923-standalone-form-lookupautofill-refused.md index f88db894a2e..87e05af6ab5 100644 --- a/.changeset/36923-standalone-form-lookupautofill-refused.md +++ b/.changeset/36923-standalone-form-lookupautofill-refused.md @@ -4,11 +4,19 @@ fix(fields): a `lookupAutofill` written by hand on a standalone form node's field is not run -Clause-②: no +Clause-②: no (narrowing) Metadata-protocol: none + + `lookupAutofill` is a fact about the object, and it runs where the object is read: in a record form and in a line-item grid column. A lookup on a standalone `form` node whose field carries `lookupAutofill` written by hand now fills nothing when a record is picked. The lookup itself is still set. Before, such a pick copied values into the other fields without the cross-currency rule, so an amount could be copied into a field in another currency with no note. A development build now warns once, naming the field and saying where the key is honoured. Record forms and grid columns behave as before, the cross-currency rule included. The widget recognises a record form by the stamp the record form puts on its lookups (`withLookupAutofillTargets`). That stamp is now written on every lookup that declares pairs, including when no target is a field of the loaded object, and only a stamp the record form issued counts. A `lookupAutofillTargets` key written as data is ignored. No metadata key is added or changed. Fix: declare `lookupAutofill` on the object's lookup field and draw the object's form. + +**BREAKING** (`@object-ui/fields`, runtime export): `readLookupAutofillTargets(field)` now answers only for a target map that `withLookupAutofillTargets` issued. + +- FROM: `readLookupAutofillTargets(field)` returned any non-array object found under the field's `lookupAutofillTargets` key. +- TO: it returns only the map `withLookupAutofillTargets` stamped, which is what the record form does. A same-name key written by hand reads `undefined`. `withLookupAutofillTargets` now also stamps a lookup whose pairs name no field of the map it is given, with an empty map. Before, it returned the field unchanged. +- Fix: stamp the field through `withLookupAutofillTargets`, as the record form does. If you need the raw value, read `field.lookupAutofillTargets` directly. From 47d5f6956ca2a1dcf113d75cc3e2d90bd02ced69 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Nov 2026 22:28:47 +0000 Subject: [PATCH 8/9] docs(fields): name the record-form stamp on onAutofill; the changeset names the widget narrowing and what its marker rests on Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- .../36923-standalone-form-lookupautofill-refused.md | 10 ++++++++-- ui/packages/fields/src/widgets/types.ts | 6 +++++- ui/packages/plugin-grid/src/relationalMetaKeys.ts | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.changeset/36923-standalone-form-lookupautofill-refused.md b/.changeset/36923-standalone-form-lookupautofill-refused.md index 87e05af6ab5..839b76cebec 100644 --- a/.changeset/36923-standalone-form-lookupautofill-refused.md +++ b/.changeset/36923-standalone-form-lookupautofill-refused.md @@ -7,7 +7,7 @@ fix(fields): a `lookupAutofill` written by hand on a standalone form node's fiel Clause-②: no (narrowing) Metadata-protocol: none - + `lookupAutofill` is a fact about the object, and it runs where the object is read: in a record form and in a line-item grid column. A lookup on a standalone `form` node whose field carries `lookupAutofill` written by hand now fills nothing when a record is picked. The lookup itself is still set. Before, such a pick copied values into the other fields without the cross-currency rule, so an amount could be copied into a field in another currency with no note. A development build now warns once, naming the field and saying where the key is honoured. @@ -15,8 +15,14 @@ Record forms and grid columns behave as before, the cross-currency rule included No metadata key is added or changed. Fix: declare `lookupAutofill` on the object's lookup field and draw the object's form. +**BREAKING** (`@object-ui/fields`, the `lookup` and `master_detail` widgets): `LookupField` handed an `onAutofill` writer runs its field's `lookupAutofill` pairs only when the record form stamped the field. + +- FROM: a single-value pick filled the declared targets whenever the host handed `onAutofill` (and no `onSelectRecord`) and the field carried `lookupAutofill` pairs. +- TO: it also needs the stamp `withLookupAutofillTargets` issues, which the record form applies to every field it draws. A host that hands `onAutofill` without that stamp, such as a standalone `form` node, sets the lookup and fills nothing, and a development build warns once per field. +- Fix: stamp the field through `withLookupAutofillTargets` before handing it to the widget, as the record form does, or declare `lookupAutofill` on the object field and draw the object's record form. + **BREAKING** (`@object-ui/fields`, runtime export): `readLookupAutofillTargets(field)` now answers only for a target map that `withLookupAutofillTargets` issued. - FROM: `readLookupAutofillTargets(field)` returned any non-array object found under the field's `lookupAutofillTargets` key. -- TO: it returns only the map `withLookupAutofillTargets` stamped, which is what the record form does. A same-name key written by hand reads `undefined`. `withLookupAutofillTargets` now also stamps a lookup whose pairs name no field of the map it is given, with an empty map. Before, it returned the field unchanged. +- TO: it returns only the map `withLookupAutofillTargets` stamped, which is what the record form does. A same-name key written by hand reads `undefined`. `withLookupAutofillTargets` now also stamps a lookup whose pairs name no field of the map it is given, with an empty map. Before, it returned the field unchanged. The map it stamps is frozen, and a field with pairs always comes back as a copy. - Fix: stamp the field through `withLookupAutofillTargets`, as the record form does. If you need the raw value, read `field.lookupAutofillTargets` directly. diff --git a/ui/packages/fields/src/widgets/types.ts b/ui/packages/fields/src/widgets/types.ts index 1900e9cfa61..37f72de3e4b 100644 --- a/ui/packages/fields/src/widgets/types.ts +++ b/ui/packages/fields/src/widgets/types.ts @@ -286,7 +286,11 @@ export type FieldWidgetComponentProps = { * **Producer**: the form renderer, which owns the record's values. * **Consumer**: `LookupField`, on a single-value pick whose host owns no * `onSelectRecord` (a host that owns the pick, the line-item grid, applies - * the pairs itself). A lookup reached without it fills nothing. + * the pairs itself). A lookup reached without it fills nothing. A lookup + * reached with it fills only when the record form stamped the field + * (`withLookupAutofillTargets`, applied to every field the record form + * draws): a host that hands `onAutofill` without that stamp, such as a + * standalone `form` node, fills nothing either. * * `options.opening` marks the fill a create form's opening value made (see * {@link openingValue}): the filled values join what the form opened with, diff --git a/ui/packages/plugin-grid/src/relationalMetaKeys.ts b/ui/packages/plugin-grid/src/relationalMetaKeys.ts index e035a7818c5..6223e8db47d 100644 --- a/ui/packages/plugin-grid/src/relationalMetaKeys.ts +++ b/ui/packages/plugin-grid/src/relationalMetaKeys.ts @@ -383,7 +383,7 @@ export const RELATIONAL_META_READ_SET: Readonly Date: Wed, 25 Nov 2026 02:31:00 +0000 Subject: [PATCH 9/9] chore(changeset): the onAutofill banner names the opening fill and the field map the stamp needs Claude-Session: https://claude.ai/code/session_01QSeKYmRepQK9DkZeU7F53D Co-authored-by: Claude --- .changeset/36923-standalone-form-lookupautofill-refused.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.changeset/36923-standalone-form-lookupautofill-refused.md b/.changeset/36923-standalone-form-lookupautofill-refused.md index 839b76cebec..7a83b020976 100644 --- a/.changeset/36923-standalone-form-lookupautofill-refused.md +++ b/.changeset/36923-standalone-form-lookupautofill-refused.md @@ -17,9 +17,9 @@ No metadata key is added or changed. Fix: declare `lookupAutofill` on the object **BREAKING** (`@object-ui/fields`, the `lookup` and `master_detail` widgets): `LookupField` handed an `onAutofill` writer runs its field's `lookupAutofill` pairs only when the record form stamped the field. -- FROM: a single-value pick filled the declared targets whenever the host handed `onAutofill` (and no `onSelectRecord`) and the field carried `lookupAutofill` pairs. -- TO: it also needs the stamp `withLookupAutofillTargets` issues, which the record form applies to every field it draws. A host that hands `onAutofill` without that stamp, such as a standalone `form` node, sets the lookup and fills nothing, and a development build warns once per field. -- Fix: stamp the field through `withLookupAutofillTargets` before handing it to the widget, as the record form does, or declare `lookupAutofill` on the object field and draw the object's record form. +- FROM: a single-value pick, and the opening fill of a create form that opened with the lookup set, filled the declared targets whenever the host handed `onAutofill` (and no `onSelectRecord`) and the field carried `lookupAutofill` pairs. +- TO: it also needs the stamp `withLookupAutofillTargets` issues, which the record form applies to every field it draws. A host that hands `onAutofill` without that stamp, such as a standalone `form` node, sets the lookup and fills nothing, on a pick and on the opening fill alike, and a development build warns once per field. +- Fix: stamp the field through `withLookupAutofillTargets(field, objectFields)` before handing it to the widget, passing the object's field map as the record form does. With no map the stamp names no target, so the pick copies without the cross-currency rule, which is the copy this change stops. Or declare `lookupAutofill` on the object field and draw the object's record form. **BREAKING** (`@object-ui/fields`, runtime export): `readLookupAutofillTargets(field)` now answers only for a target map that `withLookupAutofillTargets` issued.