diff --git a/components/clientComponents/forms/ErrorListItem/ErrorListItem.tsx b/components/clientComponents/forms/ErrorListItem/ErrorListItem.tsx
index d4182743c6..c5b4b67e4f 100644
--- a/components/clientComponents/forms/ErrorListItem/ErrorListItem.tsx
+++ b/components/clientComponents/forms/ErrorListItem/ErrorListItem.tsx
@@ -4,6 +4,7 @@ import React from "react";
export interface ErrorListProps {
errorKey: string;
value: string | undefined;
+ label?: string;
}
/**
@@ -23,9 +24,10 @@ const scrollErrorInView = (id: string) => {
* @returns ReactElement for displaying the error list
* @param errorKey The key for the form element for the error
* @param value The error to be displayed
+ * @param label The label for the form element
*/
export const ErrorListItem = (props: ErrorListProps): React.ReactElement => {
- const { errorKey, value } = props;
+ const { errorKey, value, label } = props;
return (
@@ -43,6 +45,7 @@ export const ErrorListItem = (props: ErrorListProps): React.ReactElement => {
scrollErrorInView(errorKey);
}}
>
+ {label && `${label} - `}
{value}
diff --git a/lib/validation/validation.tsx b/lib/validation/validation.tsx
index 4bce8f35c1..f00fa605eb 100644
--- a/lib/validation/validation.tsx
+++ b/lib/validation/validation.tsx
@@ -258,7 +258,7 @@ export const validateOnSubmit = (
*/
export const getErrorList = (
- props: { formRecord: PublicFormRecord } & FormikProps
+ props: { formRecord: PublicFormRecord; language: string } & FormikProps
): JSX.Element | null => {
if (!props.formRecord?.form || !props.errors) {
return null;
@@ -273,6 +273,19 @@ export const getErrorList = (
return [element, props.errors[element]];
});
+ // TODO may want to truncate long labels with css instead
+ // TODO test dynamic rows
+ const getLabel = (elementKey: string | number | undefined): string => {
+ const formElement = props.formRecord.form.elements.filter(
+ (element) => element.id === elementKey
+ )[0];
+ const formLabel =
+ (props.language === "fr"
+ ? formElement?.properties?.titleFr
+ : formElement?.properties?.titleEn) || "";
+ return formLabel.length > 24 ? formLabel.substring(0, 24) + "..." : formLabel;
+ };
+
if (props.touched && sortedFormElementErrors.length) {
errorList = sortedFormElementErrors.map(([formElementKey, formElementErrorValue]) => {
if (Array.isArray(formElementErrorValue)) {
@@ -285,6 +298,9 @@ export const getErrorList = (
key={`error-${formElementKey}.${dynamicRowIndex}.${dyanamicRowElementKey}`}
errorKey={`${formElementKey}.${dynamicRowIndex}.${dyanamicRowElementKey}`}
value={`${dyanamicRowElementErrorValue as string}`}
+ label={getLabel(
+ `${formElementKey}.${dynamicRowIndex}.${dyanamicRowElementKey}`
+ )}
/>
)
);
@@ -297,6 +313,7 @@ export const getErrorList = (
key={`error-${formElementKey}`}
errorKey={`${formElementKey}`}
value={`${formElementErrorValue}`}
+ label={getLabel(formElementKey)}
/>
);
}