Skip to content

Commit 08bf83f

Browse files
committed
renamed selection limit option and formatting function to better align with existing naming. select2#274 select2#59
1 parent 4344fa0 commit 08bf83f

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

select2.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
Copyright 2012 Igor Vaynberg
33
44
Version: @@ver@@ Timestamp: @@timestamp@@
@@ -1016,7 +1016,7 @@
10161016
*/
10171017
// abstract
10181018
updateResults: function (initial) {
1019-
var search = this.search, results = this.results, opts = this.opts, self=this;
1019+
var search = this.search, results = this.results, opts = this.opts, data, self=this;
10201020

10211021
// if the search is currently hidden we do not alter the results
10221022
if (initial !== true && (this.showSearchInput === false || !this.opened())) {
@@ -1035,10 +1035,13 @@
10351035
results.html(escapeMarkup(html));
10361036
postRender();
10371037
}
1038-
1039-
if (opts.selectionLimit && ("getVal" in this) && this.getVal().length >= opts.selectionLimit) {
1040-
render("<li class='select2-selection-limit'>" + opts.formatLimitReached(opts.selectionLimit) + "</li>");
1041-
return;
1038+
1039+
if (opts.maximumSelectionSize >=1) {
1040+
data = this.data();
1041+
if ($.isArray(data) && data.length >= opts.maximumSelectionSize) {
1042+
render("<li class='select2-selection-limit'>" + opts.formatSelectionTooBig(opts.maximumSelectionSize) + "</li>");
1043+
return;
1044+
}
10421045
}
10431046

10441047
if (search.val().length < opts.minimumInputLength) {
@@ -2143,11 +2146,11 @@
21432146
},
21442147
formatNoMatches: function () { return "No matches found"; },
21452148
formatInputTooShort: function (input, min) { return "Please enter " + (min - input.length) + " more characters"; },
2146-
formatLimitReached: function (limit) { return "You can only select " + limit + " items"; },
2149+
formatSelectionTooBig: function (limit) { return "You can only select " + limit + " items"; },
21472150
formatLoadMore: function (pageNumber) { return "Loading more results..."; },
21482151
minimumResultsForSearch: 0,
21492152
minimumInputLength: 0,
2150-
selectionLimit: 0,
2153+
maximumSelectionSize: 0,
21512154
id: function (e) { return e.id; },
21522155
matcher: function(term, text) {
21532156
return text.toUpperCase().indexOf(term.toUpperCase()) >= 0;

0 commit comments

Comments
 (0)