} The TinyMCE instance\n */\nexport const setupForTarget = async(target, options = {}) => {\n const instance = getInstanceForElement(target);\n if (instance) {\n return Promise.resolve(instance);\n }\n\n // Register a new pending promise to ensure that Behat waits for the editor setup to complete before continuing.\n const pendingPromise = new Pending('editor_tiny/editor:setupForTarget');\n\n // Get the list of plugins.\n const plugins = getPlugins(options);\n\n // Fetch the tinyMCE API, and instantiate the plugins.\n const [tinyMCE, pluginValues] = await Promise.all([\n getTinyMCE(),\n importPluginList(Object.keys(plugins)),\n ]);\n\n // TinyMCE uses the element ID as a map key internally, even if the target has changed.\n // In the case where we have an editor in a modal form which has been detached from the DOM, but the editor not removed,\n // we need to manually destroy the editor.\n // We could theoretically do this with a Mutation Observer, but in some cases the Node may be moved,\n // or added back elsewhere in the DOM.\n\n // First remove any detached editors.\n tinyMCE.get().filter((editor) => !editor.getElement().isConnected).forEach((editor) => {\n editor.remove();\n });\n\n // Now check for any existing editor which shares the same ID.\n const existingEditor = tinyMCE.EditorManager.get(target.id);\n if (existingEditor) {\n if (existingEditor.getElement() === target) {\n pendingPromise.resolve();\n return Promise.resolve(existingEditor);\n } else {\n pendingPromise.resolve();\n throw new Error('TinyMCE instance already exists for different target with same ID');\n }\n }\n\n // Get the editor configuration for this editor.\n const instanceConfig = getEditorConfiguration(target, tinyMCE, options, pluginValues);\n\n // Initialise the editor instance for the given configuration.\n // At this point any plugin which has configuration options registered will have them applied for this instance.\n const [editor] = await tinyMCE.init(instanceConfig);\n\n // Update the textarea when the editor to set the field type for Behat.\n target.dataset.fieldtype = 'editor';\n\n // Store the editor instance in the instanceMap and register a listener on removal to remove it from the map.\n instanceMap.set(target, editor);\n editor.on('remove', ({target}) => {\n // Handle removal of the editor from the map on destruction.\n instanceMap.delete(target.targetElm);\n target.dataset.fieldtype = null;\n });\n\n // If the editor is part of a form, also listen to the jQuery submit event.\n // The jQuery submit event will not trigger the native submit event, and therefore the content will not be saved.\n // We cannot rely on listening to the bubbled submit event on the document because other events on child nodes may\n // consume the data before it is saved.\n if (target.form) {\n jQuery(target.form).on('submit', () => {\n editor.save();\n });\n }\n\n // Save the editor content to the textarea when the editor is blurred.\n editor.on('blur', () => {\n editor.save();\n });\n\n pendingPromise.resolve();\n return editor;\n};\n\n/**\n * Set the default editor configuration.\n *\n * This configuration is used when an editor is initialised without any configuration.\n *\n * @param {object} [options={}]\n */\nexport const configureDefaultEditor = (options = {}) => {\n defaultOptions = options;\n};\n"],"names":["instanceMap","Map","defaultOptions","importPluginList","async","pluginHandlers","Promise","all","pluginList","map","pluginPath","indexOf","resolve","pluginNames","pluginConfig","Array","isArray","filter","value","entries","elementId","getInstanceForElement","document","getElementById","element","instance","get","removed","remove","_ref","options","target","setupForTarget","lang","querySelector","tinyMCE","langData","language","fetch","M","cfg","wwwroot","langrev","then","response","json","addI18n","initialisePage","getPlugins","plugins","getStandardConfig","config","Object","assign","base_url","baseUrl","min_height","height","clientHeight","rows","window","getComputedStyle","lineHeight","content_css","css","convert_urls","a11y_advanced_options","extended_valid_elements","xss_sanitization","quickbars_insert_toolbar","block_formats","skin","promotion","branding","table_header_type","setup","editor","Options","register","on","contentWindow","this","iframeElement","nestedmenu","container","getContainer","menuContainer","parentNode","appendChild","nestMenu","e","params","open","style","overflow","pageWithDrawers","fixMenuPositionIfInFullsreen","state","browser","isSafari","fsplugin","isFullscreen","fixDialoguePositionIfOpen","Env","fullscreen","type","toolbar","getEditorConfiguration","pluginValues","instanceConfig","menu","file","items","format","replace","replaceAll","quickbars_selection_toolbar","configure","forEach","pluginInstanceOverride","getInitialPluginConfiguration","pendingPromise","Pending","keys","getElement","isConnected","existingEditor","EditorManager","id","Error","init","dataset","fieldtype","set","_ref2","delete","targetElm","form","save"],"mappings":"4oDAmCMA,YAAc,IAAIC,QAMpBC,eAAiB,SAQfC,iBAAmBC,MAAAA,mBAGfC,qBAAuBC,QAAQC,IAAIC,WAAWC,KAAIC,aACnB,IAA7BA,WAAWC,QAAQ,KAEZL,QAAQM,QAAQF,4NAGbA,4WAAAA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AAuB5E,OAAQI,QAASL,QAAS8E,eAIjEhC,cAAgBzC,QAAQ+F,KAAKrB,uBAGpC9E,OAAOoG,QAAQC,UAAY,SAG3BpI,YAAYqI,IAAItG,OAAQ6C,QACxBA,OAAOG,GAAG,UAAUuD,YAACvG,OAACA,cAElB/B,YAAYuI,OAAOxG,OAAOyG,WAC1BzG,OAAOoG,QAAQC,UAAY,QAO3BrG,OAAO0G,0BACA1G,OAAO0G,MAAM1D,GAAG,UAAU,KAC7BH,OAAO8D,UAKf9D,OAAOG,GAAG,QAAQ,KACdH,OAAO8D,UAGXjB,eAAe7G,UACRgE,+EAU2B,eAAC9C,+DAAU,GAC7C5B,eAAiB4B"}
\ No newline at end of file
diff --git a/lib/editor/tiny/amd/src/editor.js b/lib/editor/tiny/amd/src/editor.js
index 05980f3ac45..2a31a04857c 100644
--- a/lib/editor/tiny/amd/src/editor.js
+++ b/lib/editor/tiny/amd/src/editor.js
@@ -512,11 +512,15 @@ export const setupForTarget = async(target, options = {}) => {
// At this point any plugin which has configuration options registered will have them applied for this instance.
const [editor] = await tinyMCE.init(instanceConfig);
+ // Update the textarea when the editor to set the field type for Behat.
+ target.dataset.fieldtype = 'editor';
+
// Store the editor instance in the instanceMap and register a listener on removal to remove it from the map.
instanceMap.set(target, editor);
editor.on('remove', ({target}) => {
// Handle removal of the editor from the map on destruction.
instanceMap.delete(target.targetElm);
+ target.dataset.fieldtype = null;
});
// If the editor is part of a form, also listen to the jQuery submit event.
diff --git a/lib/editor/tiny/tests/behat/non_form_fields.feature b/lib/editor/tiny/tests/behat/non_form_fields.feature
new file mode 100644
index 00000000000..e8b784ab743
--- /dev/null
+++ b/lib/editor/tiny/tests/behat/non_form_fields.feature
@@ -0,0 +1,29 @@
+@editor_tiny @qtype_essay @javascript
+Feature: Set tiny editor values when the editor is not in a form
+ As an automated tester
+ In order to use a non-form editor
+ I need to set values
+
+ Background:
+ Given the following "users" exist:
+ | username |
+ | teacher |
+ And the following "courses" exist:
+ | fullname | shortname | category |
+ | Course 1 | C1 | 0 |
+ And the following "course enrolments" exist:
+ | user | course | role |
+ | teacher | C1 | editingteacher |
+ And the following "question categories" exist:
+ | contextlevel | reference | name |
+ | Course | C1 | Test questions |
+ And the following "questions" exist:
+ | questioncategory | qtype | name | template |
+ | Test questions | essay | essay | editorfilepicker |
+
+ Scenario: Preview an Essay question that uses the HTML editor with embedded files.
+ When I am on the "essay" "core_question > preview" page logged in as teacher
+ And I expand all fieldsets
+ And I set the following fields to these values:
+ | Answer text Question 1 | The cat sat on the mat. Then it ate a frog.
|
+ And I press "Submit and finish"