diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b074cb93..74962dffc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ changes. ### Fixed - Fix calculating DRep live voting power [Issue 2460](https://github.com/IntersectMBO/govtool/issues/2460) +- Fix link and description validation [Issue 2403](https://github.com/IntersectMBO/govtool/issues/2403) ### Changed diff --git a/govtool/frontend/src/components/molecules/DRepDataForm.tsx b/govtool/frontend/src/components/molecules/DRepDataForm.tsx index f1133b001..3ef89fdc1 100644 --- a/govtool/frontend/src/components/molecules/DRepDataForm.tsx +++ b/govtool/frontend/src/components/molecules/DRepDataForm.tsx @@ -3,6 +3,7 @@ import { Control, FieldErrors, UseFormRegister, + UseFormWatch, useFieldArray, } from "react-hook-form"; import { Box } from "@mui/material"; @@ -20,9 +21,10 @@ type Props = { control: Control; errors: FieldErrors; register: UseFormRegister; + watch: UseFormWatch; }; -export const DRepDataForm = ({ control, errors, register }: Props) => { +export const DRepDataForm = ({ control, errors, register, watch }: Props) => { const { t } = useTranslation(); const { isMobile } = useScreenDimension(); @@ -111,12 +113,14 @@ export const DRepDataForm = ({ control, errors, register }: Props) => { control={control} errors={errors} register={register} + watch={watch} />
@@ -176,6 +180,7 @@ type ReferencesSectionProps = { control: Control; errors: FieldErrors; register: UseFormRegister; + watch: UseFormWatch; }; const ReferencesSection = ({ @@ -183,6 +188,7 @@ const ReferencesSection = ({ control, errors, register, + watch, }: ReferencesSectionProps) => { const { fieldName, jsonldType } = (() => { // eslint-disable-next-line default-case @@ -237,7 +243,16 @@ const ReferencesSection = ({ helpfulTextDataTestId={`${type}-reference-description-${ index + 1 }-hint`} - rules={Rules.LINK_DESCRIPTION} + rules={{ + ...Rules.LINK_DESCRIPTION, + validate: (value) => { + const isLink = watch(`${fieldName}.${index}.uri`); + if (!value && Boolean(isLink)) { + return t("dRepData.required"); + } + return true; + }, + }} /> { + const isDescription = watch(`${fieldName}.${index}.label`); + if (!value && Boolean(isDescription)) { + return t("dRepData.required"); + } + return true; + }, + }} /> ))} diff --git a/govtool/frontend/src/components/organisms/EditDRepInfoSteps/EditDRepForm.tsx b/govtool/frontend/src/components/organisms/EditDRepInfoSteps/EditDRepForm.tsx index 562d91acc..5c1974c9f 100644 --- a/govtool/frontend/src/components/organisms/EditDRepInfoSteps/EditDRepForm.tsx +++ b/govtool/frontend/src/components/organisms/EditDRepInfoSteps/EditDRepForm.tsx @@ -67,7 +67,12 @@ export const EditDRepForm = ({ return ( - + - +