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 6 months ago • 1 comments

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