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

How can I replace anyOf titles with uiSchema?

Open perelin opened this issue 1 year ago • 1 comments
trafficstars

Prerequisites

What theme are you using?

core

What is your question?

Hi all!

My schema has a list of countries in anyOf that each have const and title (displayed as a dropdown). I want to use uiSchema to change the title (for l10n).

According to the documentation this should be well supported: https://rjsf-team.github.io/react-jsonschema-form/docs/api-reference/uiSchema#anyof

Here is a playground link with the example from the documentation that shows this is working in principle playground link

But I have not been able to replicate the effect with my schema snippet here. The titles stay as defined in the JSONSchema 😭: playground link

JSONSchema:

{
  "properties": {
    "personalInformation": {
      "properties": {
        "country": {
          "anyOf": [
            {
              "const": "AT",
              "title": "AT"
            },
            {
              "const": "BE",
              "title": "BE"
            }
          ],
          "type": "string"
        }
      },
      "type": "object"
    }
  }
}

uiSchema:

{
  "personalInformation": {
    "country": {
      "anyOf": [
        {
          "ui:title": "Country1"
        },
        {
          "ui:title": "Country2"
        }
      ]
    }
  }
}

note: the JSONSchema gets auto-generated based on an external spec. Hard to change this. I would very much like to be able to tackle this with uiSchema, which I can define myself.

Any ideas welcome! Thanks!

perelin avatar Jul 31 '24 14:07 perelin

@perelin at the moment there isn't a way to do what you want. I am going to implement it in the next week or so. Stay tuned.

The feature you are mentioned in the first playground link was for the multi-schema selector. What you are showing is a simple selection of a primitive value.

heath-freenome avatar Aug 02 '24 19:08 heath-freenome

Fixed by #4263

heath-freenome avatar May 12 '25 00:05 heath-freenome