1
0
mirror of synced 2025-02-16 20:13:16 +03:00

Add minimumResultsForSearch

This commit is contained in:
Kevin Brown 2014-12-10 18:46:05 -05:00
parent caf4ad73d7
commit 0de516f17a
11 changed files with 320 additions and 101 deletions

View File

@ -84,7 +84,7 @@
.select2-search--dropdown .select2-search__field {
padding: 4px;
width: 100%; }
.select2-search--dropdown .select2-search--hide {
.select2-search--dropdown.select2-search--hide {
display: none; }
.select2-close-mask {

File diff suppressed because one or more lines are too long

View File

@ -2993,6 +2993,42 @@ define('select2/dropdown/attachBody',[
return AttachBody;
});
define('select2/dropdown/minimumResultsForSearch',[
], function () {
function countResults (data) {
count = 0;
for (var d = 0; d < data.length; d++) {
var item = data[d];
if (item.children) {
count += countResults(item.children);
} else {
count++;
}
}
return count;
}
function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
this.minimumResultsForSearch = options.get('minimumResultsForSearch');
decorated.call(this, $element, options, dataAdapter);
}
MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
if (countResults(params.data) < this.minimumResultsForSearch) {
return false;
}
return decorated.call(this, params);
};
return MinimumResultsForSearch;
});
define('select2/i18n/en',[],function () {
return {
errorLoading: function () {
@ -3063,6 +3099,7 @@ define('select2/defaults',[
'./dropdown/hidePlaceholder',
'./dropdown/infiniteScroll',
'./dropdown/attachBody',
'./dropdown/minimumResultsForSearch',
'./i18n/en'
], function ($, ResultsList,
@ -3076,7 +3113,7 @@ define('select2/defaults',[
MinimumInputLength, MaximumInputLength,
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
AttachBody,
AttachBody, MinimumResultsForSearch,
EnglishTranslation) {
function Defaults () {
@ -3094,25 +3131,24 @@ define('select2/defaults',[
} else {
options.dataAdapter = SelectData;
}
}
if (options.minimumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MinimumInputLength
);
}
if (options.minimumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MinimumInputLength
);
}
if (options.maximumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumInputLength
);
}
if (options.maximumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumInputLength
);
}
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
}
}
if (options.resultsAdapter == null) {
@ -3142,6 +3178,13 @@ define('select2/defaults',[
options.dropdownAdapter = SearchableDropdown;
}
if (options.minimumResultsForSearch > 0) {
options.dropdownAdapter = Utils.Decorate(
options.dropdownAdapter,
MinimumResultsForSearch
);
}
options.dropdownAdapter = Utils.Decorate(
options.dropdownAdapter,
AttachBody
@ -3275,13 +3318,14 @@ define('select2/defaults',[
},
minimumInputLength: 0,
maximumInputLength: 0,
theme: 'default',
minimumResultsForSearch: 0,
templateResult: function (result) {
return result.text;
},
templateSelection: function (selection) {
return selection.text;
}
},
theme: 'default'
};
};

View File

@ -2993,6 +2993,42 @@ define('select2/dropdown/attachBody',[
return AttachBody;
});
define('select2/dropdown/minimumResultsForSearch',[
], function () {
function countResults (data) {
count = 0;
for (var d = 0; d < data.length; d++) {
var item = data[d];
if (item.children) {
count += countResults(item.children);
} else {
count++;
}
}
return count;
}
function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
this.minimumResultsForSearch = options.get('minimumResultsForSearch');
decorated.call(this, $element, options, dataAdapter);
}
MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
if (countResults(params.data) < this.minimumResultsForSearch) {
return false;
}
return decorated.call(this, params);
};
return MinimumResultsForSearch;
});
define('select2/i18n/en',[],function () {
return {
errorLoading: function () {
@ -3063,6 +3099,7 @@ define('select2/defaults',[
'./dropdown/hidePlaceholder',
'./dropdown/infiniteScroll',
'./dropdown/attachBody',
'./dropdown/minimumResultsForSearch',
'./i18n/en'
], function ($, ResultsList,
@ -3076,7 +3113,7 @@ define('select2/defaults',[
MinimumInputLength, MaximumInputLength,
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
AttachBody,
AttachBody, MinimumResultsForSearch,
EnglishTranslation) {
function Defaults () {
@ -3094,25 +3131,24 @@ define('select2/defaults',[
} else {
options.dataAdapter = SelectData;
}
}
if (options.minimumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MinimumInputLength
);
}
if (options.minimumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MinimumInputLength
);
}
if (options.maximumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumInputLength
);
}
if (options.maximumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumInputLength
);
}
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
}
}
if (options.resultsAdapter == null) {
@ -3142,6 +3178,13 @@ define('select2/defaults',[
options.dropdownAdapter = SearchableDropdown;
}
if (options.minimumResultsForSearch > 0) {
options.dropdownAdapter = Utils.Decorate(
options.dropdownAdapter,
MinimumResultsForSearch
);
}
options.dropdownAdapter = Utils.Decorate(
options.dropdownAdapter,
AttachBody
@ -3275,13 +3318,14 @@ define('select2/defaults',[
},
minimumInputLength: 0,
maximumInputLength: 0,
theme: 'default',
minimumResultsForSearch: 0,
templateResult: function (result) {
return result.text;
},
templateSelection: function (selection) {
return selection.text;
}
},
theme: 'default'
};
};

View File

@ -12528,6 +12528,42 @@ define('select2/dropdown/attachBody',[
return AttachBody;
});
define('select2/dropdown/minimumResultsForSearch',[
], function () {
function countResults (data) {
count = 0;
for (var d = 0; d < data.length; d++) {
var item = data[d];
if (item.children) {
count += countResults(item.children);
} else {
count++;
}
}
return count;
}
function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
this.minimumResultsForSearch = options.get('minimumResultsForSearch');
decorated.call(this, $element, options, dataAdapter);
}
MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
if (countResults(params.data) < this.minimumResultsForSearch) {
return false;
}
return decorated.call(this, params);
};
return MinimumResultsForSearch;
});
define('select2/i18n/en',[],function () {
return {
errorLoading: function () {
@ -12598,6 +12634,7 @@ define('select2/defaults',[
'./dropdown/hidePlaceholder',
'./dropdown/infiniteScroll',
'./dropdown/attachBody',
'./dropdown/minimumResultsForSearch',
'./i18n/en'
], function ($, ResultsList,
@ -12611,7 +12648,7 @@ define('select2/defaults',[
MinimumInputLength, MaximumInputLength,
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
AttachBody,
AttachBody, MinimumResultsForSearch,
EnglishTranslation) {
function Defaults () {
@ -12629,25 +12666,24 @@ define('select2/defaults',[
} else {
options.dataAdapter = SelectData;
}
}
if (options.minimumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MinimumInputLength
);
}
if (options.minimumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MinimumInputLength
);
}
if (options.maximumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumInputLength
);
}
if (options.maximumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumInputLength
);
}
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
}
}
if (options.resultsAdapter == null) {
@ -12677,6 +12713,13 @@ define('select2/defaults',[
options.dropdownAdapter = SearchableDropdown;
}
if (options.minimumResultsForSearch > 0) {
options.dropdownAdapter = Utils.Decorate(
options.dropdownAdapter,
MinimumResultsForSearch
);
}
options.dropdownAdapter = Utils.Decorate(
options.dropdownAdapter,
AttachBody
@ -12810,13 +12853,14 @@ define('select2/defaults',[
},
minimumInputLength: 0,
maximumInputLength: 0,
theme: 'default',
minimumResultsForSearch: 0,
templateResult: function (result) {
return result.text;
},
templateSelection: function (selection) {
return selection.text;
}
},
theme: 'default'
};
};

File diff suppressed because one or more lines are too long

82
dist/js/select2.js vendored
View File

@ -3421,6 +3421,42 @@ define('select2/dropdown/attachBody',[
return AttachBody;
});
define('select2/dropdown/minimumResultsForSearch',[
], function () {
function countResults (data) {
count = 0;
for (var d = 0; d < data.length; d++) {
var item = data[d];
if (item.children) {
count += countResults(item.children);
} else {
count++;
}
}
return count;
}
function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
this.minimumResultsForSearch = options.get('minimumResultsForSearch');
decorated.call(this, $element, options, dataAdapter);
}
MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
if (countResults(params.data) < this.minimumResultsForSearch) {
return false;
}
return decorated.call(this, params);
};
return MinimumResultsForSearch;
});
define('select2/i18n/en',[],function () {
return {
errorLoading: function () {
@ -3491,6 +3527,7 @@ define('select2/defaults',[
'./dropdown/hidePlaceholder',
'./dropdown/infiniteScroll',
'./dropdown/attachBody',
'./dropdown/minimumResultsForSearch',
'./i18n/en'
], function ($, ResultsList,
@ -3504,7 +3541,7 @@ define('select2/defaults',[
MinimumInputLength, MaximumInputLength,
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
AttachBody,
AttachBody, MinimumResultsForSearch,
EnglishTranslation) {
function Defaults () {
@ -3522,25 +3559,24 @@ define('select2/defaults',[
} else {
options.dataAdapter = SelectData;
}
}
if (options.minimumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MinimumInputLength
);
}
if (options.minimumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MinimumInputLength
);
}
if (options.maximumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumInputLength
);
}
if (options.maximumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumInputLength
);
}
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
}
}
if (options.resultsAdapter == null) {
@ -3570,6 +3606,13 @@ define('select2/defaults',[
options.dropdownAdapter = SearchableDropdown;
}
if (options.minimumResultsForSearch > 0) {
options.dropdownAdapter = Utils.Decorate(
options.dropdownAdapter,
MinimumResultsForSearch
);
}
options.dropdownAdapter = Utils.Decorate(
options.dropdownAdapter,
AttachBody
@ -3703,13 +3746,14 @@ define('select2/defaults',[
},
minimumInputLength: 0,
maximumInputLength: 0,
theme: 'default',
minimumResultsForSearch: 0,
templateResult: function (result) {
return result.text;
},
templateSelection: function (selection) {
return selection.text;
}
},
theme: 'default'
};
};

File diff suppressed because one or more lines are too long

View File

@ -24,6 +24,7 @@ define([
'./dropdown/hidePlaceholder',
'./dropdown/infiniteScroll',
'./dropdown/attachBody',
'./dropdown/minimumResultsForSearch',
'./i18n/en'
], function ($, ResultsList,
@ -37,7 +38,7 @@ define([
MinimumInputLength, MaximumInputLength,
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
AttachBody,
AttachBody, MinimumResultsForSearch,
EnglishTranslation) {
function Defaults () {
@ -55,25 +56,24 @@ define([
} else {
options.dataAdapter = SelectData;
}
}
if (options.minimumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MinimumInputLength
);
}
if (options.minimumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MinimumInputLength
);
}
if (options.maximumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumInputLength
);
}
if (options.maximumInputLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumInputLength
);
}
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
}
}
if (options.resultsAdapter == null) {
@ -103,6 +103,13 @@ define([
options.dropdownAdapter = SearchableDropdown;
}
if (options.minimumResultsForSearch > 0) {
options.dropdownAdapter = Utils.Decorate(
options.dropdownAdapter,
MinimumResultsForSearch
);
}
options.dropdownAdapter = Utils.Decorate(
options.dropdownAdapter,
AttachBody
@ -236,13 +243,14 @@ define([
},
minimumInputLength: 0,
maximumInputLength: 0,
theme: 'default',
minimumResultsForSearch: 0,
templateResult: function (result) {
return result.text;
},
templateSelection: function (selection) {
return selection.text;
}
},
theme: 'default'
};
};

View File

@ -0,0 +1,35 @@
define([
], function () {
function countResults (data) {
count = 0;
for (var d = 0; d < data.length; d++) {
var item = data[d];
if (item.children) {
count += countResults(item.children);
} else {
count++;
}
}
return count;
}
function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {
this.minimumResultsForSearch = options.get('minimumResultsForSearch');
decorated.call(this, $element, options, dataAdapter);
}
MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {
if (countResults(params.data) < this.minimumResultsForSearch) {
return false;
}
return decorated.call(this, params);
};
return MinimumResultsForSearch;
});

View File

@ -62,7 +62,7 @@
width: 100%;
}
.select2-search--hide {
&.select2-search--hide {
display: none;
}
}