From 376c86814a37344eb59e0e2a82ebc5de380d417e Mon Sep 17 00:00:00 2001 From: Nagarajan Chinnasamy Date: Sat, 9 Sep 2017 15:58:49 +0530 Subject: [PATCH 1/2] Dynamic Schema issues in array --- dist/js/brutusin-json-forms.js | 8 +-- examples/example1.html | 95 +++++++++++++++++++++++++++ examples/example2.html | 113 +++++++++++++++++++++++++++++++++ src/js/brutusin-json-forms.js | 20 +++--- 4 files changed, 220 insertions(+), 16 deletions(-) create mode 100644 examples/example1.html create mode 100644 examples/example2.html diff --git a/dist/js/brutusin-json-forms.js b/dist/js/brutusin-json-forms.js index cbecd7d..7d2a4f6 100644 --- a/dist/js/brutusin-json-forms.js +++ b/dist/js/brutusin-json-forms.js @@ -827,8 +827,8 @@ if (typeof brutusin === "undefined") { obj.getData = function () { function removeEmptiesAndNulls(object, s) { - if (ss === null) { - ss = SCHEMA_ANY; + if (!s) { // 03_AddLevel2Item_SelectOPTION-2.png + s = SCHEMA_ANY; // 03_AddLevel2Item_SelectOPTION-2.png } if (s.$ref) { s = getDefinition(s.$ref); @@ -1307,7 +1307,7 @@ if (typeof brutusin === "undefined") { function cleanSchemaMap(schemaId) { for (var prop in schemaMap) { - if (schemaId.startsWith(prop)) { + if (prop.startsWith(schemaId)) { // 02_AddLevel1Item_Delete_AgainAdd.png delete schemaMap[prop]; } } @@ -1409,7 +1409,7 @@ if (typeof brutusin === "undefined") { throw ("Node '" + name + "' is of type array"); } var element = currentToken.substring(1, currentToken.length - 1); - if (element.equals("#")) { + if (element === "#") { // 01_elementEquals.png for (var i = 0; i < data.length; i++) { var child = data[i]; visit(name + currentToken, queue.slice(0), child, data, i); diff --git a/examples/example1.html b/examples/example1.html new file mode 100644 index 0000000..d67887b --- /dev/null +++ b/examples/example1.html @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + diff --git a/examples/example2.html b/examples/example2.html new file mode 100644 index 0000000..b332c4c --- /dev/null +++ b/examples/example2.html @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + diff --git a/src/js/brutusin-json-forms.js b/src/js/brutusin-json-forms.js index 49ee5ea..7d2a4f6 100644 --- a/src/js/brutusin-json-forms.js +++ b/src/js/brutusin-json-forms.js @@ -177,6 +177,7 @@ if (typeof brutusin === "undefined") { } else if (s.media) { input = document.createElement("input"); input.type = "file"; + appendChild(input, option, s); // XXX TODO, encode the SOB properly. } else if (s.enum) { input = document.createElement("select"); @@ -204,7 +205,7 @@ if (typeof brutusin === "undefined") { } } if (s.enum.length === 1) - input.selectedIndex = 0; + input.selectedIndex = 1; else input.selectedIndex = selectedIndex; } else { @@ -222,10 +223,6 @@ if (typeof brutusin === "undefined") { // #46, problem in IE11. TODO polyfill? input.type = "text"; } - } else if (s.format === "date") { - input.type = "date"; - } else if (s.format === "time") { - input.type = "time"; } else if (s.format === "email") { input.type = "email"; } else if (s.format === "text") { @@ -348,8 +345,8 @@ if (typeof brutusin === "undefined") { if (s.required) { input = document.createElement("input"); input.type = "checkbox"; - if (value === true || value !== false && s.default) { - input.checked = true; + if (value === true) { + input.checked = true; } } else { input = document.createElement("select"); @@ -750,7 +747,6 @@ if (typeof brutusin === "undefined") { if (s.readOnly) addButton.disabled = true; addButton.setAttribute('type', 'button'); - addButton.className = "addItem"; addButton.getValidationError = function () { if (s.minItems && s.minItems > table.rows.length) { return BrutusinForms.messages["minItems"].format(s.minItems); @@ -831,8 +827,8 @@ if (typeof brutusin === "undefined") { obj.getData = function () { function removeEmptiesAndNulls(object, s) { - if (s === null) { - s = SCHEMA_ANY; + if (!s) { // 03_AddLevel2Item_SelectOPTION-2.png + s = SCHEMA_ANY; // 03_AddLevel2Item_SelectOPTION-2.png } if (s.$ref) { s = getDefinition(s.$ref); @@ -1311,7 +1307,7 @@ if (typeof brutusin === "undefined") { function cleanSchemaMap(schemaId) { for (var prop in schemaMap) { - if (prop.startsWith(schemaId)) { + if (prop.startsWith(schemaId)) { // 02_AddLevel1Item_Delete_AgainAdd.png delete schemaMap[prop]; } } @@ -1413,7 +1409,7 @@ if (typeof brutusin === "undefined") { throw ("Node '" + name + "' is of type array"); } var element = currentToken.substring(1, currentToken.length - 1); - if (element.equals("#")) { + if (element === "#") { // 01_elementEquals.png for (var i = 0; i < data.length; i++) { var child = data[i]; visit(name + currentToken, queue.slice(0), child, data, i); From bf5c2b424497c2c3564690d08ffbe13978554028 Mon Sep 17 00:00:00 2001 From: Nagarajan Chinnasamy Date: Mon, 18 Sep 2017 21:23:42 +0530 Subject: [PATCH 2/2] Dynamic Schema issues in array --- examples/example1.html | 95 +++++++++++++++++++++++++++++++++++ src/js/brutusin-json-forms.js | 6 +-- 2 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 examples/example1.html diff --git a/examples/example1.html b/examples/example1.html new file mode 100644 index 0000000..d67887b --- /dev/null +++ b/examples/example1.html @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + diff --git a/src/js/brutusin-json-forms.js b/src/js/brutusin-json-forms.js index 49ee5ea..6a269d7 100644 --- a/src/js/brutusin-json-forms.js +++ b/src/js/brutusin-json-forms.js @@ -349,7 +349,7 @@ if (typeof brutusin === "undefined") { input = document.createElement("input"); input.type = "checkbox"; if (value === true || value !== false && s.default) { - input.checked = true; + input.checked = true; } } else { input = document.createElement("select"); @@ -831,7 +831,7 @@ if (typeof brutusin === "undefined") { obj.getData = function () { function removeEmptiesAndNulls(object, s) { - if (s === null) { + if (!s) { s = SCHEMA_ANY; } if (s.$ref) { @@ -1413,7 +1413,7 @@ if (typeof brutusin === "undefined") { throw ("Node '" + name + "' is of type array"); } var element = currentToken.substring(1, currentToken.length - 1); - if (element.equals("#")) { + if (element === "#") { for (var i = 0; i < data.length; i++) { var child = data[i]; visit(name + currentToken, queue.slice(0), child, data, i);