Commit b69a38c9 authored by Boris Kocherov's avatar Boris Kocherov

render unrequired fields for simple types and not schema editor

parent 96f59c1d
...@@ -191,6 +191,16 @@ ...@@ -191,6 +191,16 @@
return false; return false;
} }
function checkSchemaSimpleType(schema) {
return [
'string',
'integer',
'number',
'boolean',
'null'
].indexOf(schema.type) >=0;
}
function convertExpandedProperties2array(properties) { function convertExpandedProperties2array(properties) {
var property_name, var property_name,
arr = [], arr = [],
...@@ -787,6 +797,8 @@ ...@@ -787,6 +797,8 @@
render_object = function (g, json_field, default_dict, root, path, schema_path) { render_object = function (g, json_field, default_dict, root, path, schema_path) {
var required = json_field.required || [], var required = json_field.required || [],
schema_editor = json_field.hasOwnProperty("properties") &&
json_field.properties.hasOwnProperty("$schema"),
used_properties = {}, used_properties = {},
properties, properties,
selector = {}; selector = {};
...@@ -819,13 +831,20 @@ ...@@ -819,13 +831,20 @@
if (properties.hasOwnProperty(key)) { if (properties.hasOwnProperty(key)) {
schema_arr = properties[key]; schema_arr = properties[key];
s_o = schemaArrFilteredByDocument(schema_arr, default_dict[key]); s_o = schemaArrFilteredByDocument(schema_arr, default_dict[key]);
if (required.indexOf(key) >= 0 && schema_arr.length === 1) { if (required.indexOf(key) >= 0 && checkSchemaArrOneChoise(schema_arr)) {
used_properties[key] = false; used_properties[key] = false;
q.push(render_field.bind(g, g, key, path, q.push(render_field.bind(g, g, key, path,
s_o.schema, default_dict[key], root, s_o.schema_path, {required: true}) s_o.schema, default_dict[key], root, s_o.schema_path, {required: true})
); );
} }
if (default_dict.hasOwnProperty(key) && !used_properties.hasOwnProperty(key)) { if (!used_properties.hasOwnProperty(key) &&
(default_dict.hasOwnProperty(key) ||
( !schema_editor &&
checkSchemaArrOneChoise(schema_arr) &&
s_o.schema &&
checkSchemaSimpleType(s_o.schema)
)
)) {
used_properties[key] = ""; used_properties[key] = "";
q.push( q.push(
addSubForm.bind(g, { addSubForm.bind(g, {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment