fix callback using this.current.
add example.
This commit is contained in:
parent
1c8846079b
commit
e18fa1b5b8
21
dist/js/select2.amd.full.js
vendored
21
dist/js/select2.amd.full.js
vendored
@ -2863,20 +2863,23 @@ define('select2/data/maximumSelectionLength',[
|
||||
|
||||
MaximumSelectionLength.prototype.query =
|
||||
function (decorated, params, callback) {
|
||||
var self = this;
|
||||
|
||||
var count = this.$element.val() != null ? this.$element.val().length : 0;
|
||||
if (count >= this.maximumSelectionLength) {
|
||||
this.trigger('results:message', {
|
||||
message: 'maximumSelected',
|
||||
args: {
|
||||
maximum: this.maximumSelectionLength
|
||||
this.current(function (currentData) {
|
||||
var count = currentData != null ? currentData.length : 0;
|
||||
if (count >= self.maximumSelectionLength) {
|
||||
self.trigger('results:message', {
|
||||
message: 'maximumSelected',
|
||||
args: {
|
||||
maximum: self.maximumSelectionLength
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
decorated.call(self, params, callback);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
decorated.call(this, params, callback);
|
||||
};
|
||||
|
||||
return MaximumSelectionLength;
|
||||
|
21
dist/js/select2.amd.js
vendored
21
dist/js/select2.amd.js
vendored
@ -2863,20 +2863,23 @@ define('select2/data/maximumSelectionLength',[
|
||||
|
||||
MaximumSelectionLength.prototype.query =
|
||||
function (decorated, params, callback) {
|
||||
var self = this;
|
||||
|
||||
var count = this.$element.val() != null ? this.$element.val().length : 0;
|
||||
if (count >= this.maximumSelectionLength) {
|
||||
this.trigger('results:message', {
|
||||
message: 'maximumSelected',
|
||||
args: {
|
||||
maximum: this.maximumSelectionLength
|
||||
this.current(function (currentData) {
|
||||
var count = currentData != null ? currentData.length : 0;
|
||||
if (count >= self.maximumSelectionLength) {
|
||||
self.trigger('results:message', {
|
||||
message: 'maximumSelected',
|
||||
args: {
|
||||
maximum: self.maximumSelectionLength
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
decorated.call(self, params, callback);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
decorated.call(this, params, callback);
|
||||
};
|
||||
|
||||
return MaximumSelectionLength;
|
||||
|
21
dist/js/select2.full.js
vendored
21
dist/js/select2.full.js
vendored
@ -12398,20 +12398,23 @@ define('select2/data/maximumSelectionLength',[
|
||||
|
||||
MaximumSelectionLength.prototype.query =
|
||||
function (decorated, params, callback) {
|
||||
var self = this;
|
||||
|
||||
var count = this.$element.val() != null ? this.$element.val().length : 0;
|
||||
if (count >= this.maximumSelectionLength) {
|
||||
this.trigger('results:message', {
|
||||
message: 'maximumSelected',
|
||||
args: {
|
||||
maximum: this.maximumSelectionLength
|
||||
this.current(function (currentData) {
|
||||
var count = currentData != null ? currentData.length : 0;
|
||||
if (count >= self.maximumSelectionLength) {
|
||||
self.trigger('results:message', {
|
||||
message: 'maximumSelected',
|
||||
args: {
|
||||
maximum: self.maximumSelectionLength
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
decorated.call(self, params, callback);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
decorated.call(this, params, callback);
|
||||
};
|
||||
|
||||
return MaximumSelectionLength;
|
||||
|
4
dist/js/select2.full.min.js
vendored
4
dist/js/select2.full.min.js
vendored
File diff suppressed because one or more lines are too long
21
dist/js/select2.js
vendored
21
dist/js/select2.js
vendored
@ -3291,20 +3291,23 @@ define('select2/data/maximumSelectionLength',[
|
||||
|
||||
MaximumSelectionLength.prototype.query =
|
||||
function (decorated, params, callback) {
|
||||
var self = this;
|
||||
|
||||
var count = this.$element.val() != null ? this.$element.val().length : 0;
|
||||
if (count >= this.maximumSelectionLength) {
|
||||
this.trigger('results:message', {
|
||||
message: 'maximumSelected',
|
||||
args: {
|
||||
maximum: this.maximumSelectionLength
|
||||
this.current(function (currentData) {
|
||||
var count = currentData != null ? currentData.length : 0;
|
||||
if (count >= self.maximumSelectionLength) {
|
||||
self.trigger('results:message', {
|
||||
message: 'maximumSelected',
|
||||
args: {
|
||||
maximum: self.maximumSelectionLength
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
decorated.call(self, params, callback);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
decorated.call(this, params, callback);
|
||||
};
|
||||
|
||||
return MaximumSelectionLength;
|
||||
|
2
dist/js/select2.min.js
vendored
2
dist/js/select2.min.js
vendored
File diff suppressed because one or more lines are too long
@ -67,6 +67,35 @@ $(document).ready(function() {
|
||||
<script type="text/x-example-code" class="js-code-multiple">
|
||||
$(".js-example-basic-multiple").select2();
|
||||
|
||||
<select class="js-example-basic-multiple" multiple="multiple">
|
||||
<option value="AL">Alabama</option>
|
||||
...
|
||||
<option value="WY">Wyoming</option>
|
||||
</select>
|
||||
</script>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="multiple_max" class="row">
|
||||
<div class="col-md-4">
|
||||
<h1>Limited Multiple select boxes</h1>
|
||||
<p>Select2 multi-value select boxes can set restrictions regarding the maximum number of options selected.
|
||||
The select below is declared with the <code>multiple</code> attribute with <code>maxSelectionLength</code> in the select2 options</p>
|
||||
|
||||
<p>
|
||||
<select class="js-example-basic-multiple-limit js-states form-control" multiple="multiple"></select>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<h2>Example code</h2>
|
||||
|
||||
<pre data-fill-from=".js-code-multiple-limit"></pre>
|
||||
|
||||
<script type="text/x-example-code" class="js-code-multiple-limit">
|
||||
$(".js-example-basic-multiple-limit").select2({
|
||||
maximumSelectionLength: 2
|
||||
});
|
||||
|
||||
<select class="js-example-basic-multiple" multiple="multiple">
|
||||
<option value="AL">Alabama</option>
|
||||
...
|
||||
@ -812,6 +841,7 @@ $.fn.select2.amd.require(
|
||||
function (Select2, Utils, oldMatcher) {
|
||||
var $basicSingle = $(".js-example-basic-single");
|
||||
var $basicMultiple = $(".js-example-basic-multiple");
|
||||
var $limitMultiple = $(".js-example-basic-multiple-limit");
|
||||
|
||||
var $dataArray = $(".js-example-data-array");
|
||||
var $dataArraySelected = $(".js-example-data-array-selected");
|
||||
@ -830,7 +860,10 @@ $.fn.select2.amd.require(
|
||||
var $language = $(".js-example-language");
|
||||
|
||||
$basicSingle.select2();
|
||||
$basicMultiple.select2()
|
||||
$basicMultiple.select2();
|
||||
$limitMultiple.select2({
|
||||
maximumSelectionLength: 2
|
||||
});
|
||||
|
||||
$dataArray.select2({
|
||||
data: data
|
||||
|
23
src/js/select2/data/maximumSelectionLength.js
vendored
23
src/js/select2/data/maximumSelectionLength.js
vendored
@ -9,20 +9,21 @@ define([
|
||||
|
||||
MaximumSelectionLength.prototype.query =
|
||||
function (decorated, params, callback) {
|
||||
var self = this;
|
||||
|
||||
var count = this.current() != null ? this.current().length : 0;
|
||||
if (count >= this.maximumSelectionLength) {
|
||||
this.trigger('results:message', {
|
||||
message: 'maximumSelected',
|
||||
args: {
|
||||
maximum: this.maximumSelectionLength
|
||||
this.current(function (currentData) {
|
||||
var count = currentData != null ? currentData.length : 0;
|
||||
if (count >= self.maximumSelectionLength) {
|
||||
self.trigger('results:message', {
|
||||
message: 'maximumSelected',
|
||||
args: {
|
||||
maximum: self.maximumSelectionLength
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
decorated.call(self, params, callback);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
decorated.call(this, params, callback);
|
||||
};
|
||||
|
||||
return MaximumSelectionLength;
|
||||
|
Loading…
x
Reference in New Issue
Block a user