How to limit the minimum character when choosing tags

I want to limit at least 3 characters for inputting Selectize tags. Is it possible? is there any event when choosing?

+6
source share
2 answers

I had the same problem. Its, as Rory said, through plugins.

This is actually quite simple.

In the official example, to filter the minimum tag length, you can find here

$('#select-words-length').selectize({ create: true, createFilter: function(input) { return input.length >= MIN_LENGTH; } }); 

Another thing 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 :)

+6
source
  • Download the selectize.js plugin

  • Enable jquery and

Use this code, it will work.

$ ('# your-id'). Selectize ({maxItems: 3});

-6
source

All Articles