eckinox / tinymce-bundle

TinyMCE 6 integration for your Symfony apps and forms
MIT License
24 stars 2 forks source link

Problem with data persistance, noupdates to the underlying textarea #17

Open jmarcone opened 2 days ago

jmarcone commented 2 days ago

Hi, I'm encountering some issues with the TinyMCE plugin.

I'm using Ajax to submit the form, but in this case, the underlying textarea is never updated. Additionally, I created a tinymce.yaml file in the packages folder, but the configurations there seem to be completely ignored.

How can I update the plugin configuration to ensure it's applied properly?

How can I modify the TinyMCE JavaScript initialization to customize its behavior, such as ensuring the content is saved to the textarea on change? For example, I want to do something like this:

 tinymce.init({
        setup: function(editor) {
            editor.on('change', function() {
                editor.save();  // This ensures the content of TinyMCE is saved to the textarea
            });
        },
    });
EmilePerron commented 2 days ago

Hi there!

For the tinymce.yaml config file, I'll quote what I just replied in #16 :

I have two suggestions here.

First one would be to try switching to emileperron/tinymce-bundle - it is a fork of this bundle with some bugfixes and improvements (for context, I am the original author of this here bundle as well, but left the organisation and it is now not really being maintained as an open-source project anymore).

Second thing, which might seem obvious but could be the issue if you only recently created the tinymce.yaml config file: try clearing your cache with a good old bin/console cache:clear.

For the other issue regarding data persistence, you should be able to trigger a save of every TinyMCE instance on the page by calling tinymce.triggerSave(), at which point the textarea should be updated. See TinyMCE's docs on triggersave.

Alternatively, If you just want to retrieve the value in Javascript, you can get the value property on the <tinymce-editor> element at any time, without needing to trigger a save first. Ex.:

const editor = document.querySelector('tinymce-editor');
const myContent = editor.value;

console.log(myContent);

Hope that helps!