Wysiwyg-editor: Feature request: Setting to count html characters as well as text.

Created on 24 Jun 2015  路  9Comments  路  Source: froala/wysiwyg-editor

Example:

<p>Testing</p>```` Total text: 7 Total with HTML: 14

Most helpful comment

I'll just leave this here then if anyone stumbles upon this and need it.

Edit /js/plugins/char_counter.js

Add to line 11:

countHTMLCharacters: true

Line: 26 to 30:

    if(editor.options.countHTMLCharacters == true) {
      return this.getHTML().length;
    } else {
      return this.getText().length;
    }

Though I'd rather have it native than extend it since it might break in future updates of Froala.

All 9 comments

I can't see any reason why you would want to count HTML characters. Could you give more details?

Our systems limit the amount of characters in a custom textarea that we use the editor inside, this also counts to the HTML characters as well as the text.

It is a very weird case and I don't think there are developers doing similar things. I never saw an app working like this with a rich text editor.

If you want you could extend the plugin for your needs and use it this way. However, it is very not user friendly because the end user sees the text, not the html.

I'll just leave this here then if anyone stumbles upon this and need it.

Edit /js/plugins/char_counter.js

Add to line 11:

countHTMLCharacters: true

Line: 26 to 30:

    if(editor.options.countHTMLCharacters == true) {
      return this.getHTML().length;
    } else {
      return this.getText().length;
    }

Though I'd rather have it native than extend it since it might break in future updates of Froala.

Raising a dead horse, I know.

That HTML has to be saved somewhere (i.e. the database) which might have a character limit. Showing the hidden character count prevents users from being confused why they are exceeding the max character limit. Not sure if the latest version solves this problem.

Am I missing something? Anyone else have some insight to handle this scenario?

@wboka I believe this is a bit out of the editor context because a regular user is usually not aware of the HTML underneath. If you would like to make these changes, I would recommend to use the char counter as a starting point and make the necessary modifications over it.

I can't see any reason why you would want to count HTML characters. Could you give more details?

just fyi... reason being you can set a limit on SQL columns. If you don't want to go past 8000 (standard MAX until overflow) then you need to make sure your html count does not go over that. If you just save plain text, then the standard count is fine, but most of the time you will be saving the html to the DB.

because a regular user is usually not aware of the HTML underneath

This is why having a counter that displays the HTML (hidden) characters that are saved to the database is so important.

I need to limit total character count as well. My application is a web UI to send push notifications to a mobile app. SMS messages also have a total character limit.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bnjmnfnk picture bnjmnfnk  路  4Comments

adilsonb picture adilsonb  路  3Comments

thedotedge picture thedotedge  路  4Comments

Fandangi picture Fandangi  路  3Comments

isubasti picture isubasti  路  4Comments