Skip to content

Commit

Permalink
Add min_length validation to SIK password field
Browse files Browse the repository at this point in the history
  • Loading branch information
elboletaire committed Nov 21, 2023
1 parent 43ed84b commit 00ae23f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const QuestionField = ({ question, index }: QuestionFieldProps) => {
</chakra.div>
)}
<Controller
rules={{ required: localize('required') }}
rules={{ required: localize('validation.required') }}
name={index}
render={({ field }) => (
<RadioGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ export const SpreadsheetAccess = (rest: ChakraProps) => {

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
Expand Down Expand Up @@ -116,7 +120,7 @@ export const SpreadsheetAccess = (rest: ChakraProps) => {
{election.electionType.anonymous && (
<FormControl isInvalid={!!errors.sik_password} sx={styles.sik_control}>
<FormLabel sx={styles.label}>{localize('spreadsheet.anon_sik_label')}</FormLabel>
<Input {...register('sik_password', { required })} type='password' sx={styles.input} />
<Input {...register('sik_password', { required, minLength })} type='password' sx={styles.input} />
{!!errors.sik_password ? (
<FormErrorMessage sx={styles.error}>{errors.sik_password?.message?.toString()}</FormErrorMessage>
) : (
Expand Down
5 changes: 4 additions & 1 deletion packages/chakra-components/src/i18n/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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<typeof locales>

0 comments on commit 00ae23f

Please sign in to comment.