Tagify, accept only few chars

173 views Asked by At

I would like Tagify to only accept certain characters if they don't belong to a tag. [e.g. #,@,(,)].

In addition to the tags, there can only be the characters "(" and ")".

I tried this:

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

});

But, using the 'input' event, the character has already been written to the input. I tried using 'change' but it doesn't work at all.

Some idea?

0

There are 0 answers