1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-24 18:04:43 +02:00

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.
This commit is contained in:
David Mudrák 2016-05-19 00:01:36 +02:00
parent 33892edf18
commit 34321d491b

@ -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;
};