From 57e988ac2247a28ed81a799fb0fb47fa1fa67e4e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 07:41:45 +0000 Subject: [PATCH 1/3] fix(fields): the fill-in dialog judges option visibleWhen on the record the write would leave The required-fields fill-in dialog rendered each control with no record, so an option visibleWhen reading the field the change writes (a loss reason shown only while stage is closed_lost) was judged on an empty record and every option was hidden. The collector already judges the prompt on the stored record merged with the change; each returned field now carries that record, and the dialog hands it, with the values typed so far, to every control as dependentValues. Claude-Session: https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ Co-authored-by: Claude --- .../37250-fill-in-dialog-pending-options.md | 16 ++++ .../fields/src/RequiredFieldsDialog.tsx | 11 +++ ...equiredFieldsDialog.inPlace-35956.test.tsx | 91 +++++++++++++++++++ ui/packages/fields/src/requiredWhenPrompt.ts | 12 ++- 4 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 .changeset/37250-fill-in-dialog-pending-options.md diff --git a/.changeset/37250-fill-in-dialog-pending-options.md b/.changeset/37250-fill-in-dialog-pending-options.md new file mode 100644 index 00000000000..0e7d006ba16 --- /dev/null +++ b/.changeset/37250-fill-in-dialog-pending-options.md @@ -0,0 +1,16 @@ +--- +'@object-ui/fields': patch +--- + +fix(fields): the required-fields fill-in dialog offers the options the change makes available + +Clause-②: no +Metadata-protocol: none + +When a change in place (a stage move on the record page, a list cell, an inline edit, a kanban drop) makes another field required, the fill-in dialog asks for it. A choice field there could show "No options available" and the change could not be saved. This happened when the field's options are each shown only for some values of the field the change writes. Example: every loss reason is shown only while the stage is "closed lost". Moving an opportunity to "closed lost" asked for a loss reason and offered none. + +The dialog now judges each option's `visibleWhen` against the record as the write would leave it: the saved record, the change, and the values typed into the dialog so far. So the loss reasons appear, and an option that depends on another value typed into the dialog appears once that value is typed. Options that are not visible on that record stay hidden. The same record already decided which fields the dialog asks for, so the fields asked for do not change. + +For hosts: each field `collectRequiredWhenPromptFields` returns now carries `record`, the record it was judged against. The dialog hands it, with the typed values, to every control as `dependentValues`. A row a host builds itself (a field a refusal names) reads the same record when the dialog has a field that carries one. + +No metadata key, value or default changes. diff --git a/ui/packages/fields/src/RequiredFieldsDialog.tsx b/ui/packages/fields/src/RequiredFieldsDialog.tsx index 41411824a26..7a3f7f9bf77 100644 --- a/ui/packages/fields/src/RequiredFieldsDialog.tsx +++ b/ui/packages/fields/src/RequiredFieldsDialog.tsx @@ -188,6 +188,16 @@ export function RequiredFieldsDialog({ shown.push(f); } const missing = shown.filter((f) => isMissingForRequired(values[f.name])); + // The record every control here resolves its options against + // (objectstack#37250): the record the prompt judged its fields on (the + // stored record with the change merged in, carried on each field + // `collectRequiredWhenPromptFields` returns) with the values typed here on + // top, i.e. the record the write would leave. An option `visibleWhen` reads + // `record.*` (`useCascadingOptions`, through `dependentValues`), and with no + // record handed over every option reading the field the change writes was + // judged hidden: the loss reason a move to 「失败」 asks for offered nothing. + const judged = shown.find((f) => f.record)?.record; + const liveRecord = React.useMemo(() => ({ ...judged, ...values }), [judged, values]); const presentRefusal = (err: unknown) => { const { entries, fallback } = refusalOf(err); @@ -306,6 +316,7 @@ export function RequiredFieldsDialog({ { setValues((prev) => ({ ...prev, [f.name]: v })); // A server reason is about the value it was given; a new diff --git a/ui/packages/fields/src/__tests__/RequiredFieldsDialog.inPlace-35956.test.tsx b/ui/packages/fields/src/__tests__/RequiredFieldsDialog.inPlace-35956.test.tsx index 5de14f0c879..5a72fcd64f8 100644 --- a/ui/packages/fields/src/__tests__/RequiredFieldsDialog.inPlace-35956.test.tsx +++ b/ui/packages/fields/src/__tests__/RequiredFieldsDialog.inPlace-35956.test.tsx @@ -165,3 +165,94 @@ describe('RequiredFieldsDialog with nothing to fill (objectstack#35956 PR 2, the await waitFor(() => expect(textboxOf(dialog, 'win_reason')).toHaveFocus()); }); }); + +describe('RequiredFieldsDialog judges option visibleWhen on the record with the change merged in (objectstack#37250)', () => { + // The shape hotcrm authors on `crm_opportunity.loss_reason`: every option is + // offered only once the record is (or is being moved to) `closed_lost` — + // i.e. it reads the very field the change writes. + const LOST_ONLY = + '(has(record.stage) && record.stage == "closed_lost") || (has(record.requested_status) && record.requested_status == "closed_lost")'; + const PENDING_FIELDS = { + stage: { + type: 'select', + label: 'Stage', + options: [ + { value: 'negotiation', label: 'Negotiation' }, + { value: 'closed_lost', label: 'Closed Lost' }, + { value: 'closed_won', label: 'Closed Won' }, + ], + }, + loss_reason: { + type: 'select', + label: 'Loss Reason', + requiredWhen: 'record.stage == "closed_lost"', + options: [ + { value: 'price', label: 'Price', visibleWhen: LOST_ONLY }, + { value: 'timing', label: 'Timing', visibleWhen: LOST_ONLY }, + ], + }, + loss_channel: { + type: 'radio', + label: 'Loss Channel', + requiredWhen: 'record.stage == "closed_lost"', + options: [ + { value: 'lost_option', label: 'Lost option', visibleWhen: LOST_ONLY }, + { value: 'won_option', label: 'Won option', visibleWhen: 'record.stage == "closed_won"' }, + { value: 'plain_option', label: 'Plain option' }, + { value: 'detail_option', label: 'Detail option', visibleWhen: 'record.loss_detail == "price"' }, + ], + }, + loss_detail: { type: 'text', label: 'Loss Detail', requiredWhen: 'record.stage == "closed_lost"' }, + }; + const STORED = { id: 'o2', name: 'Globex deal', stage: 'negotiation', loss_reason: null, loss_channel: null, loss_detail: null }; + const MOVE = { stage: 'closed_lost' }; + + const renderPending = () => { + render( + , + ); + return screen.getByTestId('required-fields-dialog'); + }; + const rowOf = (dialog: HTMLElement, name: string) => + dialog.querySelector(`[data-required-fields-field="${name}"]`) as HTMLElement; + + it('the collector carries the record it judged: the stored record with the change merged in', () => { + const out = collectRequiredWhenPromptFields(PENDING_FIELDS, STORED, MOVE); + expect(out.map((f) => f.name)).toEqual(['loss_reason', 'loss_channel', 'loss_detail']); + for (const f of out) expect(f.record).toEqual({ ...STORED, ...MOVE }); + }); + + it('a select whose options read the changed field offers them, instead of the empty state', () => { + const dialog = renderPending(); + const row = rowOf(dialog, 'loss_reason'); + expect(row).not.toBeNull(); + expect(row.querySelector('[data-testid="select-empty-loss_reason"]')).toBeNull(); + expect(within(row).getByRole('combobox')).toBeInTheDocument(); + }); + + it('offers exactly the options visible on the merged record', () => { + const dialog = renderPending(); + const row = rowOf(dialog, 'loss_channel'); + expect(row.querySelector('[data-testid="radio-empty-loss_channel"]')).toBeNull(); + expect(within(row).getByText('Lost option')).toBeInTheDocument(); + expect(within(row).getByText('Plain option')).toBeInTheDocument(); + // Judged on the merged record, not opened up: `stage` is `closed_lost`, so + // the won-only option stays hidden. + expect(within(row).queryByText('Won option')).toBeNull(); + expect(within(row).queryByText('Detail option')).toBeNull(); + }); + + it('a value typed into the dialog joins the record the other rows read', () => { + const dialog = renderPending(); + expect(within(rowOf(dialog, 'loss_channel')).queryByText('Detail option')).toBeNull(); + fireEvent.change(within(rowOf(dialog, 'loss_detail')).getByRole('textbox'), { target: { value: 'price' } }); + expect(within(rowOf(dialog, 'loss_channel')).getByText('Detail option')).toBeInTheDocument(); + }); +}); diff --git a/ui/packages/fields/src/requiredWhenPrompt.ts b/ui/packages/fields/src/requiredWhenPrompt.ts index d072c4cee09..94c899a81b5 100644 --- a/ui/packages/fields/src/requiredWhenPrompt.ts +++ b/ui/packages/fields/src/requiredWhenPrompt.ts @@ -72,6 +72,16 @@ export interface RequiredWhenPromptField { name: string; /** The field definition, with `name` guaranteed present for the widget. */ def: Record & { type?: string }; + /** + * The record this field was judged against: the stored record with the + * change merged in, i.e. the record as the write would leave it. Set by + * {@link collectRequiredWhenPromptFields}; the fill-in dialog hands it to + * the field's control, so an option `visibleWhen` that reads the field the + * change writes (`record.stage == "closed_lost"` on a loss reason) is judged + * on the same record the prompt was (objectstack#37250). Absent on a row a + * host builds itself (a field a refusal names). + */ + record?: Record; } /** How {@link collectRequiredWhenPromptFields} narrows its set. */ @@ -152,7 +162,7 @@ export function collectRequiredWhenPromptFields( if (!hasFieldEditWidget(def.type as string | undefined)) continue; if (options.fillable && !options.fillable(name, def)) continue; - prompts.push({ name, def: { name, ...def } }); + prompts.push({ name, def: { name, ...def }, record: next }); } return prompts; } From f731d2461f22d8480492ec2095bdfa17d6399eaa Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 09:46:28 +0000 Subject: [PATCH 2/3] fix(fields): declare the RequiredWhenPromptField widening; name what the dialog's record now resolves MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The changeset declares Clause-② yes (widening) for the optional `record` member on the exported RequiredWhenPromptField, and states the defect as the dialog handing its controls no record: option visibility, dependsOn gates, dependent-lookup filters and a record-following currency now resolve on the record the change would leave. Adds the win_reason mirror pin (a move to closed_won offers the won-only reasons). Claude-Session: https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ Co-authored-by: Claude --- .../37250-fill-in-dialog-pending-options.md | 17 +++++++--- ...equiredFieldsDialog.inPlace-35956.test.tsx | 32 ++++++++++++++++--- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/.changeset/37250-fill-in-dialog-pending-options.md b/.changeset/37250-fill-in-dialog-pending-options.md index 0e7d006ba16..2bbd2a1fc6f 100644 --- a/.changeset/37250-fill-in-dialog-pending-options.md +++ b/.changeset/37250-fill-in-dialog-pending-options.md @@ -2,15 +2,22 @@ '@object-ui/fields': patch --- -fix(fields): the required-fields fill-in dialog offers the options the change makes available +fix(fields): the required-fields fill-in dialog hands its controls the record the change would leave -Clause-②: no +Clause-②: yes (widening) Metadata-protocol: none -When a change in place (a stage move on the record page, a list cell, an inline edit, a kanban drop) makes another field required, the fill-in dialog asks for it. A choice field there could show "No options available" and the change could not be saved. This happened when the field's options are each shown only for some values of the field the change writes. Example: every loss reason is shown only while the stage is "closed lost". Moving an opportunity to "closed lost" asked for a loss reason and offered none. +A change made in place (a stage move on the record page, a list cell, an inline edit, a kanban drop) can make another field required. The fill-in dialog then asks for that field. The dialog handed its controls no record, so every control that reads the record judged it on an empty one. Any option `visibleWhen` that read a record field was judged without that field. A condition guarded by `has(record.x)` was false, so the option was hidden. A condition without that guard could not be evaluated, and the option was offered whatever the condition said. A choice field whose options were all hidden showed "No options available", and the change could not be saved. Example: each loss reason is shown only while the stage is "closed lost", so moving an opportunity to "closed lost" asked for a loss reason and offered none. Every option list gated by `dependsOn`, and every dependent lookup, stayed on its "select the parent first" gate. -The dialog now judges each option's `visibleWhen` against the record as the write would leave it: the saved record, the change, and the values typed into the dialog so far. So the loss reasons appear, and an option that depends on another value typed into the dialog appears once that value is typed. Options that are not visible on that record stay hidden. The same record already decided which fields the dialog asks for, so the fields asked for do not change. +The dialog now hands every control the record as the write would leave it: the saved record, with the change and the values typed into the dialog so far applied on top. What reads that record now resolves on it: -For hosts: each field `collectRequiredWhenPromptFields` returns now carries `record`, the record it was judged against. The dialog hands it, with the typed values, to every control as `dependentValues`. A row a host builds itself (a field a refusal names) reads the same record when the dialog has a field that carries one. +- option visibility; +- `dependsOn` gates on option lists and lookups; +- dependent-lookup filters; +- the currency of a money field that takes its currency from the record or from a parent record. + +An option that depends on another value typed into the dialog appears once that value is typed. Options that are not visible on that record stay hidden. Which fields the dialog asks for was already decided on this record and does not change. + +Widening: the exported `RequiredWhenPromptField` type gains one optional member, `record?: Record`. That is the record the field was judged against. `collectRequiredWhenPromptFields` sets it on every field it returns, and `RequiredFieldsDialogField` inherits it. The dialog passes it, with the typed values, to every control as `dependentValues`. A row a host builds itself (a field a refusal names) carries no `record`. It reads the record of another field shown in the dialog. When no shown field carries one, it reads only the typed values. No metadata key, value or default changes. diff --git a/ui/packages/fields/src/__tests__/RequiredFieldsDialog.inPlace-35956.test.tsx b/ui/packages/fields/src/__tests__/RequiredFieldsDialog.inPlace-35956.test.tsx index 5a72fcd64f8..7e54f8190cf 100644 --- a/ui/packages/fields/src/__tests__/RequiredFieldsDialog.inPlace-35956.test.tsx +++ b/ui/packages/fields/src/__tests__/RequiredFieldsDialog.inPlace-35956.test.tsx @@ -172,6 +172,8 @@ describe('RequiredFieldsDialog judges option visibleWhen on the record with the // i.e. it reads the very field the change writes. const LOST_ONLY = '(has(record.stage) && record.stage == "closed_lost") || (has(record.requested_status) && record.requested_status == "closed_lost")'; + const WON_ONLY = + '(has(record.stage) && record.stage == "closed_won") || (has(record.requested_status) && record.requested_status == "closed_won")'; const PENDING_FIELDS = { stage: { type: 'select', @@ -203,17 +205,30 @@ describe('RequiredFieldsDialog judges option visibleWhen on the record with the ], }, loss_detail: { type: 'text', label: 'Loss Detail', requiredWhen: 'record.stage == "closed_lost"' }, + // The mirror case: a win reason, shown only once the record is (or is + // being moved to) `closed_won`. + win_reason: { + type: 'select', + label: 'Win Reason', + requiredWhen: 'record.stage == "closed_won"', + options: [ + { value: 'product', label: 'Product', visibleWhen: WON_ONLY }, + { value: 'relationship', label: 'Relationship', visibleWhen: WON_ONLY }, + ], + }, + }; + const STORED = { + id: 'o2', name: 'Globex deal', stage: 'negotiation', loss_reason: null, loss_channel: null, loss_detail: null, win_reason: null, }; - const STORED = { id: 'o2', name: 'Globex deal', stage: 'negotiation', loss_reason: null, loss_channel: null, loss_detail: null }; const MOVE = { stage: 'closed_lost' }; - const renderPending = () => { + const renderPending = (move: Record = MOVE, shown = 'Closed Lost') => { render( , @@ -249,6 +264,15 @@ describe('RequiredFieldsDialog judges option visibleWhen on the record with the expect(within(row).queryByText('Detail option')).toBeNull(); }); + it('the mirror case: a move to closed_won offers the win reasons its options gate on', () => { + const dialog = renderPending({ stage: 'closed_won' }, 'Closed Won'); + expect(rowOf(dialog, 'loss_reason')).toBeNull(); + const row = rowOf(dialog, 'win_reason'); + expect(row).not.toBeNull(); + expect(row.querySelector('[data-testid="select-empty-win_reason"]')).toBeNull(); + expect(within(row).getByRole('combobox')).toBeInTheDocument(); + }); + it('a value typed into the dialog joins the record the other rows read', () => { const dialog = renderPending(); expect(within(rowOf(dialog, 'loss_channel')).queryByText('Detail option')).toBeNull(); From c69148c9887de4715670615a4ddba681703fda8a Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 10:41:37 +0000 Subject: [PATCH 3/3] docs(changeset): state that the dialog now hides options an empty record used to let through Claude-Session: https://claude.ai/code/session_01QSeKYpEsWWE9Y5YtSsDgqZ Co-authored-by: Claude --- .changeset/37250-fill-in-dialog-pending-options.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/37250-fill-in-dialog-pending-options.md b/.changeset/37250-fill-in-dialog-pending-options.md index 2bbd2a1fc6f..e43bf4d69db 100644 --- a/.changeset/37250-fill-in-dialog-pending-options.md +++ b/.changeset/37250-fill-in-dialog-pending-options.md @@ -16,7 +16,7 @@ The dialog now hands every control the record as the write would leave it: the s - dependent-lookup filters; - the currency of a money field that takes its currency from the record or from a parent record. -An option that depends on another value typed into the dialog appears once that value is typed. Options that are not visible on that record stay hidden. Which fields the dialog asks for was already decided on this record and does not change. +Each option is now shown or hidden by its condition on the record the write would leave. If the condition is true on that record, the option is shown. If it is false, the option is hidden. This includes an option the dialog used to offer only because its condition could not be evaluated on an empty record. For example, an unguarded `record.stage == "closed_lost"` used to be offered whatever the stage. It is now hidden when the stage stays "negotiation". So in an app whose option conditions do not guard with `has()`, the dialog can offer fewer options than before. A condition that still cannot be evaluated on that record is still offered, for example one that names a field the record does not carry. An option that depends on another value typed into the dialog appears once that value is typed. Which fields the dialog asks for was already decided on this record and does not change. Widening: the exported `RequiredWhenPromptField` type gains one optional member, `record?: Record`. That is the record the field was judged against. `collectRequiredWhenPromptFields` sets it on every field it returns, and `RequiredFieldsDialogField` inherits it. The dialog passes it, with the typed values, to every control as `dependentValues`. A row a host builds itself (a field a refusal names) carries no `record`. It reads the record of another field shown in the dialog. When no shown field carries one, it reads only the typed values.