Skip to content

Commit

Permalink
rjsf-errors-on-array-template (#1683)
Browse files Browse the repository at this point in the history
* display error messages on the ArrayFieldTemplate for item list errors

* do not change things that do not need it

---------

Co-authored-by: jasquat <[email protected]>
  • Loading branch information
jasquat and jasquat authored Jun 5, 2024
1 parent 4611628 commit 9150bb7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
RJSFSchema,
StrictRJSFSchema,
} from '@rjsf/utils';
import { getCommonAttributes } from '../../helpers';

/** The `ArrayFieldTemplate` component is the template used to render all items in an array.
*
Expand All @@ -31,6 +32,7 @@ export default function ArrayFieldTemplate<
required,
schema,
title,
rawErrors,
} = props;
const uiOptions = getUiOptions<T, S, F>(uiSchema);
const ArrayFieldDescriptionTemplate = getTemplate<
Expand All @@ -50,10 +52,14 @@ export default function ArrayFieldTemplate<
S,
F
>('ArrayFieldTitleTemplate', registry, uiOptions);

const commonAttributes = getCommonAttributes('', schema, uiSchema, rawErrors);

// Button templates are not overridden in the uiSchema
const {
ButtonTemplates: { AddButton },
} = registry.templates;

return (
<fieldset className={className} id={idSchema.$id}>
<ArrayFieldTitleTemplate
Expand All @@ -71,6 +77,14 @@ export default function ArrayFieldTemplate<
uiSchema={uiSchema}
registry={registry}
/>
{commonAttributes.errorMessageForField && (
<>
<div className="error-message">
{commonAttributes.errorMessageForField}
</div>
<br />
</>
)}
<div className="row array-item-list">
{items &&
items.map(
Expand Down
2 changes: 1 addition & 1 deletion spiffworkflow-frontend/src/rjsf/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const getCommonAttributes = (
errorMessageForField = (schema as any).validationErrorMessage;
errorMessageForFieldWithoutLabel = errorMessageForField;
} else {
errorMessageForField = `${labelToUse.replace(/\*$/, '')} ${rawErrors[0]}`;
errorMessageForField = `"${labelToUse.replace(/\*$/, '')}" ${rawErrors[0]}`;
}
}

Expand Down

0 comments on commit 9150bb7

Please sign in to comment.