diff --git a/webapp/public/locales/en/main.json b/webapp/public/locales/en/main.json index 49ed4ce172..ccfac647f2 100644 --- a/webapp/public/locales/en/main.json +++ b/webapp/public/locales/en/main.json @@ -123,7 +123,8 @@ "form.asyncDefaultValues.error": "Failed to get values", "form.field.required": "Field required", "form.field.duplicate": "Value already exists", - "form.field.minLength": "{{0}} character(s) minimum", + "form.field.minLength": "{{length}} character(s) minimum", + "form.field.maxLength": "{{length}} character(s) maximum", "form.field.minValue": "The minimum value is {{0}}", "form.field.maxValue": "The maximum value is {{0}}", "form.field.invalidNumber": "Invalid number", diff --git a/webapp/public/locales/fr/main.json b/webapp/public/locales/fr/main.json index 21085ed4bd..ef12be54ec 100644 --- a/webapp/public/locales/fr/main.json +++ b/webapp/public/locales/fr/main.json @@ -123,7 +123,8 @@ "form.asyncDefaultValues.error": "Impossible d'obtenir les valeurs", "form.field.required": "Champ requis", "form.field.duplicate": "Cette valeur existe déjà", - "form.field.minLength": "{{0}} caractère(s) minimum", + "form.field.minLength": "{{length}} caractère(s) minimum", + "form.field.maxLength": "{{length}} caractère(s) maximum", "form.field.minValue": "La valeur minimum est {{0}}", "form.field.maxValue": "La valeur maximum est {{0}}", "form.field.invalidNumber": "Nombre invalide", diff --git a/webapp/src/components/App/Singlestudy/explore/Modelization/BindingConstraints/AddDialog.tsx b/webapp/src/components/App/Singlestudy/explore/Modelization/BindingConstraints/AddDialog.tsx index f1af440491..6891123b8c 100644 --- a/webapp/src/components/App/Singlestudy/explore/Modelization/BindingConstraints/AddDialog.tsx +++ b/webapp/src/components/App/Singlestudy/explore/Modelization/BindingConstraints/AddDialog.tsx @@ -157,7 +157,7 @@ function AddDialog({ rules={{ validate: (v) => validateString(v, { - max: 20, + maxLength: 20, specialChars: "-", }), }} diff --git a/webapp/src/components/App/Singlestudy/explore/Modelization/BindingConstraints/BindingConstView/ConstraintFields.tsx b/webapp/src/components/App/Singlestudy/explore/Modelization/BindingConstraints/BindingConstView/ConstraintFields.tsx index 3405540a6e..7677a78c4f 100644 --- a/webapp/src/components/App/Singlestudy/explore/Modelization/BindingConstraints/BindingConstView/ConstraintFields.tsx +++ b/webapp/src/components/App/Singlestudy/explore/Modelization/BindingConstraints/BindingConstView/ConstraintFields.tsx @@ -90,7 +90,7 @@ function Fields({ study, constraintId }: Props) { rules={{ validate: (v) => validateString(v, { - max: 20, + maxLength: 20, specialChars: "-", }), }} diff --git a/webapp/src/utils/validationUtils.ts b/webapp/src/utils/validationUtils.ts index 5760f285ae..7cc416fb4e 100644 --- a/webapp/src/utils/validationUtils.ts +++ b/webapp/src/utils/validationUtils.ts @@ -9,7 +9,7 @@ interface NumberValidationOptions { max?: number; } -interface ValidationOptions { +interface StringValidationOptions { existingValues?: string[]; excludedValues?: string[]; isCaseSensitive?: boolean; @@ -17,8 +17,8 @@ interface ValidationOptions { specialChars?: string; allowSpaces?: boolean; editedValue?: string; - min?: number; - max?: number; + minLength?: number; + maxLength?: number; } //////////////////////////////////////////////////////////////// @@ -46,7 +46,7 @@ interface ValidationOptions { */ export function validateString( value: string, - options?: ValidationOptions, + options?: StringValidationOptions, ): string | true { const { existingValues = [], @@ -56,8 +56,8 @@ export function validateString( allowSpaces = true, specialChars = "&()_-", editedValue = "", - min = 0, - max = 255, + minLength = 0, + maxLength = 255, } = options || {}; const trimmedValue = value.trim(); @@ -70,12 +70,12 @@ export function validateString( return t("form.field.spacesNotAllowed"); } - if (trimmedValue.length < min) { - return t("form.field.minValue", { 0: min }); + if (trimmedValue.length < minLength) { + return t("form.field.minLength", { length: minLength }); } - if (trimmedValue.length > max) { - return t("form.field.maxValue", { 0: max }); + if (trimmedValue.length > maxLength) { + return t("form.field.maxLength", { length: maxLength }); } // Compiles a regex pattern based on allowed characters and flags. @@ -129,11 +129,11 @@ export function validatePassword(password: string): string | true { } if (trimmedPassword.length < 8) { - return t("form.field.minValue", { 0: 8 }); + return t("form.field.minLength", { length: 8 }); } if (trimmedPassword.length > 50) { - return t("form.field.maxValue", { 0: 50 }); + return t("form.field.maxLength", { length: 50 }); } if (!/[a-z]/.test(trimmedPassword)) {