From 3c150b368c276b59e6b985c77ed7155e2b11ad41 Mon Sep 17 00:00:00 2001 From: Emmanuel Chambon Date: Mon, 21 Feb 2022 15:47:33 +0100 Subject: [PATCH 1/2] fix: correct overwritten regex type --- src/components/TextBoxField/index.tsx | 2 +- src/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/TextBoxField/index.tsx b/src/components/TextBoxField/index.tsx index 5f1a2234..857b0dca 100644 --- a/src/components/TextBoxField/index.tsx +++ b/src/components/TextBoxField/index.tsx @@ -46,7 +46,7 @@ type TextBoxFieldProps = BaseFieldProps & className?: string max?: number min?: number - regex?: RegExp[] + regex?: (RegExp | RegExp[])[] } const TextBoxField = forwardRef( diff --git a/src/types.ts b/src/types.ts index f9f4df3f..3eaee857 100644 --- a/src/types.ts +++ b/src/types.ts @@ -48,7 +48,7 @@ type RequiredErrors = { | ((params: FormErrorFunctionParams & { maxLength: number }) => string) | string REGEX: - | ((params: FormErrorFunctionParams & { regex: RegExp[] }) => string) + | ((params: FormErrorFunctionParams & { regex: (RegExp | RegExp[])[] }) => string) | string REQUIRED: ((params: FormErrorFunctionParams) => string) | string } From 20a66378393f59e6357f5efcf357cd159b0316f4 Mon Sep 17 00:00:00 2001 From: Emmanuel Chambon Date: Mon, 21 Feb 2022 18:00:43 +0100 Subject: [PATCH 2/2] fix: add missing regex --- src/mocks/mockErrors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mocks/mockErrors.ts b/src/mocks/mockErrors.ts index 7e09ace5..c07f1ff7 100644 --- a/src/mocks/mockErrors.ts +++ b/src/mocks/mockErrors.ts @@ -7,7 +7,7 @@ const mockErrors: FormErrors = { `This field should have a length greater than ${minLength}`, REGEX: ({ regex }) => `This field should match the regex ${regex - .map(r => r.source) + .map(r => Array.isArray(r) ? r.map(nestedRegex => nestedRegex.source).join(' or ') : r.source ) .join(' and ')}`, REQUIRED: 'This field is required', TOO_HIGH: ({ max }) => `This field is too high (maximum is : ${max})`,