brutusin/json-forms

Nulls are returned instead of empty strings

Opened this issue · 1 comments

When new sting elements are added and they are not filled with any data, nulls are returned instead. However it should be empty strings according to the schema.

See the screenshot:

Screen Shot 2019-08-14 at 2 50 09 PM

function processOptions(parentId, names, data, cb) {
var schemas = {};
var schema = { type: "string" };

if (data[parentId] === "efg") {
schema.title = "efg";
schema.enum = ["", ""];
} else if (data[parentId] === "abc") {
schema.title = "abc";
schema.enum = ["", ""];
}

// Check for null values and convert them to empty strings
var subOptionValue = data[parentId + ".suboption1"];
if (subOptionValue === null) {
subOptionValue = "";
}

schemas["$.sub" + parentId] = schema;
schemas["$.sub" + parentId].default = subOptionValue;
setTimeout(function() {
cb(schemas);
}, 500); // in order to show asynchrony
}