From 929727e3efcd3ef52b1c02ea1b4790d5889eda66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Thu, 19 May 2016 13:20:44 +0200 Subject: [PATCH] MDL-54633 tinymce: Sync editors' iframe to textarea on form submit The previous commit "Automatically sync editor with its textarea" was found a not good solution as the onchange event is triggered way less often than needed for our needs. So this reverts commit 34321d49. Instead, we add a hack to the formslib so that when there are some TinyMCE editors used at the page, we explicitly save them before triggering the form validation. This simply calls save() on all editors on the page - see the API reference: http://archive.tinymce.com/wiki.php/API3:method.tinymce.triggerSave Having TinyMCE hardcoded like this on this core level does not make me happy. But it seems to be most effective solution for now (and definitely more efficient than the previous solution). Plus there is a precedence - we already use window.tinyMCE in formchangechecker.js YUI module, for example. --- lib/editor/tinymce/module.js | 7 ------- lib/formslib.php | 3 +++ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/editor/tinymce/module.js b/lib/editor/tinymce/module.js index 4b227d132bb..d3118ef0f33 100644 --- a/lib/editor/tinymce/module.js +++ b/lib/editor/tinymce/module.js @@ -45,7 +45,6 @@ M.editor_tinymce.init_editor = function(Y, editorid, options) { M.editor_tinymce.initialised = true; M.util.js_pending('editors'); options.oninit = "M.editor_tinymce.init_callback"; - options.onchange_callback = "M.editor_tinymce.onchange_callback"; } M.editor_tinymce.editor_options[editorid] = options; @@ -93,12 +92,6 @@ M.editor_tinymce.init_callback = function() { M.util.js_complete('editors'); } -M.editor_tinymce.onchange_callback = function(editorinstance) { - // We need to keep the underlying textarea in sync so that when the form - // validator is triggered, it has the value property up-to-date. - editorinstance.save(); -}; - M.editor_tinymce.init_filepicker = function(Y, editorid, options) { M.editor_tinymce.filepicker_options[editorid] = options; }; diff --git a/lib/formslib.php b/lib/formslib.php index e5314863403..727309e3875 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -2316,6 +2316,9 @@ var skipClientValidation = false; } catch(e) { return true; } + if (typeof window.tinyMCE !== \'undefined\') { + window.tinyMCE.triggerSave(); + } if (!myValidator()) { ev.preventDefault(); }