- bug TRA-68 solved - bug in javascript code did not pass changed json content.
This commit is contained in:
@@ -40,10 +40,10 @@ window.EveAI.JsonEditors = {
|
||||
mainMenuBar: options.mainMenuBar !== undefined ? options.mainMenuBar : true,
|
||||
navigationBar: options.navigationBar !== undefined ? options.navigationBar : false,
|
||||
statusBar: options.statusBar !== undefined ? options.statusBar : !isReadOnly,
|
||||
onChange: (updatedContent, previousContent, { contentErrors, patchResult }) => {
|
||||
// content is an object { json: unknown } | { text: string }
|
||||
console.log('onChange', { updatedContent, previousContent, contentErrors, patchResult })
|
||||
}
|
||||
onChange: options.onChange || ((updatedContent, previousContent, { contentErrors, patchResult }) => {
|
||||
// Default onChange behavior - alleen loggen
|
||||
console.log('onChange', { updatedContent, previousContent, contentErrors, patchResult });
|
||||
})
|
||||
};
|
||||
console.log('EditorProps', editorProps);
|
||||
|
||||
@@ -107,13 +107,51 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
window.EveAI.JsonEditors.initialize(containerId, data, {
|
||||
mode: isReadOnly ? 'preview' : 'tree',
|
||||
readOnly: isReadOnly,
|
||||
onChangeText: isReadOnly ? undefined : (jsonString) => { textarea.value = jsonString; }
|
||||
onChange: isReadOnly ? undefined : (updatedContent, previousContent, { contentErrors, patchResult }) => {
|
||||
// Automatische synchronisatie naar textarea bij elke wijziging
|
||||
if (updatedContent.json !== undefined) {
|
||||
textarea.value = JSON.stringify(updatedContent.json, null, 2);
|
||||
} else if (updatedContent.text !== undefined) {
|
||||
textarea.value = updatedContent.text;
|
||||
}
|
||||
console.log('Textarea automatisch bijgewerkt via onChange');
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Error parsing initial JSON for .json-editor:', e);
|
||||
container.innerHTML = `<div class="alert alert-danger p-3"><strong>Error loading JSON data:</strong><br>${e.message}</div>`;
|
||||
}
|
||||
});
|
||||
|
||||
// Real-time synchronisatie als extra beveiliging
|
||||
setInterval(function() {
|
||||
document.querySelectorAll('.json-editor').forEach(function(textarea) {
|
||||
if (textarea.style.display === 'none') { // Alleen voor verborgen textareas (zoals in edit forms)
|
||||
const containerId = textarea.id + '-editor';
|
||||
const editor = window.EveAI?.JsonEditors?.get(containerId);
|
||||
if (editor && editor.get) {
|
||||
try {
|
||||
const content = editor.get();
|
||||
let newValue = '';
|
||||
if (content.json !== undefined) {
|
||||
newValue = JSON.stringify(content.json, null, 2);
|
||||
} else if (content.text !== undefined) {
|
||||
newValue = content.text;
|
||||
}
|
||||
|
||||
// Alleen updaten als de waarde daadwerkelijk is veranderd
|
||||
if (textarea.value !== newValue) {
|
||||
textarea.value = newValue;
|
||||
console.log('Real-time sync uitgevoerd voor', textarea.id);
|
||||
}
|
||||
} catch (e) {
|
||||
// Stil falen - geen console spam
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 1000); // Elke seconde controleren
|
||||
|
||||
// Alleen-lezen containers
|
||||
document.querySelectorAll('.json-viewer').forEach(function(container) {
|
||||
const dataElement = document.getElementById(container.id + '-data');
|
||||
|
||||
Reference in New Issue
Block a user