3

this is my tinymce script:

<script>
      tinymce.init({
          menubar: false,
          selector: "textarea",
          plugins: [
              "advlist autolink lists link image charmap print preview anchor",
              "searchreplace visualblocks code fullscreen",
              "insertdatetime media table contextmenu paste"
          ],
          toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
      });
    </script>

how to limit characters to 500?

user3818592
  • 163
  • 1
  • 3
  • 9
  • I don't know how to do that in tinymce 4.0 but you should do that counting on the server side. – yotamN Sep 27 '14 at 16:28
  • Do you mean like this : http://www.tinymce.com/wiki.php/TinyMCE3x:How_to_limit_number_of_characters/words ? – laruiss Sep 27 '14 at 16:37
  • Have you tried to add `maxlength` attribute: ``? Be carefull, there is [an open issue](https://github.com/angular-ui/ui-tinymce/issues/145) related to AngularJS binding. – naXa stands with Ukraine Dec 08 '15 at 13:53
  • 3
    Possible duplicate of [Limit the number of character in tinyMCE](http://stackoverflow.com/questions/11342921/limit-the-number-of-character-in-tinymce) – naXa stands with Ukraine Dec 08 '15 at 13:58

2 Answers2

1

I added the "stopPropagation" line, in order to prevent the user from continuing to enter characters: 1 - in the html code of the textarea it is necessary to include the value of maxlength and Id.
2 - in script part, code below. If you want, uncomment the alert() line, and put your message.

<script type="text/javascript">
  tinymce.init ({
    ...
    ...
      setup: function(ed) {
        var maxlength = parseInt($("#" + (ed.id)).attr("maxlength"));
        var count = 0;
        ed.on("keydown", function(e) {
          count++;
          if (count > maxlength) {
            // alert("You have reached the character limit");
            e.stopPropagation();
            return false;
          }
        });
     },
<textarea type="text" id="test" name="test" maxlength="10"></textarea>
Brasil
  • 31
  • 1
0

It can work, but I don't know how to let it can press delete key...

  setup: function(ed) {
        var maxlength = parseInt($("#" + (ed.id)).attr("maxlength"));
        var count = 0;
        ed.on("keydown", function(e) {
            count++;
            if (count >= maxlength) {
                alert("false");
                return false;
            }
        });
    },
carry0987
  • 117
  • 1
  • 2
  • 14