Skip to content

Commit

Permalink
fix #69
Browse files Browse the repository at this point in the history
  • Loading branch information
idelvall committed Mar 16, 2017
1 parent b6750cf commit cefc47c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
11 changes: 7 additions & 4 deletions dist/js/brutusin-json-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,14 +821,17 @@ if (typeof brutusin === "undefined") {
};

obj.getData = function () {
function removeEmptiesAndNulls(object, schema) {
function removeEmptiesAndNulls(object, s) {
if (s.$ref) {
s = getDefinition(s.$ref);
}
if (object instanceof Array) {
if (object.length === 0) {
return null;
}
var clone = new Array();
for (var i = 0; i < object.length; i++) {
clone[i] = removeEmptiesAndNulls(object[i], schema.items);
clone[i] = removeEmptiesAndNulls(object[i], s.items);
}
return clone;
} else if (object === "") {
Expand All @@ -840,13 +843,13 @@ if (typeof brutusin === "undefined") {
if (prop.startsWith("$") && prop.endsWith("$")) {
continue;
}
var value = removeEmptiesAndNulls(object[prop], schema.properties[prop]);
var value = removeEmptiesAndNulls(object[prop], s.properties[prop]);
if (value !== null) {
clone[prop] = value;
nonEmpty = true;
}
}
if (nonEmpty || schema.required) {
if (nonEmpty || s.required) {
return clone;
} else {
return null;
Expand Down
Loading

0 comments on commit cefc47c

Please sign in to comment.