brutusin / json-forms

JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided
http://brutusin.org/json-forms
Apache License 2.0
606 stars 168 forks source link

Nulls are returned instead of empty strings #138

Open ghost opened 5 years ago

ghost commented 5 years ago

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

peeyush12345 commented 1 year ago

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 }