|
@@ -9718,19 +9718,25 @@ define('select2/results',[
|
|
|
this.$results.empty();
|
|
|
};
|
|
|
|
|
|
- Results.prototype.empty = function () {
|
|
|
- var $empty = $('<li role="treeitem" class="option"></li>');
|
|
|
+ Results.prototype.displayMessage = function (params) {
|
|
|
+ this.clear();
|
|
|
+
|
|
|
+ var $message = $('<li role="treeitem" class="option"></li>');
|
|
|
+
|
|
|
+ var message = this.options.get('translations').get(params.message);
|
|
|
|
|
|
- $empty.text(this.options.get('translations').get('noResults'));
|
|
|
+ $message.text(message(params.args));
|
|
|
|
|
|
- this.$results.append($empty);
|
|
|
+ this.$results.append($message);
|
|
|
};
|
|
|
|
|
|
Results.prototype.append = function (data) {
|
|
|
var $options = [];
|
|
|
|
|
|
if (data.length === 0) {
|
|
|
- this.empty();
|
|
|
+ this.trigger('results:message', {
|
|
|
+ message: 'noResults'
|
|
|
+ });
|
|
|
|
|
|
return;
|
|
|
}
|
|
@@ -9984,6 +9990,14 @@ define('select2/results',[
|
|
|
params.element.addClass('highlighted');
|
|
|
});
|
|
|
|
|
|
+ container.on('results:message', function (params) {
|
|
|
+ self.trigger('results:message', params);
|
|
|
+ });
|
|
|
+
|
|
|
+ this.on('results:message', function (params) {
|
|
|
+ self.displayMessage(params);
|
|
|
+ });
|
|
|
+
|
|
|
this.$results.on('mouseup', '.option[aria-selected]', function (evt) {
|
|
|
var $this = $(this);
|
|
|
|
|
@@ -10276,10 +10290,7 @@ define('select2/selection/multiple',[
|
|
|
'../utils'
|
|
|
], function (BaseSelection, Utils) {
|
|
|
function MultipleSelection ($element, options) {
|
|
|
- this.$element = $element;
|
|
|
- this.options = options;
|
|
|
-
|
|
|
- MultipleSelection.__super__.constructor.call(this);
|
|
|
+ MultipleSelection.__super__.constructor.apply(this, arguments);
|
|
|
}
|
|
|
|
|
|
Utils.Extend(MultipleSelection, BaseSelection);
|
|
@@ -10896,6 +10907,37 @@ define('select2/data/tags',[
|
|
|
return Tags;
|
|
|
});
|
|
|
|
|
|
+define('select2/data/minimumInputLength',[
|
|
|
+
|
|
|
+], function () {
|
|
|
+ function MinimumInputLength (decorated, $e, options) {
|
|
|
+ this.minimumInputLength = options.get('minimumInputLength');
|
|
|
+
|
|
|
+ decorated.call(this, $e, options);
|
|
|
+ }
|
|
|
+
|
|
|
+ MinimumInputLength.prototype.query = function (decorated, params, callback) {
|
|
|
+ params.term = params.term || '';
|
|
|
+
|
|
|
+ if (params.term.length < this.minimumInputLength) {
|
|
|
+ this.trigger('results:message', {
|
|
|
+ message: 'inputTooShort',
|
|
|
+ args: {
|
|
|
+ minimum: this.minimumInputLength,
|
|
|
+ input: params.term,
|
|
|
+ params: params
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ decorated.call(this, params, callback);
|
|
|
+ };
|
|
|
+
|
|
|
+ return MinimumInputLength;
|
|
|
+});
|
|
|
+
|
|
|
define('select2/dropdown',[
|
|
|
'./utils'
|
|
|
], function (Utils) {
|
|
@@ -10956,13 +10998,7 @@ define('select2/dropdown/search',[
|
|
|
});
|
|
|
|
|
|
this.$search.on('keyup', function (evt) {
|
|
|
- if (!self._keyUpPrevented) {
|
|
|
- self.trigger('query', {
|
|
|
- term: $(this).val()
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- self._keyUpPrevented = false;
|
|
|
+ self.handleSearch(evt);
|
|
|
});
|
|
|
|
|
|
container.on('open', function () {
|
|
@@ -10988,6 +11024,18 @@ define('select2/dropdown/search',[
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ Search.prototype.handleSearch = function (evt) {
|
|
|
+ if (!this._keyUpPrevented) {
|
|
|
+ var input = this.$search.val();
|
|
|
+
|
|
|
+ this.trigger('query', {
|
|
|
+ term: input
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ this._keyUpPrevented = false;
|
|
|
+ };
|
|
|
+
|
|
|
Search.prototype.showSearch = function (_, params) {
|
|
|
return true;
|
|
|
};
|
|
@@ -11040,6 +11088,17 @@ define('select2/dropdown/hidePlaceholder',[
|
|
|
|
|
|
define('select2/i18n/en',[],function () {
|
|
|
return {
|
|
|
+ inputTooShort: function (args) {
|
|
|
+ var remainingChars = args.minimum - args.input.length;
|
|
|
+
|
|
|
+ var message = 'Please enter ' + remainingChars + ' or more character';
|
|
|
+
|
|
|
+ if (remainingChars != 1) {
|
|
|
+ message += 's';
|
|
|
+ }
|
|
|
+
|
|
|
+ return message;
|
|
|
+ },
|
|
|
noResults: function () {
|
|
|
return 'No results found';
|
|
|
}
|
|
@@ -11061,6 +11120,7 @@ define('select2/defaults',[
|
|
|
'./data/array',
|
|
|
'./data/ajax',
|
|
|
'./data/tags',
|
|
|
+ './data/minimumInputLength',
|
|
|
|
|
|
'./dropdown',
|
|
|
'./dropdown/search',
|
|
@@ -11070,7 +11130,7 @@ define('select2/defaults',[
|
|
|
], function ($, ResultsList,
|
|
|
SingleSelection, MultipleSelection, Placeholder,
|
|
|
Utils, Translation,
|
|
|
- SelectData, ArrayData, AjaxData, Tags,
|
|
|
+ SelectData, ArrayData, AjaxData, Tags, MinimumInputLength,
|
|
|
Dropdown, Search, HidePlaceholder,
|
|
|
EnglishTranslation) {
|
|
|
function Defaults () {
|
|
@@ -11090,6 +11150,14 @@ define('select2/defaults',[
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ if (options.minimumInputLength > 0) {
|
|
|
+ options.dataAdapter = Utils.Decorate(
|
|
|
+ options.dataAdapter,
|
|
|
+ MinimumInputLength
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
if (options.tags != null) {
|
|
|
options.dataAdapter = Utils.Decorate(options.dataAdapter, Tags);
|
|
|
}
|
|
@@ -11162,6 +11230,7 @@ define('select2/defaults',[
|
|
|
Defaults.prototype.reset = function () {
|
|
|
this.defaults = {
|
|
|
language: ['select2/i18n/en'],
|
|
|
+ minimumInputLength: 0,
|
|
|
templateResult: function (result) {
|
|
|
return result.text;
|
|
|
},
|
|
@@ -11266,6 +11335,7 @@ define('select2/core',[
|
|
|
this._registerDomEvents();
|
|
|
|
|
|
// Register any internal event handlers
|
|
|
+ this._registerDataEvents();
|
|
|
this._registerSelectionEvents();
|
|
|
this._registerDropdownEvents();
|
|
|
this._registerResultsEvents();
|
|
@@ -11347,6 +11417,14 @@ define('select2/core',[
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ Select2.prototype._registerDataEvents = function () {
|
|
|
+ var self = this;
|
|
|
+
|
|
|
+ this.data.on('results:message', function (params) {
|
|
|
+ self.trigger('results:message', params);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
Select2.prototype._registerSelectionEvents = function () {
|
|
|
var self = this;
|
|
|
|