Fix other editor would not pop up anymore

This commit is contained in:
Gabriel Augendre 2018-06-16 10:46:48 +02:00
parent 979bc005d1
commit 2c74ea7a45
2 changed files with 14 additions and 15 deletions

View file

@ -76,15 +76,18 @@ document.addEventListener("DOMContentLoaded", function (event) {
editor.value = editorValue;
editor.classList.add('is-valid');
event = document.createEvent("HTMLEvents");
event.initEvent("change", true, true);
event.eventName = "change";
editor.dispatchEvent(event);
if (editorIsOther) {
otherEditor.value = data.editor;
otherEditor.classList.add('is-valid');
}
enableFields();
// The event propagation must be done after the fields have been re-enabled
// because a change event can't be propagated to a field that's disabled.
var event = document.createEvent("HTMLEvents");
event.initEvent("change", true, true);
event.eventName = "change";
document.querySelector('#id_editor').dispatchEvent(event);
});
});
});

View file

@ -57,23 +57,19 @@ document.addEventListener("DOMContentLoaded", function (event) {
});
var editor = document.querySelector('#id_editor');
var otherEditor = document.querySelector('#id_other_editor').parentElement;
function toggleOtherEditorDisplay() {
var editor = document.querySelector('#id_editor');
var otherEditor = document.querySelector('#id_other_editor').parentElement;
if (editor.options[editor.selectedIndex].text.toLowerCase().indexOf('autre') !== -1) {
otherEditor.style.display = 'block';
}
else {
otherEditor.style.display = 'none';
}
editor.addEventListener('change', function(event) {
if (editor.options[editor.selectedIndex].text.toLowerCase().indexOf('autre') !== -1) {
otherEditor.style.display = 'block';
}
else {
otherEditor.style.display = 'none';
}
});
}
toggleOtherEditorDisplay();
document.querySelector('#id_editor').addEventListener('change', toggleOtherEditorDisplay);
});