forked from rjsf-team/react-jsonschema-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FieldErrorTemplate.tsx
36 lines (34 loc) · 951 Bytes
/
FieldErrorTemplate.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from "react";
import {
FieldErrorProps,
FormContextType,
RJSFSchema,
StrictRJSFSchema,
} from "@rjsf/utils";
import ListGroup from "react-bootstrap/ListGroup";
/** The `FieldErrorTemplate` component renders the errors local to the particular field
*
* @param props - The `FieldErrorProps` for the errors being rendered
*/
export default function FieldErrorTemplate<
T = any,
S extends StrictRJSFSchema = RJSFSchema,
F extends FormContextType = any
>(props: FieldErrorProps<T, S, F>) {
const { errors = [], idSchema } = props;
if (errors.length === 0) {
return null;
}
const id = `${idSchema.$id}__error`;
return (
<ListGroup as="ul" id={id}>
{errors.map((error, i) => {
return (
<ListGroup.Item as="li" key={i} className="border-0 m-0 p-0">
<small className="m-0 text-danger">{error}</small>
</ListGroup.Item>
);
})}
</ListGroup>
);
}