소스 검색

fixed placeholder bug. closes #55

Igor Vaynberg 13 년 전
부모
커밋
450aad8f46
1개의 변경된 파일6개의 추가작업 그리고 1개의 파일을 삭제
  1. 6 1
      select2.js

+ 6 - 1
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());