Skip to content

Commit

Permalink
backend: fixed request_params editor initialization if route changed
Browse files Browse the repository at this point in the history
  • Loading branch information
handcode committed Nov 17, 2021
1 parent 78f7939 commit 894a957
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions assets/backend/page-route-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,26 @@ $(function () {

if (editor !== undefined) {
var element = editor.element;

editor.destroy();

var editorIndex = jsonEditorList.indexOf(editor);
jsonEditorList[editorIndex] = new JSONEditor(element, {
schema: JSON.parse(schema),
theme: "bootstrap3",
ajax: true,
disable_collapse: true,
// disable_edit_json: true,
// disable_properties: true
});
// we only want to change schema, so get defined options from current editor.
var editorOptions = editor.options;
editorOptions.schema = JSON.parse(schema);
// recreate Editor
editor.destroy();
jsonEditorList[editorIndex] = new JSONEditor(element, editorOptions);

// inital update of value
$('input[name="Tree[request_params]"]').val(JSON.stringify(jsonEditorList[editorIndex].getValue()));

// update of value for newly inserted editor
$('#tree-request_params-container').on('change', function () {
// update/init change callback for newly inserted editor which update the input value
jsonEditorList[editorIndex].on('change', function () {
$('input[name="Tree[request_params]"]').val(JSON.stringify(jsonEditorList[editorIndex].getValue()));
});

} else {
console.error('Editor not found.');
}


}
} else {
console.error('Something went wrong.');
Expand Down

0 comments on commit 894a957

Please sign in to comment.