When you insert a line break into the text it counts as two characters and the remaining character counter goes down by 2.
However for each line break you have it is then possible to go into negative for a character.

So if I have 5 line breaks my remaining character count can go down to -5.

Note that this is independent of the "warning" option for the plugin, which I have hacked to 0 instead of 10.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Leksat’s picture

I made some research on the topic. And, yes, there is a problem with line breaks because they are browser/OS depended. The JavaScript code tries to solve the issue, but all it did - it counts all line breaks ("\r\n", "\r", or "\n") as two symbols.

We don't actually care about how many characters will be stored in the database. So, my suggestion is to count all type of line breaks as one character on both PHP and JavaScript sides. That will be more user friendly.

If this is sufficient, I will create a patch.

rooby’s picture

Sounds logical to me.

sgurlt’s picture

Subscribing !

rooby’s picture

@sg88:
You can subscribe to issues by clicking the "Follow" button at the top right of the issue.

undertext’s picture

brandy.brown’s picture

supplied patch doesn't change anything for me.

juagarc4’s picture

Issue summary: View changes

Sounds logical to me too.
Supplied patch works for me.
Thanks.

kungfu4’s picture

So, one thing I've noticed that is related to this (patch or no patch) if you do a simple line break (shift-return), when you type another character after doing that, it is not counted. Has anyone else encountered this?

Thanks

tmcfarlin4’s picture

tmcfarlin4’s picture

#9 is quick and dirty, someone can clean it up, but this addresses #8 & seems to be more robust.

tmcfarlin4’s picture

Status: Active » Needs review
tim@lammar.be’s picture

I fixed it by forcing to count each format of line ending as 2 characters (as the browser forces the POST data to use \r\n).
Next I force stop an enter press if the remaining character count < 2 (otherwise the remaining will be -1).

woutervu’s picture

I think it can be argued whether or not a negative remaining character counter or force stopping an enter press are welcome features. However I do agree with @Leksat that line breaks should be counted as one character. As to not further pollute this issue, I've created a seperate issue with a patch included: https://www.drupal.org/project/maxlength/issues/3043450#comment-13040630

cedewey’s picture

Status: Needs review » Closed (won't fix)

We are only maintaining the Drupal 7 version of the module for critical security fixes, so I'm marking this Closed (works as designed). Thank you everyone for working on this issue. If you do want to maintain the Drupal 7 version, do reach out. We'd be happy to bring you on board as a maintainer.

I also encourage you, if you haven't already, to upgrade your site to Drupal 8/9. We are actively maintaining that version and you would enjoy all of the other features of the latest version of Drupal.