From 34321d491beec252cd4bb1da8d43a44b5866e5df Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20Mudr=C3=A1k?= Date: Thu, 19 May 2016 00:01:36 +0200 Subject: [PATCH] MDL-54633 tinymce: Automatically sync editor with its textarea Probably as a result of recent changes in the way how forms client side validators are trigerred (MDL-52826), the field validator has been triggered before the underlying textarea's values property is updated by TinyMCE. This led to marking such a field as "required" even if the value is provided. Inspired by http://stackoverflow.com/questions/2122085/ this patch adds a new onchange callback that automatically keeps the underlying textarea synced with the editor iframe. Relevant API docs: http://archive.tinymce.com/wiki.php/Configuration3x:onchange_callback I was also trying to call the save() method via the editor's onSubmit method but that one seems to be also triggered only after the validator. --- lib/editor/tinymce/module.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/editor/tinymce/module.js b/lib/editor/tinymce/module.js index d3118ef0f33..4b227d132bb 100644 --- a/lib/editor/tinymce/module.js +++ b/lib/editor/tinymce/module.js @@ -45,6 +45,7 @@ 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; @@ -92,6 +93,12 @@ 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; }; -- 2.43.0