Tagify,只接受几个字符

问题描述 投票:0回答:0

我希望 Tagify 只接受某些不属于标签的字符。 [例如。 #,@,(,)].

除了标签,只能有字符“(”和“)”。

我试过这个:

var input = document.querySelector('input'),
    tagify = new Tagify(input, {
        mode: 'mix', //i would use Tagify in mixed mode.
        pattern: /@|#/, //this is my trigger-chars for invoke ajax calls
        trim: true
    });

tagify.on('input', function(event) {
    const allowedChars = ['(',')'];
    const value = e.detail.textContent;

    if (!allowedChars.includes(value)) {
        console.log("exit")
        return false;
    }

    // other code

});

但是,使用“输入”事件,字符已经被写入输入。 我尝试使用“更改”,但它根本不起作用。

一些想法?

javascript tags autosuggest tagify
© www.soinside.com 2019 - 2024. All rights reserved.