Commit 35492a16 authored by Boris Kocherov's avatar Boris Kocherov

notify about changes after rendering if document changed during render

parent 26024012
...@@ -684,6 +684,11 @@ ...@@ -684,6 +684,11 @@
.push(function () { .push(function () {
return g.checkValidity(); return g.checkValidity();
}) })
.push(function () {
if (g.props.form_gadget.props.changed) {
g.notifyChange();
}
})
.push(function () { .push(function () {
return g; return g;
}); });
......
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
return schema; return schema;
} }
function render_enum(schema, json_document) { function render_enum(g, schema, json_document) {
var input = document.createElement("select"), var input = document.createElement("select"),
option, option,
i, i,
...@@ -132,6 +132,7 @@ ...@@ -132,6 +132,7 @@
if (schema.default) { if (schema.default) {
if (json_document === undefined) { if (json_document === undefined) {
json_document = schema.default; json_document = schema.default;
g.props.changed = true;
} }
} else { } else {
option = document.createElement("option"); option = document.createElement("option");
...@@ -177,7 +178,7 @@ ...@@ -177,7 +178,7 @@
return input; return input;
} }
function render_boolean(schema, json_document) { function render_boolean(g, schema, json_document) {
var input, var input,
schema_for_selection = { schema_for_selection = {
type: "boolean", type: "boolean",
...@@ -193,7 +194,7 @@ ...@@ -193,7 +194,7 @@
if (getDocumentType(schema.default) === "boolean") { if (getDocumentType(schema.default) === "boolean") {
schema_for_selection.default = schema.default; schema_for_selection.default = schema.default;
} }
input = render_enum(schema_for_selection, json_document); input = render_enum(g, schema_for_selection, json_document);
input.setAttribute('data-json-type', "boolean"); input.setAttribute('data-json-type', "boolean");
return input; return input;
} }
...@@ -274,6 +275,12 @@ ...@@ -274,6 +275,12 @@
document: options.default_dict, document: options.default_dict,
display_label: options.parent_type !== "array", display_label: options.parent_type !== "array",
scope: scope scope: scope
})
.push(function () {
if (form_gadget.props.changed) {
g.props.changed = true;
}
return form_gadget.element;
}); });
}); });
} }
...@@ -777,7 +784,7 @@ ...@@ -777,7 +784,7 @@
if (json_field.const !== undefined) { if (json_field.const !== undefined) {
input = render_const(json_field, default_value); input = render_const(json_field, default_value);
} else if (json_field.enum !== undefined) { } else if (json_field.enum !== undefined) {
input = render_enum(json_field, default_value); input = render_enum(gadget, json_field, default_value);
// XXX take in account existing type with enum // XXX take in account existing type with enum
type_changed = false; type_changed = false;
} }
...@@ -787,7 +794,7 @@ ...@@ -787,7 +794,7 @@
} }
if (!input && type === "boolean") { if (!input && type === "boolean") {
input = render_boolean(json_field, default_value); input = render_boolean(gadget, json_field, default_value);
} }
if (!input && ["string", "integer", "number", "null"].indexOf(type) >= 0) { if (!input && ["string", "integer", "number", "null"].indexOf(type) >= 0) {
...@@ -806,6 +813,7 @@ ...@@ -806,6 +813,7 @@
if (type === "integer" || type === "number") { if (type === "integer" || type === "number") {
if (default_value === undefined && typeof json_field.default === "number") { if (default_value === undefined && typeof json_field.default === "number") {
input.value = json_field.default; input.value = json_field.default;
gadget.props.changed = true;
} }
input.setAttribute("data-json-type", type); input.setAttribute("data-json-type", type);
if (default_value === undefined || default_value === null || if (default_value === undefined || default_value === null ||
...@@ -827,6 +835,7 @@ ...@@ -827,6 +835,7 @@
} else { } else {
if (default_value === undefined && typeof json_field.default === "string") { if (default_value === undefined && typeof json_field.default === "string") {
input.value = json_field.default; input.value = json_field.default;
gadget.props.changed = true;
} }
input.type = "text"; input.type = "text";
if (json_field.pattern) { if (json_field.pattern) {
...@@ -1607,6 +1616,7 @@ ...@@ -1607,6 +1616,7 @@
property_name = g.element.getAttribute('data-json-property-name'), property_name = g.element.getAttribute('data-json-property-name'),
schema = options.schema, schema = options.schema,
root; root;
g.props.change = false;
g.props.inputs = []; g.props.inputs = [];
g.props.add_buttons = []; g.props.add_buttons = [];
g.props.add_custom_data = {}; g.props.add_custom_data = {};
......
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