Fix minimumResultsForSearch by recursively counting items
Signed-off-by: Igor Vaynberg <igor.vaynberg@gmail.com>
This commit is contained in:
parent
4d3f8b6332
commit
c2fa04529b
16
select2.js
16
select2.js
@ -404,6 +404,18 @@
|
|||||||
return $.isFunction(val) ? val() : val;
|
return $.isFunction(val) ? val() : val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function countResults(results) {
|
||||||
|
var count = 0;
|
||||||
|
$.each(results, function(i, item) {
|
||||||
|
if (item.children) {
|
||||||
|
count += countResults(item.children);
|
||||||
|
} else {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* blurs any Select2 container that has focus when an element outside them was clicked or received focus
|
* blurs any Select2 container that has focus when an element outside them was clicked or received focus
|
||||||
*
|
*
|
||||||
@ -1534,9 +1546,7 @@
|
|||||||
// 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) {
|
||||||
// TODO below we use data.results.length, but what we really need is something recursive to calc the length
|
showSearchInput = this.showSearchInput = countResults(data.results) >= this.opts.minimumResultsForSearch;
|
||||||
// TODO in case there are optgroups
|
|
||||||
showSearchInput = this.showSearchInput = data.results.length >= this.opts.minimumResultsForSearch;
|
|
||||||
this.dropdown.find(".select2-search")[showSearchInput ? "removeClass" : "addClass"]("select2-search-hidden");
|
this.dropdown.find(".select2-search")[showSearchInput ? "removeClass" : "addClass"]("select2-search-hidden");
|
||||||
|
|
||||||
//add "select2-with-searchbox" to the container if search box is shown
|
//add "select2-with-searchbox" to the container if search box is shown
|
||||||
|
Loading…
Reference in New Issue
Block a user