Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jmarcone opened this issue Nov 19, 2024 · 1 comment
Open

Comments

@jmarcone
Copy link

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
Copy link
Collaborator

EmilePerron commented Nov 19, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants