mirror of
https://github.com/moodle/moodle.git
synced 2025-03-22 08:30:04 +01:00
MDL-76734 editor_tiny: Listen to TinyMCE submit events
jQuery submit events do not trigger the native submit event, and therefore the TinyMCE submit listener is not called. This means that the tinymce.triggerSave() function is not called, and the editor content is not saved. To work around this, if there is a form for the Node that the editor is attached to, the jQuery submit event is listened to and the save event called. Unfortunately it is not possible to use a global jQuery submit listener added to the document to save all editors on the page. In some cases, this is too late because the bubbling process means that a child node consumer may attempt to consume the data before the delegated handler is called for the document.
This commit is contained in:
parent
24c009f222
commit
744e1dbaea
2
lib/editor/tiny/amd/build/editor.min.js
vendored
2
lib/editor/tiny/amd/build/editor.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -21,6 +21,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import Pending from 'core/pending';
|
||||
import {getDefaultConfiguration} from './defaults';
|
||||
import {getTinyMCE, baseUrl} from './loader';
|
||||
@ -382,6 +383,16 @@ export const setupForTarget = async(target, options = {}) => {
|
||||
instanceMap.delete(target.targetElm);
|
||||
});
|
||||
|
||||
// If the editor is part of a form, also listen to the jQuery submit event.
|
||||
// The jQuery submit event will not trigger the native submit event, and therefore the content will not be saved.
|
||||
// We cannot rely on listening to the bubbled submit event on the document because other events on child nodes may
|
||||
// consume the data before it is saved.
|
||||
if (target.form) {
|
||||
jQuery(target.form).on('submit', () => {
|
||||
editor.save();
|
||||
});
|
||||
}
|
||||
|
||||
pendingPromise.resolve();
|
||||
return editor;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user