Commit fa45756e authored by Boris Kocherov's avatar Boris Kocherov

support `default` value worked with `enum`

parent ed436c28
...@@ -111,24 +111,30 @@ ...@@ -111,24 +111,30 @@
function render_selection(schema, json_document) { function render_selection(schema, json_document) {
var input = document.createElement("select"), var input = document.createElement("select"),
option = document.createElement("option"), option,
option_index, option_index;
optionz;
input.size = 1; input.size = 1;
option.value = ""; if (schema.default) {
if (json_document === undefined) { if (json_document === undefined) {
option.selected = "selected"; json_document = schema.default;
}
} else {
option = document.createElement("option");
option.value = "";
if (json_document === undefined) {
option.selected = "selected";
}
input.appendChild(option);
} }
input.appendChild(option);
for (option_index in schema['enum']) { for (option_index in schema['enum']) {
if (schema['enum'].hasOwnProperty(option_index)) { if (schema['enum'].hasOwnProperty(option_index)) {
optionz = document.createElement("option"); option = document.createElement("option");
optionz.value = schema['enum'][option_index]; option.value = schema['enum'][option_index];
optionz.textContent = schema['enum'][option_index]; option.textContent = schema['enum'][option_index];
if (schema['enum'][option_index] === json_document) { if (schema['enum'][option_index] === json_document) {
optionz.selected = "selected"; option.selected = "selected";
} }
input.appendChild(optionz); input.appendChild(option);
} }
} }
return input; return input;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment