StopVerbosity
StopVerbosity copied to clipboard
a problem with new lines
when you insert new lines the count is wrong insert only new lines in the basic example of maxlength=10
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.
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
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.
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.
I made the necessary changes to use crlf for all browsers in version 1.14.1.