You need to be logged in to post in the forum - Log In

An active JCE Pro Subscription is required to post in the forum - Buy a Subscription

Support is currently Offline

Official support hours
Monday to Friday
09:00 - 17:00 Europe/London (BST)

Please create a new Ticket and we will get back to you as soon as we can.

#114949 Can I set different character limit before loading the editor (or after loading it)?

Posted in ‘Editor’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Latest post by carcam on Thursday, 19 October 2023 16:23 BST

carcam
Hi Ryan!!
I set up JCE on a client custom development, and it was really useful for handling all hits "editorial" requests.

This is a custom component and we have several item categories (not Joomla categories, but ones from my custom component). The client wants to have different limit of words per category.

So let's say the user chooses category A, then the editor will have just 2500 words limit. For category B the limit of words will be 3000.

Category is chosen after page load so I guess the best way to handle this is JavaScript, but I could force a page load after category selection if we need to do it server side.

Is this possible?

Thanks!!

Ryan
Category is chosen after page load so I guess the best way to handle this is JavaScript, but I could force a page load after category selection if we need to do it server side.
You could try something like this maybe:

// your script triggered after category is chosen, then...
var editor = tinymce.get('id');

if (editor) {
    editor.settings.wordcount_limit = 300;
}

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

carcam
Thank you very much for your reply!!

I have tested this with browser console, but it doesn't seem to work:



Can you think of another way of replicating this behaviour? It would work just allowing me to load different profiles in the Joomla editor field for instance...

Attachments

carcam
Ryan I have made it to change the character count, but still having some issues. I have created this JS method:

function fixWordCount(){
    var editor = tinymce.get('jform_work');
    editor.settings.wordcount_limit = 5;
    tinymce.EditorManager.execCommand('mceRemoveEditor',true, 'jform_work');
    tinymce.EditorManager.execCommand('mceAddEditor',true, 'jform_work');
}
That works fine. It basically reloads the editor and the new wordcount works. Problem I face now is that I cannot execute it on page load, because JCE is still not loaded and editor variable is undefined at that stage. Can you think of a way to handle this?

Ryan
You can try running this:

document.addEventListener("DOMContentLoaded", (event) => {
    tinymce.onAddEditor.add(function (ed) {
        if (ed.id !== 'jform_work') {
            return;
        }

        editor.settings.wordcount_limit = 5;
    });
});

Ryan Demmer

Lead Developer / CEO / CTO

Just because you're not paranoid doesn't mean everybody isn't out to get you.

carcam
Thanks Ryan!! It works!! (almost). This is the final code that worked for me:

document.addEventListener("DOMContentLoaded", (event) => {
    tinymce.onAddEditor.add(function (ed) {
        if (ed.activeEditor.id !== 'jform_work') {
            return;
        }
        ed.activeEditor.settings.wordcount_limit = 5;
    });
});
Thank you very much!!