bootstrap-maxlength icon indicating copy to clipboard operation
bootstrap-maxlength copied to clipboard

Counter is incorrect when you paste text

Open aamirafridi opened this issue 10 years ago • 5 comments

In your demo for textarea, type some text with line breaks in it. Copy it and than kept press Ctrl + V to repeatedly paste the text and you can see the counter is wrong. Fix this issue and it will make it a good plugin :) Here is how you can do: https://github.com/aaronrussell/jquery-simply-countable/blob/master/jquery.simplyCountable.js#L123

aamirafridi avatar Apr 16 '15 08:04 aamirafridi

i think it's a problem counting line breaks as 2 chars instead of 1

dvelayos avatar Apr 29 '15 15:04 dvelayos

Why a timeout after a paste should fix this issue?

mimo84 avatar Oct 10 '15 07:10 mimo84

@mimo84 I think he used a timeout because if you try to get a value from a element just after paste operation it will be empty value instead of a new text pasted. i mean, i dont know why this happen, but after a while it will have the text copy pasted.... it seems a strange behavior for me.

diego3 avatar Apr 19 '16 11:04 diego3

As long as I remember, the problem was that if you have maxlength property on textarea than copy paste behaves differently. So just change maxlength to something like data-maxlength would solve the issue.

aamirafridi avatar Apr 21 '16 11:04 aamirafridi

When you paste text in that is too long, the remaining variable becomes a negative number. When subtracting a negative the result goes positive. Check if remaining is less than zero and set remaining to zero if it is.

maxLengthIndicator.html(updateMaxLengthHTML(currentInput.val(), maxLengthCurrentInput, (maxLengthCurrentInput - remaining)));

41GitHub avatar Jun 26 '17 20:06 41GitHub