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

Array of (Enum or other) not working properly

Open alphatownsman opened this issue 6 months ago • 2 comments

If the schema is organized as following, all const options are incorrectly mapped to the previous one.

{
  "type": "array",
  "title": "Languages",
  "items": {
    "oneOf": [
      {"const": "en","title": "English"},
      {"const": "fr","title": "French"},
      {"const": "zh","title": "Chinese"},
      {"title": "Other","type": "string"}
    ]
  },
  "uniqueItems":true
}

by moving {"title": "Other","type": "string"} to be the first element, it solves the mapping, but loses the ability to greyout/readonly the text input while selecting a const

{
  "type": "array",
  "title": "Languages",
  "items": {
    "oneOf": [
      {"title": "Other","type": "string"},
      {"const": "en","title": "English"},
      {"const": "fr","title": "French"},
      {"const": "zh","title": "Chinese"}
    ]
  },
  "uniqueItems":true
}

alphatownsman avatar May 21 '25 12:05 alphatownsman

Dig a bit deeper, even only 2 const options has same problem

{
  "type": "array",
  "title": "Languages",
  "items": {
    "oneOf": [
      {"const": "en","title": "English"},
      {"const": "fr","title": "French"}
    ]
  },
  "uniqueItems":true
}

When reduce the option to one, click add item will reset the playground

{
  "type": "array",
  "title": "Languages",
  "items": {
    "oneOf": [
      {"const": "fr","title": "French"}
    ]
  },
  "uniqueItems":true
}

alphatownsman avatar May 21 '25 12:05 alphatownsman

Thanks for opening the issue and taking the time to test out multiple cases. That was really helpful.

I've found the cause of this and it's a really silly typo on this line: https://github.com/bhch/react-json-form/blob/master/src/ui.js#L738. It should be index = i instead of index = 1.

I'll release the fix soon.

bhch avatar May 21 '25 18:05 bhch