Skip Navigation

[Résolu] Cred Field WYSIWYG post_content max words

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:

How do I set a limit of words to a the WYSIWYG editor (other than with filter cred_form_validate on backend) on the frontend?

Solution:

There isn't such kind of built-in feature within Toolset plugins, the WYSIWYG field is using TinyMCE editor, see their document:

https://www.tiny.cloud/docs-3x/extras/TinyMCE3x@TinyMCE_FAQ/#ineedtolimitthenumberofcharactersausercaninput

There isn't such kind of feature within TinyMCE editor too.

You can setup custom JS codes to send a message to user if they input too much words, for example:

https://toolset.com/forums/topic/cred-field-wysiwyg-post_content-max-words/#post-1903573

Relevant Documentation:

This support ticket is created Il y a 3 années et 10 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Marqué : 

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par fifthI Il y a 3 années et 10 mois.

Assisté par: Luo Yang.

Auteur
Publications
#1903231

Hi.
I'm trying to set a limit of words to a form that contains this

<div class="form-group">
<label>[cred_i18n name='post_content-label']Poster Content (max 250 words)[/cred_i18n]</label>
[cred_field field='post_content' output='bootstrap']
</div>

How do i achieve it (other than with filter cred_form_validate on backend) on the frontend?
The solutions i found on the forums are not working for the WYSIWYG editor, but only for single/multiple line inputs or textareas (which of course are very easy to achieve)

Best

#1903573

Hello,

There isn't such kind of built-in feature within Toolset plugins, the WYSIWYG field is using TinyMCE editor, see their document:
lien caché
There isn't such kind of feature within TinyMCE editor too.

However, you can setup custom JS codes to send some message to user when they input too much words, for example:

document.addEventListener('DOMContentLoaded', function(event) {
    window.tinyMCE.on( 'AddEditor' , function( event ) {
        var editor = event.editor;
 
        if( editor.id.endsWith( 'post_content' ) ) {
            var editor_id = editor.id; // tinyMCE ID
            editor.on( 'change', function() {
                    var getContent = editor.getContent();         // gets the Content of the active editor
              		var count= getContent.split(" ").length;
                    if(count > 10){
                       alert( 'Too much words: ' + count );
                    }
            } )
        }
    } );
});
#1904081

Thank you sir.

I strongly suggest you to make this feature a core feature of Toolset.
I bet for you it will be very easy, and it will solve a great deal to lots of devs and users of your awesome plugin.

Best regards