From a1a0fb8360e0538370e9c03211784712e1731dd3 Mon Sep 17 00:00:00 2001 From: Yohann Date: Sun, 7 Sep 2014 15:08:05 -0400 Subject: [PATCH] Set a correct behaviour using the placeholder Sometimes we want to have a dynamic width even when the input is smaller than the placeholder. To do that, we may drop the width css attribute. Here is an example. Please input some text, then erase it. http://jsfiddle.net/mJMpw/695/ The trick is to use the placeholder text as a default if there is no value in the input. --- jquery.autosize.input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.autosize.input.js b/jquery.autosize.input.js index d4bf181..9bcef0d 100644 --- a/jquery.autosize.input.js +++ b/jquery.autosize.input.js @@ -44,7 +44,7 @@ var Plugins; }; AutosizeInput.prototype.update = function () { - var value = this._input.val() || ""; + var value = this._input.val() || this._input.attr('placeholder'); if (value === this._mirror.text()) { // Nothing have changed - skip