1
0
mirror of synced 2024-11-23 05:26:10 +03:00

allow hiding search field permanently. #189

This commit is contained in:
Igor Vaynberg 2013-02-12 00:11:24 -08:00
parent 8868d59176
commit cd3d7421c4

View File

@ -1627,6 +1627,8 @@ the specific language governing permissions and limitations under the Apache Lic
dropdown = this.dropdown, dropdown = this.dropdown,
clickingInside = false; clickingInside = false;
this.showSearch(this.opts.minimumResultsForSearch >= 0);
this.selection = selection = container.find(".select2-choice"); this.selection = selection = container.find(".select2-choice");
this.focusser = container.find(".select2-focusser"); this.focusser = container.find(".select2-focusser");
@ -1691,7 +1693,9 @@ the specific language governing permissions and limitations under the Apache Lic
this.focusser.bind("keyup-change input", this.bind(function(e) { this.focusser.bind("keyup-change input", this.bind(function(e) {
if (this.opened()) return; if (this.opened()) return;
this.open(); this.open();
if (this.showSearchInput !== false) {
this.search.val(this.focusser.val()); this.search.val(this.focusser.val());
}
this.focusser.val(""); this.focusser.val("");
killEvent(e); killEvent(e);
})); }));
@ -1840,15 +1844,22 @@ the specific language governing permissions and limitations under the Apache Lic
// hide the search box if this is the first we got the results and there are a few of them // hide the search box if this is the first we got the results and there are a few of them
if (initial === true) { if (initial === true) {
showSearchInput = this.showSearchInput = countResults(data.results) >= this.opts.minimumResultsForSearch; var min=this.opts.minimumResultsForSearch;
this.dropdown.find(".select2-search")[showSearchInput ? "removeClass" : "addClass"]("select2-search-hidden"); showSearchInput = min < 0 ? false : countResults(data.results) >= min;
this.showSearch(showSearchInput);
//add "select2-with-searchbox" to the container if search box is shown
$(this.dropdown, this.container)[showSearchInput ? "addClass" : "removeClass"]("select2-with-searchbox");
} }
}, },
// single
showSearch: function(showSearchInput) {
this.showSearchInput = showSearchInput;
this.dropdown.find(".select2-search")[showSearchInput ? "removeClass" : "addClass"]("select2-search-hidden");
//add "select2-with-searchbox" to the container if search box is shown
$(this.dropdown, this.container)[showSearchInput ? "addClass" : "removeClass"]("select2-with-searchbox");
},
// single // single
onSelect: function (data, options) { onSelect: function (data, options) {
var old = this.opts.element.val(); var old = this.opts.element.val();