question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to set a maximum character limit to editor ?

See original GitHub issue

How to restrict characters from being entered after the maximum limit exceeds ? and to show the character length 234/5000 likewise. I couldn’t find an exact documentation explaining this for the react integration. I’m using react functional component.

 <TinyMCE
            key={field.NAME}
            config={{
            menubar: false,
            plugins: 'autolink link  lists',
             toolbar: 'fontselect fontsizeselect formatselect| bold italic underline strikethrough | 
                           bullist numlist outdent indent | alignleft aligncenter alignright| insertfile 
                           image media pageembed template link anchor codesample'
             }}
             onChange={handleDescriptionEdito}
             onKeyup={handleDescriptionEditor}
 />

EDIT :

I found out this doc

i tried const wordcount = window.tinymce.activeEditor.plugins; wordcount.body.getCharacterCount(); in my handler function handleDescriptionEditor but it is giving out an error

Cannot read property 'getCharacterCount' of undefined Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
tzakrzewski-devcommented, Jul 15, 2020

Hello, i tryed also to get the number of character in react. it works fine with this code

handleEditorChange(content, Editor) { const wordcount = Editor.plugins.wordcount; this.setState({ content, numberOfCharacter: wordcount.body.getCharacterCountWithoutSpaces(), }); } it set my state with the value

2reactions
fabiokiatkowskicommented, Aug 25, 2020

Hello, some updates about this?

I have a controlled component with onEditorChange and value and I can get the size of the content but even I won’t updating my state, my view is updating and showing more characters that my value.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set character limit and maxlength - TinyMCE
One solution is to keep the character limit in a textarea set to a specific length with warnings about size. Another is to...
Read more >
Limit Max Characters for Editor? - Google Groups
I am developing my own component and i can't seem to figure out how to set the maximum number of characters a person...
Read more >
Specify the character limit for a text box - Microsoft Support
Click the Display tab. Under Options, select the Limit text box to check box, and then specify the number of characters that you...
Read more >
How to specify minimum & maximum number of characters ...
To set the maximum character limit in input field, we use <input> maxlength attribute. This attribute is used to specify the maximum number ......
Read more >
Character limit | Lokalise Docs
Setting character limit for a single key ... To limit the maximum character length of your translations for a specific key, open the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found