Be able to limit each input to a maximum length
This commit is contained in:
parent
7f83d8276a
commit
007fd8c3f5
11
select2.js
11
select2.js
@ -1248,6 +1248,15 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
render("<li class='select2-searching'>" + opts.formatSearching() + "</li>");
|
render("<li class='select2-searching'>" + opts.formatSearching() + "</li>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opts.maximumInputLength && search.val().length > opts.maximumInputLength) {
|
||||||
|
if (checkFormatter(opts.formatInputTooLong, "formatInputTooLong")) {
|
||||||
|
render("<li class='select2-no-results'>" + opts.formatInputTooLong(search.val(), opts.maximumInputLength) + "</li>");
|
||||||
|
} else {
|
||||||
|
render("");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// give the tokenizer a chance to pre-process the input
|
// give the tokenizer a chance to pre-process the input
|
||||||
input = this.tokenize();
|
input = this.tokenize();
|
||||||
if (input != undefined && input != null) {
|
if (input != undefined && input != null) {
|
||||||
@ -2405,11 +2414,13 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
formatResultCssClass: function(data) {return undefined;},
|
formatResultCssClass: function(data) {return undefined;},
|
||||||
formatNoMatches: function () { return "No matches found"; },
|
formatNoMatches: function () { return "No matches found"; },
|
||||||
formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " more character" + (n == 1? "" : "s"); },
|
formatInputTooShort: function (input, min) { var n = min - input.length; return "Please enter " + n + " more character" + (n == 1? "" : "s"); },
|
||||||
|
formatInputTooLong: function (input, max) { var n = input.length - max; return "Please enter " + n + " less character" + (n == 1? "" : "s"); },
|
||||||
formatSelectionTooBig: function (limit) { return "You can only select " + limit + " item" + (limit == 1 ? "" : "s"); },
|
formatSelectionTooBig: function (limit) { return "You can only select " + limit + " item" + (limit == 1 ? "" : "s"); },
|
||||||
formatLoadMore: function (pageNumber) { return "Loading more results..."; },
|
formatLoadMore: function (pageNumber) { return "Loading more results..."; },
|
||||||
formatSearching: function () { return "Searching..."; },
|
formatSearching: function () { return "Searching..."; },
|
||||||
minimumResultsForSearch: 0,
|
minimumResultsForSearch: 0,
|
||||||
minimumInputLength: 0,
|
minimumInputLength: 0,
|
||||||
|
maximumInputLength: null,
|
||||||
maximumSelectionSize: 0,
|
maximumSelectionSize: 0,
|
||||||
id: function (e) { return e.id; },
|
id: function (e) { return e.id; },
|
||||||
matcher: function(term, text) {
|
matcher: function(term, text) {
|
||||||
|
Loading…
Reference in New Issue
Block a user