From 819ac33c863ca8730f99a35157acd642f7414a02 Mon Sep 17 00:00:00 2001 From: Pierre Pfister Date: Thu, 20 Jun 2019 09:33:04 +0200 Subject: [PATCH 1/2] Fix selected index when field is not required --- src/js/brutusin-json-forms.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/js/brutusin-json-forms.js b/src/js/brutusin-json-forms.js index 49ee5ea..9fc9924 100644 --- a/src/js/brutusin-json-forms.js +++ b/src/js/brutusin-json-forms.js @@ -203,10 +203,7 @@ if (typeof brutusin === "undefined") { input.disabled = true; } } - if (s.enum.length === 1) - input.selectedIndex = 0; - else - input.selectedIndex = selectedIndex; + input.selectedIndex = selectedIndex; } else { input = document.createElement("input"); if (s.type === "integer" || s.type === "number") { From 24ad71bc6b968cf440924dbbe8dd438061f3f50b Mon Sep 17 00:00:00 2001 From: Pierre Pfister Date: Thu, 20 Jun 2019 10:13:27 +0200 Subject: [PATCH 2/2] dependsOn support for getdata --- src/js/brutusin-json-forms.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/js/brutusin-json-forms.js b/src/js/brutusin-json-forms.js index 9fc9924..cbf680e 100644 --- a/src/js/brutusin-json-forms.js +++ b/src/js/brutusin-json-forms.js @@ -827,20 +827,24 @@ if (typeof brutusin === "undefined") { }; obj.getData = function () { - function removeEmptiesAndNulls(object, s) { + function removeEmptiesAndNulls(object, s, id) { if (s === null) { s = SCHEMA_ANY; } if (s.$ref) { s = getDefinition(s.$ref); } + if (s.hasOwnProperty('dependsOn')) { + s = getSchema(getSchemaId(id)); + return removeEmptiesAndNulls(object, s, id); + } if (object instanceof Array) { - if (object.length === 0) { + if (object.length === 0 || !s.hasOwnProperty("items")) { return null; } var clone = new Array(); for (var i = 0; i < object.length; i++) { - clone[i] = removeEmptiesAndNulls(object[i], s.items); + clone[i] = removeEmptiesAndNulls(object[i], s.items, id + "[" + i + "]"); } return clone; } else if (object === "") { @@ -870,7 +874,7 @@ if (typeof brutusin === "undefined") { } } } - var value = removeEmptiesAndNulls(object[prop], ss); + var value = removeEmptiesAndNulls(object[prop], ss, id+"."+prop); if (value !== null) { clone[prop] = value; nonEmpty = true; @@ -888,7 +892,7 @@ if (typeof brutusin === "undefined") { if (!container) { return null; } else { - return removeEmptiesAndNulls(data, schema); + return removeEmptiesAndNulls(data, schema, "$"); } };