I want to limit minimum 3 characters for Selectize tags input. Is it possible? is there any event in selectize?
I had the same problem. Its as Rory has mentioned, via plugins.
Its actually quite simple.
The official example for tag minimum word length filtering you can find here
$('#select-words-length').selectize({
create: true,
createFilter: function(input) { return input.length >= MIN_LENGTH; }
});
Another thing that you can do is filter the search itself
//restricts the matches to fulfill MIN_SEARCH_LENGTH via the 'score' callback
//see https://github.com/brianreavis/selectize.js/blob/master/docs/usage.md#callbacks
score: function scoreFilter(search) {
var ignore = search && search.length < MIN_SEARCH_LENGTH;
var score = this.getScoreFunction(search);
//the "search" argument is a Search object (see https://github.com/brianreavis/selectize.js/blob/master/docs/usage.md#search).
return function onScore(item) {
if (ignore) {
//If 0, the option is declared not a match.
return 0;
} else {
var result = score(item);
return result;
}
};
},
Hope that helps :)
There is a working example in the docs. See the "Remote Source — Rotten Tomatoes" example. I adapted to something like this:
load: function(query, callback) {
if (!query || query.length < 3) return callback(); // <- this line
$.ajax({
// ajax options...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With