1
0
mirror of synced 2024-11-29 16:16:02 +03:00

add maximum selection length option

This commit is contained in:
Zubair 2015-01-12 17:32:08 -05:00
parent 5dad831f7f
commit 2bdb5dbdae
8 changed files with 207 additions and 13 deletions

View File

@ -2852,6 +2852,36 @@ define('select2/data/maximumInputLength',[
return MaximumInputLength;
});
define('select2/data/maximumSelectionLength',[
], function (){
function MaximumSelectionLength (decorated, $e, options) {
this.maximumSelectionLength = options.get('maximumSelectionLength');
decorated.call(this, $e, options);
}
MaximumSelectionLength.prototype.query =
function (decorated, params, callback) {
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
}
});
return;
}
decorated.call(this, params, callback);
};
return MaximumSelectionLength;
});
define('select2/dropdown',[
'./utils'
], function (Utils) {
@ -3403,6 +3433,7 @@ define('select2/defaults',[
'./data/tokenizer',
'./data/minimumInputLength',
'./data/maximumInputLength',
'./data/maximumSelectionLength',
'./dropdown',
'./dropdown/search',
@ -3421,7 +3452,7 @@ define('select2/defaults',[
Utils, Translation, DIACRITICS,
SelectData, ArrayData, AjaxData, Tags, Tokenizer,
MinimumInputLength, MaximumInputLength,
MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
AttachBody, MinimumResultsForSearch, SelectOnClose,
@ -3457,6 +3488,13 @@ define('select2/defaults',[
);
}
if (options.maximumSelectionLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumSelectionLength
);
}
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
}
@ -3570,7 +3608,7 @@ define('select2/defaults',[
language = Translation.loadPath(name);
} catch (e) {
// If we couldn't load it, check if it wasn't the full path
name = this.get('amdTranslationBase') + name;
name = this.defaults.amdLanguageBase + name;
language = Translation.loadPath(name);
}
@ -3647,6 +3685,7 @@ define('select2/defaults',[
matcher: matcher,
minimumInputLength: 0,
maximumInputLength: 0,
maximumSelectionLength: 0,
minimumResultsForSearch: 0,
selectOnClose: false,
sorter: function (data) {

View File

@ -2852,6 +2852,36 @@ define('select2/data/maximumInputLength',[
return MaximumInputLength;
});
define('select2/data/maximumSelectionLength',[
], function (){
function MaximumSelectionLength (decorated, $e, options) {
this.maximumSelectionLength = options.get('maximumSelectionLength');
decorated.call(this, $e, options);
}
MaximumSelectionLength.prototype.query =
function (decorated, params, callback) {
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
}
});
return;
}
decorated.call(this, params, callback);
};
return MaximumSelectionLength;
});
define('select2/dropdown',[
'./utils'
], function (Utils) {
@ -3403,6 +3433,7 @@ define('select2/defaults',[
'./data/tokenizer',
'./data/minimumInputLength',
'./data/maximumInputLength',
'./data/maximumSelectionLength',
'./dropdown',
'./dropdown/search',
@ -3421,7 +3452,7 @@ define('select2/defaults',[
Utils, Translation, DIACRITICS,
SelectData, ArrayData, AjaxData, Tags, Tokenizer,
MinimumInputLength, MaximumInputLength,
MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
AttachBody, MinimumResultsForSearch, SelectOnClose,
@ -3457,6 +3488,13 @@ define('select2/defaults',[
);
}
if (options.maximumSelectionLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumSelectionLength
);
}
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
}
@ -3570,7 +3608,7 @@ define('select2/defaults',[
language = Translation.loadPath(name);
} catch (e) {
// If we couldn't load it, check if it wasn't the full path
name = this.get('amdTranslationBase') + name;
name = this.defaults.amdLanguageBase + name;
language = Translation.loadPath(name);
}
@ -3647,6 +3685,7 @@ define('select2/defaults',[
matcher: matcher,
minimumInputLength: 0,
maximumInputLength: 0,
maximumSelectionLength: 0,
minimumResultsForSearch: 0,
selectOnClose: false,
sorter: function (data) {

View File

@ -12387,6 +12387,36 @@ define('select2/data/maximumInputLength',[
return MaximumInputLength;
});
define('select2/data/maximumSelectionLength',[
], function (){
function MaximumSelectionLength (decorated, $e, options) {
this.maximumSelectionLength = options.get('maximumSelectionLength');
decorated.call(this, $e, options);
}
MaximumSelectionLength.prototype.query =
function (decorated, params, callback) {
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
}
});
return;
}
decorated.call(this, params, callback);
};
return MaximumSelectionLength;
});
define('select2/dropdown',[
'./utils'
], function (Utils) {
@ -12938,6 +12968,7 @@ define('select2/defaults',[
'./data/tokenizer',
'./data/minimumInputLength',
'./data/maximumInputLength',
'./data/maximumSelectionLength',
'./dropdown',
'./dropdown/search',
@ -12956,7 +12987,7 @@ define('select2/defaults',[
Utils, Translation, DIACRITICS,
SelectData, ArrayData, AjaxData, Tags, Tokenizer,
MinimumInputLength, MaximumInputLength,
MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
AttachBody, MinimumResultsForSearch, SelectOnClose,
@ -12992,6 +13023,13 @@ define('select2/defaults',[
);
}
if (options.maximumSelectionLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumSelectionLength
);
}
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
}
@ -13105,7 +13143,7 @@ define('select2/defaults',[
language = Translation.loadPath(name);
} catch (e) {
// If we couldn't load it, check if it wasn't the full path
name = this.get('amdTranslationBase') + name;
name = this.defaults.amdLanguageBase + name;
language = Translation.loadPath(name);
}
@ -13182,6 +13220,7 @@ define('select2/defaults',[
matcher: matcher,
minimumInputLength: 0,
maximumInputLength: 0,
maximumSelectionLength: 0,
minimumResultsForSearch: 0,
selectOnClose: false,
sorter: function (data) {

File diff suppressed because one or more lines are too long

43
dist/js/select2.js vendored
View File

@ -3280,6 +3280,36 @@ define('select2/data/maximumInputLength',[
return MaximumInputLength;
});
define('select2/data/maximumSelectionLength',[
], function (){
function MaximumSelectionLength (decorated, $e, options) {
this.maximumSelectionLength = options.get('maximumSelectionLength');
decorated.call(this, $e, options);
}
MaximumSelectionLength.prototype.query =
function (decorated, params, callback) {
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
}
});
return;
}
decorated.call(this, params, callback);
};
return MaximumSelectionLength;
});
define('select2/dropdown',[
'./utils'
], function (Utils) {
@ -3831,6 +3861,7 @@ define('select2/defaults',[
'./data/tokenizer',
'./data/minimumInputLength',
'./data/maximumInputLength',
'./data/maximumSelectionLength',
'./dropdown',
'./dropdown/search',
@ -3849,7 +3880,7 @@ define('select2/defaults',[
Utils, Translation, DIACRITICS,
SelectData, ArrayData, AjaxData, Tags, Tokenizer,
MinimumInputLength, MaximumInputLength,
MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
AttachBody, MinimumResultsForSearch, SelectOnClose,
@ -3885,6 +3916,13 @@ define('select2/defaults',[
);
}
if (options.maximumSelectionLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumSelectionLength
);
}
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
}
@ -3998,7 +4036,7 @@ define('select2/defaults',[
language = Translation.loadPath(name);
} catch (e) {
// If we couldn't load it, check if it wasn't the full path
name = this.get('amdTranslationBase') + name;
name = this.defaults.amdLanguageBase + name;
language = Translation.loadPath(name);
}
@ -4075,6 +4113,7 @@ define('select2/defaults',[
matcher: matcher,
minimumInputLength: 0,
maximumInputLength: 0,
maximumSelectionLength: 0,
minimumResultsForSearch: 0,
selectOnClose: false,
sorter: function (data) {

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,29 @@
define([
], function (){
function MaximumSelectionLength (decorated, $e, options) {
this.maximumSelectionLength = options.get('maximumSelectionLength');
decorated.call(this, $e, options);
}
MaximumSelectionLength.prototype.query =
function (decorated, params, callback) {
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
}
});
return;
}
decorated.call(this, params, callback);
};
return MaximumSelectionLength;
});

View File

@ -20,6 +20,7 @@ define([
'./data/tokenizer',
'./data/minimumInputLength',
'./data/maximumInputLength',
'./data/maximumSelectionLength',
'./dropdown',
'./dropdown/search',
@ -38,7 +39,7 @@ define([
Utils, Translation, DIACRITICS,
SelectData, ArrayData, AjaxData, Tags, Tokenizer,
MinimumInputLength, MaximumInputLength,
MinimumInputLength, MaximumInputLength, MaximumSelectionLength,
Dropdown, DropdownSearch, HidePlaceholder, InfiniteScroll,
AttachBody, MinimumResultsForSearch, SelectOnClose,
@ -74,6 +75,13 @@ define([
);
}
if (options.maximumSelectionLength > 0) {
options.dataAdapter = Utils.Decorate(
options.dataAdapter,
MaximumSelectionLength
);
}
if (options.tags != null) {
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
}
@ -187,7 +195,7 @@ define([
language = Translation.loadPath(name);
} catch (e) {
// If we couldn't load it, check if it wasn't the full path
name = this.get('amdTranslationBase') + name;
name = this.defaults.amdLanguageBase + name;
language = Translation.loadPath(name);
}
@ -264,6 +272,7 @@ define([
matcher: matcher,
minimumInputLength: 0,
maximumInputLength: 0,
maximumSelectionLength: 0,
minimumResultsForSearch: 0,
selectOnClose: false,
sorter: function (data) {