StopVerbosity icon indicating copy to clipboard operation
StopVerbosity copied to clipboard

a problem with new lines

Open yakovyarmo opened this issue 10 years ago • 5 comments

when you insert new lines the count is wrong insert only new lines in the basic example of maxlength=10

yakovyarmo avatar Oct 12 '14 14:10 yakovyarmo

What you mention is actually the intended behavior of the plugin. Most other jQuery plugins out there for textarea character counting also exhibit the behavior of counting each new line character as one character.

WilliamHuey avatar Oct 21 '14 20:10 WilliamHuey

Hi, I would like to know why this was the intended behavior? Because according to w3c, roughly speaking, on form submition new line characters (LF) are replaced by two characters (CRLF). Then when the plugin uses the native maxlength it counts a new line character as one instead of two and thus doesn't display the correct value. http://dev.w3.org/html5/spec-preview/the-textarea-element.html

christianarevalo avatar Dec 24 '14 13:12 christianarevalo

Assuming that yakovyarmo and christianarevalo are on the same page, my plugin is short on the character count.

Each CRLF is represented as two characters instead of the one from LF.

From christianarevalo, I understand the conflict arises when my plugin's maxlength treats newlines as LF as opposes to CRLF such that the character limitations behave different (character count) is different from native maxlength. This behavior is evident in Chrome version 39. However this is not present in Firefox.

Currently, using native maxlength on Chrome will produce a counter and character input capability mismatch.

From this link, the explanation of browser treating newlines different such that Firefox and jQuery ignores the canonical representation of newlines in textareas: http://stackoverflow.com/questions/10030921/chrome-counts-characters-wrong-in-textarea-with-maxlength-attribute.

I will have to rewrite my plugin to use the crlf format, which then means that newlines will take up two characters instead of one.

WilliamHuey avatar Dec 26 '14 08:12 WilliamHuey

I tried with the following versions firefox 31.0, IE 11, Opera 26.0. Then I submit a form using a textarea with a new line character, the same result in the server side I received 2 characters. I still have to check the behavior using Android/iOS browsers, but I suspect that the behavior will be the same. So this is something all other character counters plugins using textarea should take care of.

Thanks again for your work.

christianarevalo avatar Dec 26 '14 10:12 christianarevalo

I made the necessary changes to use crlf for all browsers in version 1.14.1.

WilliamHuey avatar Jan 09 '15 04:01 WilliamHuey