bootstrap-maxlength
bootstrap-maxlength copied to clipboard
Counter is incorrect when you paste text
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
i think it's a problem counting line breaks as 2 chars instead of 1
Why a timeout after a paste should fix this issue?
@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.
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.
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)));