react-json-form
react-json-form copied to clipboard
Array of (Enum or other) not working properly
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
}
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
}
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.