Skip to content

Commit

Permalink
update: improve RJS form
Browse files Browse the repository at this point in the history
  • Loading branch information
k0stik committed Jul 29, 2024
1 parent f28269e commit 24ab57e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion dist/other/rjsf/templates/ObjectFieldTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import Box from "@mui/material/Box";
import Grid from "@mui/material/Grid";
import { canExpand, descriptionId, getTemplate, getUiOptions, titleId, } from "@rjsf/utils";
import React from "react";
function isNumeric(str) {
return (!Number.isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
!Number.isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail
);
}
export default function ObjectFieldTemplate(props) {
const { description, title, properties, required, disabled, readonly, uiSchema, idSchema, schema, formData, onAddClick, registry, } = props;
const uiOptions = getUiOptions(uiSchema);
Expand All @@ -12,7 +17,7 @@ export default function ObjectFieldTemplate(props) {
// Button templates are not overridden in the uiSchema
const { ButtonTemplates: { AddButton }, } = registry.templates;
return (React.createElement(Box, { className: "ObjectFieldTemplate" },
title && (React.createElement(TitleFieldTemplate, { id: titleId(idSchema), title: title, required: required, schema: schema, uiSchema: uiSchema, registry: registry })),
title && !isNumeric(title) && (React.createElement(TitleFieldTemplate, { id: titleId(idSchema), title: title, required: required, schema: schema, uiSchema: uiSchema, registry: registry })),
description && (React.createElement(DescriptionFieldTemplate, { id: descriptionId(idSchema), description: description, schema: schema, uiSchema: uiSchema, registry: registry })),
React.createElement(Grid, { container: true, spacing: 2, style: { marginTop: "10px" } },
properties.map((element, index) =>
Expand Down
9 changes: 8 additions & 1 deletion src/other/rjsf/templates/ObjectFieldTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ import {
} from "@rjsf/utils";
import React from "react";

function isNumeric(str: string) {
return (
!Number.isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
!Number.isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail
);
}

export default function ObjectFieldTemplate<
T = any,
S extends StrictRJSFSchema = RJSFSchema,
Expand Down Expand Up @@ -56,7 +63,7 @@ export default function ObjectFieldTemplate<

return (
<Box className="ObjectFieldTemplate">
{title && (
{title && !isNumeric(title) && (
<TitleFieldTemplate
id={titleId<T>(idSchema)}
title={title}
Expand Down

0 comments on commit 24ab57e

Please sign in to comment.