diff --git a/manuels/static/manuels/fetch-isbn.js b/manuels/static/manuels/fetch-isbn.js index 878c6cb..0543843 100644 --- a/manuels/static/manuels/fetch-isbn.js +++ b/manuels/static/manuels/fetch-isbn.js @@ -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); }); }); }); diff --git a/manuels/static/manuels/no_book.js b/manuels/static/manuels/no_book.js index a0b9a46..675c1e6 100644 --- a/manuels/static/manuels/no_book.js +++ b/manuels/static/manuels/no_book.js @@ -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); });