Commit 0fa703bd authored by Boris Kocherov's avatar Boris Kocherov

enum rendering improved. now it allow render complex objects.

imho not usable, but needed for tests
parent e3d91b30
...@@ -94,6 +94,8 @@ ...@@ -94,6 +94,8 @@
var input = document.createElement("select"), var input = document.createElement("select"),
option, option,
i, i,
ser_value,
selected = false,
enum_arr = schema['enum']; enum_arr = schema['enum'];
input.size = 1; input.size = 1;
if (schema.default) { if (schema.default) {
...@@ -111,14 +113,28 @@ ...@@ -111,14 +113,28 @@
for (i = 0; i < enum_arr.length; i += 1) { for (i = 0; i < enum_arr.length; i += 1) {
if (enum_arr.hasOwnProperty(i)) { if (enum_arr.hasOwnProperty(i)) {
option = document.createElement("option"); option = document.createElement("option");
option.value = enum_arr[i]; // XXX use number id for speedup
option.textContent = enum_arr[i]; ser_value = JSON.stringify(enum_arr[i]);
option.value = ser_value;
option.textContent = ser_value;
if (enum_arr[i] === json_document) { if (enum_arr[i] === json_document) {
option.selected = true; option.selected = true;
selected = true;
} }
input.appendChild(option); input.appendChild(option);
} }
} }
if (json_document !== undefined && !selected) {
// save original json_document even if it
// not support with schema
// XXX element should be removed on first user interact
option = document.createElement("option");
ser_value = JSON.stringify(json_document);
option.value = ser_value;
option.textContent = ser_value;
option.selected = true;
input.appendChild(option);
}
return input; return input;
} }
...@@ -1307,7 +1323,10 @@ ...@@ -1307,7 +1323,10 @@
} else { } else {
if (input.required || input.value !== "") { if (input.required || input.value !== "") {
var type = input.getAttribute('data-json-type'); var type = input.getAttribute('data-json-type');
if (type === 'number') { if (input.tagName === "SELECT" && input.value) {
// selection used for enums
json_dict[input.name] = JSON.parse(input.value);
} else if (type === 'number') {
json_dict[input.name] = parseFloat(input.value); json_dict[input.name] = parseFloat(input.value);
} else if (type === "integer") { } else if (type === "integer") {
json_dict[input.name] = parseInt(input.value, 10); json_dict[input.name] = parseInt(input.value, 10);
......
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