From d9b70a89e63b722dec3c02c9be5b99cf17d5e2ab Mon Sep 17 00:00:00 2001 From: "Beier (Bill)" Date: Sat, 24 Dec 2022 13:12:08 +1100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=A6=F0=9F=8F=BB=E2=80=8D=E2=99=82?= =?UTF-8?q?=EF=B8=8Ffix=20#9661=20regression=20on=20required=20valueAsNumb?= =?UTF-8?q?er=20(#9662)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/logic/validateField.test.tsx | 22 ++++++++++++++++++++++ src/logic/validateField.ts | 1 + 2 files changed, 23 insertions(+) diff --git a/src/__tests__/logic/validateField.test.tsx b/src/__tests__/logic/validateField.test.tsx index dbdfca19efe..ce95aeec86d 100644 --- a/src/__tests__/logic/validateField.test.tsx +++ b/src/__tests__/logic/validateField.test.tsx @@ -36,6 +36,28 @@ describe('validateField', () => { }, }); + expect( + await validateField( + { + _f: { + mount: true, + name: 'test', + ref: { type: 'text', value: '', name: 'test' }, + required: true, + valueAsNumber: true, + }, + }, + NaN, + false, + ), + ).toEqual({ + test: { + ref: { type: 'text', value: '', name: 'test' }, + message: '', + type: 'required', + }, + }); + expect( await validateField( { diff --git a/src/logic/validateField.ts b/src/logic/validateField.ts index 13e66e4bc1d..48732b72b1c 100644 --- a/src/logic/validateField.ts +++ b/src/logic/validateField.ts @@ -66,6 +66,7 @@ export default async ( isUndefined(ref.value) && isUndefined(inputValue)) || inputValue === '' || + ref.value === '' || (Array.isArray(inputValue) && !inputValue.length); const appendErrorsCurry = appendErrors.bind( null,