Skip to content

Commit

Permalink
Merge pull request #472 from Plant-for-the-Planet-org/feature/restric…
Browse files Browse the repository at this point in the history
…t-gift-recipient-name-length

Add validation for recipient name length in GiftForm
  • Loading branch information
mariahosfeld authored Dec 3, 2024
2 parents b7cb75c + c379166 commit 8546ebb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"tree_other": "trees",
"recipientName": "Recipient Name",
"recipientNameRequired": "Recipient Name is required",
"recipientNameTooLong": "Recipient Name must be 35 characters or less",
"email": "Email",
"recipientEmail": "Recipient Email",
"emailRequired": "Email is required",
Expand Down
15 changes: 12 additions & 3 deletions src/Donations/Micros/GiftForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,16 @@ export default function GiftForm(): ReactElement {
<Controller
name="recipientName"
control={control}
rules={{ required: true }}
rules={{
required: {
value: true,
message: t("recipientNameRequired"),
},
maxLength: {
value: 35,
message: t("recipientNameTooLong"),
},
}}
render={({ field: { onChange, value } }) => (
<MaterialTextField
onChange={onChange}
Expand All @@ -109,9 +118,9 @@ export default function GiftForm(): ReactElement {
/>
)}
/>
{errors.recipientName && (
{errors.recipientName !== undefined && (
<div className={"form-errors"}>
{t("recipientNameRequired")}
{errors.recipientName.message}
</div>
)}
</div>
Expand Down

0 comments on commit 8546ebb

Please sign in to comment.