table format is no longer shown with enum arrays
General information
- json-editor version broken: 2.15.2
- json-editor version working: 2.10.0
Expected behavior
Should show table editor with add/remove buttons when type=array, format=table and items contains enum.
In version 2.10.0 and lower it works fine.
Actual behavior
Shows a multi-select input when type=array, format=table and items contains enum.
In version 2.11.0 and and higher it is broken.
Steps to reproduce the behavior
{
"title": "Format Table Not Working for enum arrays",
"type": "object",
"properties": {
"currencyList": {
"type": "array",
"format": "table",
"title": "Currency List",
"uniqueItems": true,
"items": {
"title": "Currency Code",
"type": "string",
"$ref": "#/definitions/code"
}
}
},
"definitions": {
"code": {
"enum": ["USD", "EUR", "CAD", "MXN"]
}
}
}
I can't reproduce locally this with 2.11, see screenshot
Sorry @schmunk42 , I didn't realize $ref was a factor in table format. I updated the original sample.
Here's an HTML sample of the table format. If you replace the version with 2.15.2 you'll see it stops working.
<!doctype html>
<html>
<head>
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/@json-editor/[email protected]/dist/jsoneditor.min.js"
></script>
</head>
<body>
<main id="editor"></main>
<script>
var options = {
schema: {
title: "Table Format",
type: "object",
properties: {
currencyList: {
type: "array",
format: "table",
title: "Currency List",
uniqueItems: true,
items: {
title: "Currency Code",
type: "string",
$ref: "#/definitions/code",
},
},
},
definitions: {
code: {
enum: ["USD", "EUR", "CAD", "MXN"],
},
},
},
};
const editor = new JSONEditor(document.getElementById("editor"), options);
</script>
</body>
</html>
It looks like table format is still in resolvers. I made a commit to pass it along to the table resolver. It will also show the table resolver if it is $ref or enum.
https://github.com/json-editor/json-editor/commit/303bd35126d5ebedd7228796787bb17f6addfa2a
The table format in conjunction with uniqueItems is problematic, since the UI does not prevent you from adding the same element twice, but if the format is explicitly specified it should be supported.
Could you create a PR with tests?
If you can include additional js, you can also give format choices or select2 (needs a reload in the demo) a try.
Note: We also found a validator.js bug with "uniqueItems": false, which would do what you need, but we need to fix this, so DO NOT USE :)
addon ... also choices often needs another click on "Update Schema" it should look like this:
I'd appreciate if you can elaborate on my questions below. I'm new to this library.
My understanding is that table format wasn't being reached because of an error in resolvers. Was table format intentionally removed?
For choices/select: I don't understand how choices or select2 relate to table format? Are you suggesting alternate options? I'd like this issue to represent "table format" or "not table format" rather than other options.
For tests: Looking at the code, table already has several tests (see below). Are you saying the tests need to be updated? Or suggesting more manual tests for the many situations/scenarios involving table?
- tests/unit/editors/table.spec.js
- test/pages/table.html
For uniqueItems=true: I see the UI issues. Validation does catch this and warns when duplicates exist. Maybe I can update table format UI and prevent duplicates.
For uniqueItems=false: Is there an existing bug number? I haven't tried this situation yet. I'll test next chance I get.
My understanding is that table format wasn't being reached because of an error in resolvers. Was table format intentionally removed?
It was not intentionally removed.
For choices/select: I don't understand how choices or select2 relate to table format? Are you suggesting alternate options? I'd like this issue to represent "table format" or "not table format" rather than other options.
I thought you "just" need to pick currencies into an array from a rather large list without duplicates. Multiselect is not very user-friendly here, but the mentioned plugins work well.
For tests: Looking at the code, table already has several tests (see below). Are you saying the tests need to be updated? Or suggesting more manual tests for the many situations/scenarios involving table?
I meant the specific use-case you have, which changed in 2.12.0.
For uniqueItems=true: I see the UI issues. Validation does catch this and warns when duplicates exist. Maybe I can update table format UI and prevent duplicates.
For uniqueItems=false: Is there an existing bug number? I haven't tried this situation yet. I'll test next chance I get.
No not yet. @germanbisurgi: Could you create one, you are more into the resolver stuff.