1

I found a jQuery plugin at StackOverflow Page to auto-expand/contract a textbox as the user pastes/removes data from a text input. It works fine until I try to paste a substantial chunk of text into it. Then it doesn't expand at all. However it works fine if I go on typing characters, or even if I paste a small amount of text. Can anybody tell me how to tweak it to expand simultaneously even when a large chunk of data is pasted?

Community
  • 1
  • 1
SexyBeast
  • 7,913
  • 28
  • 108
  • 196

1 Answers1

1

Your problem is due to the way the plugin handles the maximum width.

If a single operation (e.g. a paste) results in the element's width exceeding the maximum, the plugin does not extend the width to the maximum value, it leaves it as it is.

To work around this, I modified the code to take the maximum width into account when computing the new width:

// Calculate new width + whether to change
var testerWidth = testSubject.width(),
    newWidth = Math.min((testerWidth + o.comfortZone) >= minWidth
        ? testerWidth + o.comfortZone : minWidth, o.maxWidth - 1);

You will find an updated jsbin here.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479