Skip to content

Commit d543785

Browse files
committed
fix closeOnSelect and maximumSelectionSize combo bug. fixes select2#672
1 parent 6c4b967 commit d543785

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

select2.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ the specific language governing permissions and limitations under the Apache Lic
609609
}
610610

611611
syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass);
612-
612+
613613
this.container.css(evaluate(opts.containerCss));
614614
this.container.addClass(evaluate(opts.containerCssClass));
615615

@@ -1158,6 +1158,11 @@ the specific language governing permissions and limitations under the Apache Lic
11581158

11591159
},
11601160

1161+
//abstract
1162+
getMaximumSelectionSize: function() {
1163+
return evaluate(this.opts.maximumSelectionSize);
1164+
},
1165+
11611166
// abstract
11621167
ensureHighlightVisible: function () {
11631168
var results = this.results, children, index, child, hb, rb, y, more;
@@ -1339,7 +1344,7 @@ the specific language governing permissions and limitations under the Apache Lic
13391344
postRender();
13401345
}
13411346

1342-
var maxSelSize = $.isFunction(opts.maximumSelectionSize) ? opts.maximumSelectionSize() : opts.maximumSelectionSize;
1347+
var maxSelSize = this.getMaximumSelectionSize();
13431348
if (maxSelSize >=1) {
13441349
data = this.data();
13451350
if ($.isArray(data) && data.length >= maxSelSize && checkFormatter(opts.formatSelectionTooBig, "formatSelectionTooBig")) {
@@ -2222,6 +2227,7 @@ the specific language governing permissions and limitations under the Apache Lic
22222227
// multi
22232228
onSelect: function (data, options) {
22242229
this.addSelectedChoice(data);
2230+
22252231
if (this.select || !this.opts.closeOnSelect) this.postprocessResults();
22262232

22272233
if (this.opts.closeOnSelect) {
@@ -2231,10 +2237,16 @@ the specific language governing permissions and limitations under the Apache Lic
22312237
if (this.countSelectableResults()>0) {
22322238
this.search.width(10);
22332239
this.resizeSearch();
2240+
if (this.val().length >= this.getMaximumSelectionSize()) {
2241+
// if we reached max selection size repaint the results so choices
2242+
// are replaced with the max selection reached message
2243+
this.updateResults(true);
2244+
}
22342245
this.positionDropdown();
22352246
} else {
22362247
// if nothing left to select close
22372248
this.close();
2249+
this.search.width(10);
22382250
}
22392251
}
22402252

0 commit comments

Comments
 (0)