From 00ae23fe44394940bfb538f3bff67c0a55275782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=92scar=20Casajuana?= Date: Tue, 21 Nov 2023 10:41:02 +0100 Subject: [PATCH] Add min_length validation to SIK password field --- .../src/components/Election/Questions.tsx | 2 +- .../src/components/Election/SpreadsheetAccess.tsx | 8 ++++++-- packages/chakra-components/src/i18n/locales.ts | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/chakra-components/src/components/Election/Questions.tsx b/packages/chakra-components/src/components/Election/Questions.tsx index d6ebc74e..bdcc5d76 100644 --- a/packages/chakra-components/src/components/Election/Questions.tsx +++ b/packages/chakra-components/src/components/Election/Questions.tsx @@ -169,7 +169,7 @@ const QuestionField = ({ question, index }: QuestionFieldProps) => { )} ( { const required = { value: true, - message: localize('required'), + message: localize('validation.required'), + } + const minLength = { + value: 8, + message: localize('validation.min_length', { min: 8 }), } if (election?.get('census.type') !== 'spreadsheet' || election instanceof ArchivedElection) return null @@ -116,7 +120,7 @@ export const SpreadsheetAccess = (rest: ChakraProps) => { {election.electionType.anonymous && ( {localize('spreadsheet.anon_sik_label')} - + {!!errors.sik_password ? ( {errors.sik_password?.message?.toString()} ) : ( diff --git a/packages/chakra-components/src/i18n/locales.ts b/packages/chakra-components/src/i18n/locales.ts index 9b48b2c8..0f35d20b 100644 --- a/packages/chakra-components/src/i18n/locales.ts +++ b/packages/chakra-components/src/i18n/locales.ts @@ -35,7 +35,6 @@ export const locales = { wrong_data_title: 'Wrong data', wrong_data_description: 'The specified data is not correct', }, - required: 'This field is required', schedule: 'Voting from {{ begin }} to {{ end }}', // results component results: { @@ -63,6 +62,10 @@ export const locales = { logout: 'Logout', modal_title: 'You must identify first', }, + validation: { + required: 'This field is required', + min_length: 'This field must be at least {{ min }} characters long', + }, } export type Locale = RecursivePartial