From 450aad8f46b7ae617731ec6a30ae656dcb1a0da6 Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Wed, 2 May 2012 22:48:44 -0700 Subject: [PATCH] fixed placeholder bug. closes #55 --- select2.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/select2.js b/select2.js index 5abe5b9b..6ab586fd 100755 --- a/select2.js +++ b/select2.js @@ -398,6 +398,8 @@ installKeyUpChangeEvent(search); search.bind("keyup-change", this.bind(this.updateResults)); + search.bind("focus", function() { search.addClass("select2-focused");}); + search.bind("blur", function() { search.removeClass("select2-focused");}); this.container.delegate(resultsSelector, "click", this.bind(function (e) { if ($(e.target).closest(".select2-result:not(.select2-disabled)").length > 0) { @@ -1177,7 +1179,10 @@ clearSearch: function () { var placeholder = this.getPlaceholder(); - if (placeholder !== undefined && this.getVal().length === 0) { + if (placeholder !== undefined + && this.getVal().length === 0 + && this.search.hasClass("select2-focused")===false) { + this.search.val(placeholder).addClass("select2-default"); // stretch the search box to full width of the container so as much of the placeholder is visible as possible this.search.width(this.getContainerWidth());