Skip Navigation

[Resolved] Cred Field WYSIWYG post_content max words

This thread is resolved. Here is a description of the problem and solution.

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 3 years, 3 months ago. 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.

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)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by fifthI 3 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#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:
hidden link
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

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.