react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

ObjectFieldTemplate Never gets the uiSchema passed into it

Open gurnro opened this issue 2 years ago • 7 comments

Prerequisites

What theme are you using?

mui

Version

5.x

Current Behavior

Inside the MUI method : ObjectFieldTemplate(props).

The uiSchema is never passed in through the props, I am trying to extend the functionality a little you see and wanted to do through using ui:options.

However the object never seems to get passed in

Expected Behavior

I would expect that uiSchema would exist on this object since it's referenced and there are calls using it inside the method.

I've attached some hacky code to show you where this is missing.

Steps To Reproduce

  /** The `ObjectFieldTemplate` is the template to use to render all the inner properties of an object along with the
   * title and description if available. If the object is expandable, then an `AddButton` is also rendered after all
   * the properties.
   *
   * @param props - The `ObjectFieldTemplateProps` for this component
   */
  function ObjectFieldTemplate(props) {
    var description = props.description,
      title = props.title,
      properties = props.properties,
      required = props.required,
      disabled = props.disabled,
      readonly = props.readonly,
      uiSchema = props.uiSchema,
      idSchema = props.idSchema,
      schema = props.schema,
      formData = props.formData,
      onAddClick = props.onAddClick,
      registry = props.registry;
    var uiOptions = utils.getUiOptions(uiSchema);
    var TitleFieldTemplate = utils.getTemplate("TitleFieldTemplate", registry, uiOptions);
    var DescriptionFieldTemplate = utils.getTemplate("DescriptionFieldTemplate", registry, uiOptions);
    // Button templates are not overridden in the uiSchema
    var AddButton = registry.templates.ButtonTemplates.AddButton;

    var fullWidth = uiOptions.columnWidth ? false : true;
    var columnWidth = uiOptions.columnWidth || 6;

    console.log("object field PROPS", props);
    console.log("object field UIOPTIONS", uiOptions); // always empty
    console.log("object field FW", fullWidth);
    console.log("object field CW", columnWidth);

    return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, (uiOptions.title || title) && /*#__PURE__*/React__default["default"].createElement(TitleFieldTemplate, {
      id: utils.titleId(idSchema),
      title: title,
      required: required,
      schema: schema,
      uiSchema: uiSchema,
      registry: registry
    }), (uiOptions.description || description) && /*#__PURE__*/React__default["default"].createElement(DescriptionFieldTemplate, {
      id: utils.descriptionId(idSchema),
      description: uiOptions.description || description,
      schema: schema,
      uiSchema: uiSchema,
      registry: registry
    }), /*#__PURE__*/React__default["default"].createElement(Grid__default["default"], {
      container: true,
      spacing: 2,
      style: {
        marginTop: "10px"
      }
    }, properties.map(function (element, index) {
      return (
        // Remove the <Grid> if the inner element is hidden as the <Grid>
        // itself would otherwise still take up space.
        element.hidden ? element.content : /*#__PURE__*/React__default["default"].createElement(Grid__default["default"], {
          item: true,
          xs: 12,
          key: index,
          style: {
            marginBottom: "10px"
          }
        }, element.content)
      );
    }), utils.canExpand(schema, uiSchema, formData) && /*#__PURE__*/React__default["default"].createElement(Grid__default["default"], {
      container: true,
      justifyContent: "flex-end"
    }, /*#__PURE__*/React__default["default"].createElement(Grid__default["default"], {
      item: true
    }, /*#__PURE__*/React__default["default"].createElement(AddButton, {
      className: "object-property-expand",
      onClick: onAddClick(schema),
      disabled: disabled || readonly,
      uiSchema: uiSchema,
      registry: registry
    })))));
  }

Environment

Node

Anything else?

No response

gurnro avatar Jan 30 '23 23:01 gurnro

I believe this is line 238 in this file where it's set to {}

https://github.com/rjsf-team/react-jsonschema-form/blob/5555123b72c040f47eb2d9299de9bd3603888248/packages/core/src/components/fields/ObjectField.tsx

gurnro avatar Jan 31 '23 11:01 gurnro

@gurnro If you can't reproduce this in the playground, could you link to a Codepen or JSFiddle example so someone can get to the bottom of this? Or you are welcome to create a pull request yourself. Thanks!

nickgros avatar Feb 03 '23 16:02 nickgros

Hi Nick, Ive been trying to get to the bottom of it in the code so I can do a PR!

gurnro avatar Feb 03 '23 17:02 gurnro

@gurnro Awesome, thanks for being willing to contribute

heath-freenome avatar Feb 24 '23 17:02 heath-freenome

This issue has been automatically marked as possibly close because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.

stale[bot] avatar May 25 '24 19:05 stale[bot]

This issue was closed because of lack of recent activity. Reopen if you still need assistance.

stale[bot] avatar Jun 24 '24 23:06 stale[bot]

@gurnro Are you able to help fix this?

heath-freenome avatar Jun 25 '24 17:06 heath-freenome

This issue was closed because of lack of recent activity. Reopen if you still need assistance.

stale[bot] avatar Jul 25 '24 22:07 stale[bot]