Skip to content

Commit

Permalink
fix: add max length validations on name and affiliation
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Feb 7, 2025
1 parent 9cbf55e commit f11044d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 8 additions & 2 deletions public/locales/en/shared.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = {
Expand Down Expand Up @@ -119,6 +130,7 @@ export const TopFieldsSection = ({ isEditingRootCollection }: TopFieldsSectionPr
<Controller
name="affiliation"
control={control}
rules={affiliationRules}
render={({ field: { onChange, ref, value }, fieldState: { invalid, error } }) => (
<Col>
<Form.Group.Input
Expand Down

0 comments on commit f11044d

Please sign in to comment.