jazzband / django-tinymce

TinyMCE integration for Django
http://django-tinymce.readthedocs.org/
MIT License
1.25k stars 317 forks source link

set callback functions #452

Closed esseti closed 1 month ago

esseti commented 5 months ago

How is it possible to create some settings in oreder that the tinymce.init is as the following?

tinymce.init({
  init_instance_callback: function (editor) {
    editor.on('blur', function (e) {
      console.log('Editor was blurred!');
    });
  }
});

I tried with

TINYMCE_DEFAULT_CONFIG = {
....
    "init_instance_callback":"""function (editor) {
editor.on('blur', function (e) {
    tinyMCE.triggerSave();
    console.log('test')
});"""

but that is then a string, not a valid funciton and it's not triggered.

My scope is to trigger an action when onblur, since using tinymce the event on input, that is: $(':input').on('change', function () .. is not triggered..

Pantzan commented 2 months ago

It looks like the init_instance_callback callback is not supported. Use the setup callback instead

esseti commented 1 month ago

do you have a working example for this case?

Pantzan commented 1 month ago
TINYMCE_DEFAULT_CONFIG = {
....
`"setup":"""function (editor) {
        editor.on('blur', function (e) {
        editor.save();
        console.log('test')
    });} """
}

The blur event in order to trigger the focus event, it must be shifted to another input. In my projects clicking anywhere in the page does not trigger the event. As for the save, I am not using it in my projects so I cannot test that functionality but I don't see any reason the editor.save() not to work.

If the issue is solved, please mark this ticket as closed.