本文介绍了如何限制选择标签中的最小字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要限制选择标签"输入的最少3个字符.是否有可能? select中有任何事件吗?

I want to limit minimum 3 characters for Selectize tags input. Is it possible? is there any event in selectize?

推荐答案

我遇到了同样的问题.正如Rory所说的那样,它是通过插件实现的.

I had the same problem.Its as Rory has mentioned, via plugins.

它实际上很简单.

您可以找到这里

$('#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;
        }
    };
},

希望有帮助:)

这篇关于如何限制选择标签中的最小字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 12:08