From 6580158d291207b5b60830fe3ecb78b456d7f130 Mon Sep 17 00:00:00 2001 From: huhupy <67313891+huhumeng2@users.noreply.github.com> Date: Tue, 29 Sep 2026 21:59:30 +0800 Subject: [PATCH] fix(web): accept zero in required number inputs --- .../check-input-forms-hooks.spec.tsx | 47 +++++++++++++++++++ .../base/chat/chat/check-input-forms-hooks.ts | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/web/app/components/base/chat/chat/__tests__/check-input-forms-hooks.spec.tsx b/web/app/components/base/chat/chat/__tests__/check-input-forms-hooks.spec.tsx index ee344841691655..18bf3151910416 100644 --- a/web/app/components/base/chat/chat/__tests__/check-input-forms-hooks.spec.tsx +++ b/web/app/components/base/chat/chat/__tests__/check-input-forms-hooks.spec.tsx @@ -49,6 +49,53 @@ describe('useCheckInputsForms', () => { ) }) + describe('required number inputs', () => { + const inputsForm: InputForm[] = [ + { + variable: 'count', + label: 'Count', + required: true, + type: InputVarType.number, + hide: false, + }, + ] + + it.each([0, 1, -1, '0'])('should accept %j without a required-input error', (value) => { + const { result } = renderHook(() => useCheckInputsForms()) + + expect(result.current.checkInputsForm({ count: value }, inputsForm)).toBe(true) + expect(mockNotify).not.toHaveBeenCalled() + }) + + it.each([undefined, null, ''])('should reject an empty number value (%j)', (value) => { + const { result } = renderHook(() => useCheckInputsForms()) + + expect(result.current.checkInputsForm({ count: value }, inputsForm)).toBe(false) + expect(mockNotify).toHaveBeenCalledWith( + expect.objectContaining({ + type: 'error', + message: expect.stringContaining('appDebug.errorMessage.valueOfVarRequired'), + }), + ) + }) + }) + + it('should allow an unchecked required checkbox without a notification', () => { + const { result } = renderHook(() => useCheckInputsForms()) + const inputsForm: InputForm[] = [ + { + variable: 'enabled', + label: 'Enabled', + required: true, + type: InputVarType.checkbox, + hide: false, + }, + ] + + expect(result.current.checkInputsForm({ enabled: false }, inputsForm)).toBe(true) + expect(mockNotify).not.toHaveBeenCalled() + }) + it('should ignore missing but not required inputs', () => { const { result } = renderHook(() => useCheckInputsForms()) const inputsForm = [ diff --git a/web/app/components/base/chat/chat/check-input-forms-hooks.ts b/web/app/components/base/chat/chat/check-input-forms-hooks.ts index 8348581d3cfc76..d91b4aca46dc69 100644 --- a/web/app/components/base/chat/chat/check-input-forms-hooks.ts +++ b/web/app/components/base/chat/chat/check-input-forms-hooks.ts @@ -18,7 +18,7 @@ export const useCheckInputsForms = () => { requiredVars.forEach(({ variable, label, type }) => { if (hasEmptyInput) return if (fileIsUploading) return - if (!inputs[variable]) hasEmptyInput = label as string + if (!inputs[variable] && inputs[variable] !== 0) hasEmptyInput = label as string if ( (type === InputVarType.singleFile || type === InputVarType.multiFiles) && inputs[variable]