| 1 |
import ListItem from '@mui/material/ListItem'; |
| 2 |
import FormHelperText from '@mui/material/FormHelperText'; |
| 3 |
import List from '@mui/material/List'; |
| 4 |
import { errorId, FieldErrorProps, FormContextType, RJSFSchema, StrictRJSFSchema } from '@rjsf/utils'; |
| 5 |
|
| 6 |
/** The `FieldErrorTemplate` component renders the errors local to the particular field |
| 7 |
* |
| 8 |
* @param props - The `FieldErrorProps` for the errors being rendered |
| 9 |
*/ |
| 10 |
export default function FieldErrorTemplate< |
| 11 |
T = any, |
| 12 |
S extends StrictRJSFSchema = RJSFSchema, |
| 13 |
F extends FormContextType = any |
| 14 |
>(props: FieldErrorProps<T, S, F>) { |
| 15 |
const { errors = [], idSchema } = props; |
| 16 |
if (errors.length === 0) { |
| 17 |
return null; |
| 18 |
} |
| 19 |
const id = errorId<T>(idSchema); |
| 20 |
|
| 21 |
return ( |
| 22 |
<List dense={true} disablePadding={true}> |
| 23 |
{errors.map((error, i: number) => { |
| 24 |
return ( |
| 25 |
<ListItem key={i} disableGutters={true}> |
| 26 |
<FormHelperText id={id}>{error}</FormHelperText> |
| 27 |
</ListItem> |
| 28 |
); |
| 29 |
})} |
| 30 |
</List> |
| 31 |
); |
| 32 |
} |