rjsf-team / react-jsonschema-form

A React component for building Web forms from JSON Schema.
https://rjsf-team.github.io/react-jsonschema-form/
Apache License 2.0
14.09k stars 2.18k forks source link

ui:title changes multiple nested titles. How do I only change one or the other individually? #3942

Open hirenr opened 10 months ago

hirenr commented 10 months ago

Prerequisites

What theme are you using?

core

What is your question?

Hi, I am quite new to rjsf. I have a query that is leaving me stumped. ui:title is overriding both the nested titles. I just want to change one or the other specifically. How do i do that?

Schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "RootTitle",
  "description": "Any xarf schema type.",
  "oneOf": [
    {
      "$schema": "http://json-schema.org/draft-07/schema#",
      "title": "Another Title",
      "description": "A format to report RPZ events.",
      "allOf": [
        {
          "description": "Base properties for all xarf reports",
          "type": "object"
        }
      ]
    }
  ]
}

uiSchema:

{}

Output: image

uiSchema:

{
  "ui:title": "Override"
}

Output: image

heath-freenome commented 10 months ago

For your use case the ui:title is applied to both because the oneOf is considered the same level as the root. Our uiSchema does not support the JSON Schema branches, instead it behaves more like formData in that it is flatten to the view structure. I'm not sure we can easily make the uiSchema do what you want. What is your use case for renaming the titles?

hirenr commented 10 months ago

Well, I do not define the json schema. It is part of a cross-industry accepted format. format example

I need to build the a form where I can choose one of the "oeOf" items in a select field. The object within the oneOf list, is a fairly complex format with its own title. The example in the above post is derived from the xarf schema url.

In an ideal case, I just pass on the JsonSchema to rjsf with my own uiSchema to build a more human readable/understandable form.

The idea is to build something like abuse.cloudflare.com form with a select field at the top. In my case, the top level title would be renamed to "Choose an Abuse Report" and the next level title into the names of the individual type of reports.

Hope i make sense!

heath-freenome commented 9 months ago

If you don't have a title/description on the Root schema then you should be able to programmatically change the ui:title to be more relevant for the selected schema. You could keep the main title outside of the Form as a div or something to avoid the duplication

hirenr commented 9 months ago

True. That is exactly what I am planning to do. Keep the main title outside the schema. But this requires me to refactor an incoming schema that I do not own. I believe I cannot even selectively hide the root title. I wanted to just point to the public url of the schema by the schema owner.

heath-freenome commented 9 months ago

Does ui:hideLabel: true on the root work?