Commit 91ee6c4f authored by Rafael Monnerat's avatar Rafael Monnerat

erp5_json_editor: Disable ajax and catch promise

   The JSONEditor relies on call async load for load promises. The current code waits for the promises to finish and throw errors explicitly.

    This allows the renderjs properly handle the error on the same chain of promises.
parent 26d4a0c4
...@@ -152,12 +152,12 @@ ...@@ -152,12 +152,12 @@
JSONEditor.defaults.editors.string.prototype.setValueToInputField = function (value) { JSONEditor.defaults.editors.string.prototype.setValueToInputField = function (value) {
this.input.value = value === undefined ? '' : value; this.input.value = value === undefined ? '' : value;
/* ERP5: Once you set the value to the input, you also /* ERP5: Once you set the value to the input, you also
updates the field value, otherwise the getValue will miss the value */ updates the field value, otherwise the getValue will miss the value */
this.value = this.input.value; this.value = this.input.value;
}; };
/* Backward compatibility with the usage of textarea property /* Backward compatibility with the usage of textarea property
if converts into json-editor proper property */ if converts into json-editor proper property */
JSONEditor.defaults.editors.string.prototype.preBuild = function () { JSONEditor.defaults.editors.string.prototype.preBuild = function () {
if ((this.schema.textarea === true) || (this.schema.textarea === 1)) { if ((this.schema.textarea === true) || (this.schema.textarea === 1)) {
...@@ -188,7 +188,7 @@ ...@@ -188,7 +188,7 @@
} }
// Ignore the first attempt since editor trigger change on the after the // Ignore the first attempt since editor trigger change on the after the
// end of the rendering, so ignore the first attempt is reaquired. // end of the rendering, so ignore the first attempt is reaquired.
// Later calls that trigger change // Later calls that trigger change
gadget.state.ignoredChangeDuringInitialization = false; gadget.state.ignoredChangeDuringInitialization = false;
} }
...@@ -221,7 +221,7 @@ ...@@ -221,7 +221,7 @@
.push(function (schema) { .push(function (schema) {
return new JSONEditor(domsugar(json_editor_container), { return new JSONEditor(domsugar(json_editor_container), {
schema: schema, schema: schema,
ajax: true, ajax: false,
theme: 'bootstrap5', theme: 'bootstrap5',
show_errors: 'always', show_errors: 'always',
//iconlib: 'fontawesome5', //iconlib: 'fontawesome5',
...@@ -249,6 +249,14 @@ ...@@ -249,6 +249,14 @@
// it seems to crash rjs somewhere. To check... // it seems to crash rjs somewhere. To check...
// https://lab.nexedi.com/nexedi/renderjs/blob/master/renderjs.js#L2070 // https://lab.nexedi.com/nexedi/renderjs/blob/master/renderjs.js#L2070
//return editor; //return editor;
// editor relies on async load function, so we need to await the promise
// to finish before continue, otherwise rendering errors wont throw Errors
// in the same stack as expected.
return editor.promise.catch();
})
.push(undefined, function (err) {
throw new Error(err);
}); });
}) })
.declareMethod('getContent', function () { .declareMethod('getContent', function () {
......
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