2015-07-01 57 views
6

我想限制選擇標籤輸入的最少3個字符數。可能嗎?選舉中是否有任何事件?如何限制選擇標籤中的最小字符數

+0

搜索本身

//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; } }; }, 

希望[documentation](https://github.com/brianreavis/selectize.js/blob/master/docs/usage.md)似乎沒有任何設置允許您修改此行爲。 –

+0

但是,Rory可以用其他方式。 – Faizan

+0

一切皆有可能。你可能需要創建你自己的[插件](https://github.com/brianreavis/selectize.js/blob/master/docs/plugins.md)來實現它。 –

回答

-6
  1. 下載selectize.js插件

  2. 包括jQuery和

使用此代碼,它將工作。

$('#your-id')。selectize({ maxItems:3 });

+0

字符,而不是項目 – Andrey

+0

沒有直接選擇API。 –

6

我有同樣的問題。 正如羅裏所說,通過插件。

其實很簡單。

的標籤最小字長過濾官方的例子中,你可以找到here

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

另一件事,你能做的就是過濾幫助:)

+0

btw爲什麼命名匿名函數? – tom10271

+1

一個匿名函數沒有名字。 'onScore'函數有一個名字(所以它不是匿名的)有助於理解正在做什麼。也許這個名字可能更準確,但是當你在調試的時候,你會看到棧跟蹤中的名字,這比查看這麼多的匿名函數更好。 –

+0

哦....好吧......我從來沒有這樣做過,認爲它不是很有用,對象鍵已經提供了足夠的提示。隨你 – tom10271

相關問題