Skip to content

Counter is incorrect when you paste text #95

Open

Description

@aamirafridi

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

Activity

  1. dvelayos commented on Apr 29, 2015

    @dvelayos

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

  2. mimo84 commented on Oct 10, 2015

    @mimo84
    Owner

    Why a timeout after a paste should fix this issue?

  3. diego3 commented on Apr 19, 2016

    @diego3

    @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.

  4. aamirafridi commented on Apr 21, 2016

    @aamirafridi
    Author

    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.

  5. 41GitHub commented on Jun 26, 2017

    @41GitHub

    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)));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions