From f11044dd0959157d10226ee554226db0253db9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Fri, 7 Feb 2025 15:40:54 -0300 Subject: [PATCH] fix: add max length validations on name and affiliation --- public/locales/en/shared.json | 10 ++++++++-- .../top-fields-section/TopFieldsSection.tsx | 14 +++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/public/locales/en/shared.json b/public/locales/en/shared.json index 6a80af135..94d48cc1a 100644 --- a/public/locales/en/shared.json +++ b/public/locales/en/shared.json @@ -74,11 +74,17 @@ "name": { "label": "Collection Name", "description": "The project, department, university, professor, or journal this collection will contain data for.", - "required": "Collection Name is required" + "required": "Collection Name is required", + "invalid": { + "maxLength": "Collection Name must be at most {{maxLength}} characters." + } }, "affiliation": { "label": "Affiliation", - "description": "The organization with which this collection is affiliated." + "description": "The organization with which this collection is affiliated.", + "invalid": { + "maxLength": "Affiliation must be at most {{maxLength}} characters." + } }, "alias": { "label": "Identifier", diff --git a/src/sections/shared/form/EditCreateCollectionForm/collection-form/top-fields-section/TopFieldsSection.tsx b/src/sections/shared/form/EditCreateCollectionForm/collection-form/top-fields-section/TopFieldsSection.tsx index 8de181dcc..76e0297ce 100644 --- a/src/sections/shared/form/EditCreateCollectionForm/collection-form/top-fields-section/TopFieldsSection.tsx +++ b/src/sections/shared/form/EditCreateCollectionForm/collection-form/top-fields-section/TopFieldsSection.tsx @@ -23,7 +23,18 @@ export const TopFieldsSection = ({ isEditingRootCollection }: TopFieldsSectionPr } const nameRules: UseControllerProps['rules'] = { - required: t('fields.name.required') + required: t('fields.name.required'), + maxLength: { + value: 120, + message: t('fields.name.invalid.maxLength', { maxLength: 60 }) + } + } + + const affiliationRules: UseControllerProps['rules'] = { + maxLength: { + value: 120, + message: t('fields.affiliation.invalid.maxLength', { maxLength: 100 }) + } } const aliasRules: UseControllerProps['rules'] = { @@ -119,6 +130,7 @@ export const TopFieldsSection = ({ isEditingRootCollection }: TopFieldsSectionPr (