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,6 +57,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
});
function toggleOtherEditorDisplay() {
var editor = document.querySelector('#id_editor');
var otherEditor = document.querySelector('#id_other_editor').parentElement;
@ -66,14 +67,9 @@ document.addEventListener("DOMContentLoaded", function (event) {
else {
otherEditor.style.display = 'none';
}
}
toggleOtherEditorDisplay();
editor.addEventListener('change', function(event) {
if (editor.options[editor.selectedIndex].text.toLowerCase().indexOf('autre') !== -1) {
otherEditor.style.display = 'block';
}
else {
otherEditor.style.display = 'none';
}
});
document.querySelector('#id_editor').addEventListener('change', toggleOtherEditorDisplay);
});