diff --git a/client/src/components/Draftail/index.js b/client/src/components/Draftail/index.js index 748996749..741afa0b2 100644 --- a/client/src/components/Draftail/index.js +++ b/client/src/components/Draftail/index.js @@ -50,7 +50,9 @@ export const wrapWagtailIcon = type => { const initEditor = (selector, options, currentScript) => { // document.currentScript is not available in IE11. Use a fallback instead. const context = currentScript ? currentScript.parentNode : document.body; - const field = context.querySelector(selector); + // If the field is not in the current context, look for it in the whole body. + // Fallback for sequence.js jQuery eval-ed scripts running in document.head. + const field = context.querySelector(selector) || document.body.querySelector(selector); const editorWrapper = document.createElement('div'); editorWrapper.className = 'Draftail-Editor__wrapper'; diff --git a/client/src/components/Draftail/index.test.js b/client/src/components/Draftail/index.test.js index 49973b2bd..cf3ce15e8 100644 --- a/client/src/components/Draftail/index.test.js +++ b/client/src/components/Draftail/index.test.js @@ -88,6 +88,18 @@ describe('Draftail', () => { expect(document.querySelector('[name="last"]').draftailEditor).toBeDefined(); }); + + it('uses fallback document.body when currentScript context is wrong', () => { + window.draftail = draftail; + document.body.innerHTML = ` + +