Standarzing the TextWidget widget

This commit is contained in:
2025-04-21 15:37:18 +02:00
parent 6c480a4971
commit 3005c94010

View File

@@ -1,4 +1,5 @@
import React from "react"; import React from "react";
import { getDefaultRegistry } from "@rjsf/core";
import { FormContextType, getTemplate, RJSFSchema, WidgetProps } from "@rjsf/utils"; import { FormContextType, getTemplate, RJSFSchema, WidgetProps } from "@rjsf/utils";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
@@ -11,15 +12,14 @@ export default function CrudTextWidget<T = any, S extends CrudTextRJSFSchema = C
props: WidgetProps<T, S, F> props: WidgetProps<T, S, F>
) { ) {
const { schema } = props; const { schema } = props;
if (schema.hasOwnProperty("foreign_key")) { if (schema.hasOwnProperty("foreignKey")) {
return <ForeignKeyWidget {...props} />; return <ForeignKeyWidget {...props} />;
} else if (schema.hasOwnProperty("const")) { } else if (schema.hasOwnProperty("const")) {
return <Typography >{schema.const as string}</Typography>; return <Typography >{schema.const as string}</Typography>;
} else if (schema.props?.hasOwnProperty("richtext")) { } else if (schema.props?.hasOwnProperty("richtext")) {
return <RichtextWidget {...props} />; return <RichtextWidget {...props} />;
} else { } else {
const { options, registry } = props; const { widgets: { TextWidget } } = getDefaultRegistry<T,S,F>();
const BaseInputTemplate = getTemplate<'BaseInputTemplate', T, S, F>('BaseInputTemplate', registry, options); return <TextWidget {...props} />;
return <BaseInputTemplate {...props} />;
} }
} }