1
0
mirror of synced 2024-11-26 14:56:07 +03:00

fix closeOnSelect and maximumSelectionSize combo bug. fixes #672

This commit is contained in:
Igor Vaynberg 2013-02-09 15:48:20 -08:00
parent 6c4b96791d
commit d54378563c

View File

@ -609,7 +609,7 @@ the specific language governing permissions and limitations under the Apache Lic
} }
syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass); syncCssClasses(this.container, this.opts.element, this.opts.adaptContainerCssClass);
this.container.css(evaluate(opts.containerCss)); this.container.css(evaluate(opts.containerCss));
this.container.addClass(evaluate(opts.containerCssClass)); this.container.addClass(evaluate(opts.containerCssClass));
@ -1158,6 +1158,11 @@ the specific language governing permissions and limitations under the Apache Lic
}, },
//abstract
getMaximumSelectionSize: function() {
return evaluate(this.opts.maximumSelectionSize);
},
// abstract // abstract
ensureHighlightVisible: function () { ensureHighlightVisible: function () {
var results = this.results, children, index, child, hb, rb, y, more; 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
postRender(); postRender();
} }
var maxSelSize = $.isFunction(opts.maximumSelectionSize) ? opts.maximumSelectionSize() : opts.maximumSelectionSize; var maxSelSize = this.getMaximumSelectionSize();
if (maxSelSize >=1) { if (maxSelSize >=1) {
data = this.data(); data = this.data();
if ($.isArray(data) && data.length >= maxSelSize && checkFormatter(opts.formatSelectionTooBig, "formatSelectionTooBig")) { 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
// multi // multi
onSelect: function (data, options) { onSelect: function (data, options) {
this.addSelectedChoice(data); this.addSelectedChoice(data);
if (this.select || !this.opts.closeOnSelect) this.postprocessResults(); if (this.select || !this.opts.closeOnSelect) this.postprocessResults();
if (this.opts.closeOnSelect) { if (this.opts.closeOnSelect) {
@ -2231,10 +2237,16 @@ the specific language governing permissions and limitations under the Apache Lic
if (this.countSelectableResults()>0) { if (this.countSelectableResults()>0) {
this.search.width(10); this.search.width(10);
this.resizeSearch(); this.resizeSearch();
if (this.val().length >= this.getMaximumSelectionSize()) {
// if we reached max selection size repaint the results so choices
// are replaced with the max selection reached message
this.updateResults(true);
}
this.positionDropdown(); this.positionDropdown();
} else { } else {
// if nothing left to select close // if nothing left to select close
this.close(); this.close();
this.search.width(10);
} }
} }