From 24c6e6dfee06e2d11f8ce6f0ac97a560923a01c3 Mon Sep 17 00:00:00 2001 From: Lakshmi Tanmay Date: Fri, 6 Nov 2026 18:57:15 +0530 Subject: [PATCH] fix(client): allow submitting empty multi-select answers --- .../src/state/pendingUserInput.test.ts | 18 ++++++++++++++++++ .../src/state/pendingUserInput.ts | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/client-runtime/src/state/pendingUserInput.test.ts b/packages/client-runtime/src/state/pendingUserInput.test.ts index 7f5a2b0b84c3d..0236303685804 100644 --- a/packages/client-runtime/src/state/pendingUserInput.test.ts +++ b/packages/client-runtime/src/state/pendingUserInput.test.ts @@ -32,6 +32,19 @@ const nativeChoiceQuestion = { } as const; describe("resolvePendingUserInputAnswer", () => { + it("accepts no selections for multi-select questions while single-select stays unanswered", () => { + const question = { ...singleSelectQuestion, multiSelect: true }; + expect(buildPendingUserInputAnswers([question], {})).toEqual({ scope: [] }); + expect(resolvePendingUserInputAnswer(question, { selectedOptionValues: [] })).toEqual([]); + expect(resolvePendingUserInputAnswer(question, { customAnswer: " " })).toEqual([]); + expect(resolvePendingUserInputAnswer(question, { customAnswer: "Something else" })).toBe( + "Something else", + ); + expect(resolvePendingUserInputAnswer(question, { attachmentCount: 1 })).toBe(""); + expect(resolvePendingUserInputAnswer(question, { attachmentsBlocked: true })).toBeNull(); + expect(resolvePendingUserInputAnswer(singleSelectQuestion, undefined)).toBeNull(); + }); + it("preserves exact editor text, including a deliberately cleared answer", () => { const question = { ...singleSelectQuestion, initialAnswer: " Proposed message\n" }; expect(resolvePendingUserInputAnswer(question, { customAnswer: question.initialAnswer })).toBe( @@ -124,6 +137,11 @@ describe("togglePendingUserInputOptionSelection", () => { expect(buildPendingUserInputAnswers([question], { result: secondSelected })).toEqual({ result: ["second"], }); + + const noneSelected = togglePendingUserInputOptionSelection(question, secondSelected, "second"); + expect(buildPendingUserInputAnswers([question], { result: noneSelected })).toEqual({ + result: [], + }); }); it("submits raw option values and leaves the draft alone for an unknown option", () => { diff --git a/packages/client-runtime/src/state/pendingUserInput.ts b/packages/client-runtime/src/state/pendingUserInput.ts index 1c71cdb29b4df..428c2dc667996 100644 --- a/packages/client-runtime/src/state/pendingUserInput.ts +++ b/packages/client-runtime/src/state/pendingUserInput.ts @@ -77,7 +77,9 @@ export function resolvePendingUserInputAnswer( return selectedOptionValues.length > 0 ? selectedOptionValues : (customAnswer ?? - (question.allowCustomAnswer !== false && (draft?.attachmentCount ?? 0) > 0 ? "" : null)); + (question.allowCustomAnswer !== false && (draft?.attachmentCount ?? 0) > 0 + ? "" + : selectedOptionValues)); } return ( selectedOptionValues[0] ??