Skip to content

Commit 0de516f

Browse files
committed
Add minimumResultsForSearch
1 parent caf4ad7 commit 0de516f

11 files changed

Lines changed: 320 additions & 101 deletions

File tree

dist/css/select2.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
.select2-search--dropdown .select2-search__field {
8585
padding: 4px;
8686
width: 100%; }
87-
.select2-search--dropdown .select2-search--hide {
87+
.select2-search--dropdown.select2-search--hide {
8888
display: none; }
8989

9090
.select2-close-mask {

dist/css/select2.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/select2.amd.full.js

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,42 @@ define('select2/dropdown/attachBody',[
29932993
return AttachBody;
29942994
});
29952995

2996+
define('select2/dropdown/minimumResultsForSearch',[
2997+
2998+
], function () {
2999+
function countResults (data) {
3000+
count = 0;
3001+
3002+
for (var d = 0; d < data.length; d++) {
3003+
var item = data[d];
3004+
3005+
if (item.children) {
3006+
count += countResults(item.children);
3007+
} else {
3008+
count++;
3009+
}
3010+
}
3011+
3012+
return count;
3013+
}
3014+
3015+
function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
3016+
this.minimumResultsForSearch = options.get('minimumResultsForSearch');
3017+
3018+
decorated.call(this, $element, options, dataAdapter);
3019+
}
3020+
3021+
MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
3022+
if (countResults(params.data) < this.minimumResultsForSearch) {
3023+
return false;
3024+
}
3025+
3026+
return decorated.call(this, params);
3027+
};
3028+
3029+
return MinimumResultsForSearch;
3030+
});
3031+
29963032
define('select2/i18n/en',[],function () {
29973033
return {
29983034
errorLoading: function () {
@@ -3063,6 +3099,7 @@ define('select2/defaults',[
30633099
'./dropdown/hidePlaceholder',
30643100
'./dropdown/infiniteScroll',
30653101
'./dropdown/attachBody',
3102+
'./dropdown/minimumResultsForSearch',
30663103

30673104
'./i18n/en'
30683105
], function ($, ResultsList,
@@ -3076,7 +3113,7 @@ define('select2/defaults',[
30763113
MinimumInputLength, MaximumInputLength,
30773114

30783115
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
3079-
AttachBody,
3116+
AttachBody, MinimumResultsForSearch,
30803117

30813118
EnglishTranslation) {
30823119
function Defaults () {
@@ -3094,25 +3131,24 @@ define('select2/defaults',[
30943131
} else {
30953132
options.dataAdapter = SelectData;
30963133
}
3097-
}
3098-
30993134

3100-
if (options.minimumInputLength > 0) {
3101-
options.dataAdapter = Utils.Decorate(
3102-
options.dataAdapter,
3103-
MinimumInputLength
3104-
);
3105-
}
3135+
if (options.minimumInputLength > 0) {
3136+
options.dataAdapter = Utils.Decorate(
3137+
options.dataAdapter,
3138+
MinimumInputLength
3139+
);
3140+
}
31063141

3107-
if (options.maximumInputLength > 0) {
3108-
options.dataAdapter = Utils.Decorate(
3109-
options.dataAdapter,
3110-
MaximumInputLength
3111-
);
3112-
}
3142+
if (options.maximumInputLength > 0) {
3143+
options.dataAdapter = Utils.Decorate(
3144+
options.dataAdapter,
3145+
MaximumInputLength
3146+
);
3147+
}
31133148

3114-
if (options.tags != null) {
3115-
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
3149+
if (options.tags != null) {
3150+
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
3151+
}
31163152
}
31173153

31183154
if (options.resultsAdapter == null) {
@@ -3142,6 +3178,13 @@ define('select2/defaults',[
31423178
options.dropdownAdapter = SearchableDropdown;
31433179
}
31443180

3181+
if (options.minimumResultsForSearch > 0) {
3182+
options.dropdownAdapter = Utils.Decorate(
3183+
options.dropdownAdapter,
3184+
MinimumResultsForSearch
3185+
);
3186+
}
3187+
31453188
options.dropdownAdapter = Utils.Decorate(
31463189
options.dropdownAdapter,
31473190
AttachBody
@@ -3275,13 +3318,14 @@ define('select2/defaults',[
32753318
},
32763319
minimumInputLength: 0,
32773320
maximumInputLength: 0,
3278-
theme: 'default',
3321+
minimumResultsForSearch: 0,
32793322
templateResult: function (result) {
32803323
return result.text;
32813324
},
32823325
templateSelection: function (selection) {
32833326
return selection.text;
3284-
}
3327+
},
3328+
theme: 'default'
32853329
};
32863330
};
32873331

dist/js/select2.amd.js

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,42 @@ define('select2/dropdown/attachBody',[
29932993
return AttachBody;
29942994
});
29952995

2996+
define('select2/dropdown/minimumResultsForSearch',[
2997+
2998+
], function () {
2999+
function countResults (data) {
3000+
count = 0;
3001+
3002+
for (var d = 0; d < data.length; d++) {
3003+
var item = data[d];
3004+
3005+
if (item.children) {
3006+
count += countResults(item.children);
3007+
} else {
3008+
count++;
3009+
}
3010+
}
3011+
3012+
return count;
3013+
}
3014+
3015+
function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
3016+
this.minimumResultsForSearch = options.get('minimumResultsForSearch');
3017+
3018+
decorated.call(this, $element, options, dataAdapter);
3019+
}
3020+
3021+
MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
3022+
if (countResults(params.data) < this.minimumResultsForSearch) {
3023+
return false;
3024+
}
3025+
3026+
return decorated.call(this, params);
3027+
};
3028+
3029+
return MinimumResultsForSearch;
3030+
});
3031+
29963032
define('select2/i18n/en',[],function () {
29973033
return {
29983034
errorLoading: function () {
@@ -3063,6 +3099,7 @@ define('select2/defaults',[
30633099
'./dropdown/hidePlaceholder',
30643100
'./dropdown/infiniteScroll',
30653101
'./dropdown/attachBody',
3102+
'./dropdown/minimumResultsForSearch',
30663103

30673104
'./i18n/en'
30683105
], function ($, ResultsList,
@@ -3076,7 +3113,7 @@ define('select2/defaults',[
30763113
MinimumInputLength, MaximumInputLength,
30773114

30783115
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
3079-
AttachBody,
3116+
AttachBody, MinimumResultsForSearch,
30803117

30813118
EnglishTranslation) {
30823119
function Defaults () {
@@ -3094,25 +3131,24 @@ define('select2/defaults',[
30943131
} else {
30953132
options.dataAdapter = SelectData;
30963133
}
3097-
}
3098-
30993134

3100-
if (options.minimumInputLength > 0) {
3101-
options.dataAdapter = Utils.Decorate(
3102-
options.dataAdapter,
3103-
MinimumInputLength
3104-
);
3105-
}
3135+
if (options.minimumInputLength > 0) {
3136+
options.dataAdapter = Utils.Decorate(
3137+
options.dataAdapter,
3138+
MinimumInputLength
3139+
);
3140+
}
31063141

3107-
if (options.maximumInputLength > 0) {
3108-
options.dataAdapter = Utils.Decorate(
3109-
options.dataAdapter,
3110-
MaximumInputLength
3111-
);
3112-
}
3142+
if (options.maximumInputLength > 0) {
3143+
options.dataAdapter = Utils.Decorate(
3144+
options.dataAdapter,
3145+
MaximumInputLength
3146+
);
3147+
}
31133148

3114-
if (options.tags != null) {
3115-
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
3149+
if (options.tags != null) {
3150+
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
3151+
}
31163152
}
31173153

31183154
if (options.resultsAdapter == null) {
@@ -3142,6 +3178,13 @@ define('select2/defaults',[
31423178
options.dropdownAdapter = SearchableDropdown;
31433179
}
31443180

3181+
if (options.minimumResultsForSearch > 0) {
3182+
options.dropdownAdapter = Utils.Decorate(
3183+
options.dropdownAdapter,
3184+
MinimumResultsForSearch
3185+
);
3186+
}
3187+
31453188
options.dropdownAdapter = Utils.Decorate(
31463189
options.dropdownAdapter,
31473190
AttachBody
@@ -3275,13 +3318,14 @@ define('select2/defaults',[
32753318
},
32763319
minimumInputLength: 0,
32773320
maximumInputLength: 0,
3278-
theme: 'default',
3321+
minimumResultsForSearch: 0,
32793322
templateResult: function (result) {
32803323
return result.text;
32813324
},
32823325
templateSelection: function (selection) {
32833326
return selection.text;
3284-
}
3327+
},
3328+
theme: 'default'
32853329
};
32863330
};
32873331

0 commit comments

Comments
 (0)