javascriptjquerytokenize2

In Tokenize2, can I use the same token multiple times?


In Tokenize2, is there any way to add the same token/text multiple times.

I have implemented it, and when I type the first time e.g "Hello" it add in the box, next time if I type "Hello" again and try to add, it just clears the text. So adding the same text as the token is not possible for me.

Is there any way to achieve this?


Solution

  • Directly it is not possible but we can achieve it. Basically, we need to change the key text for the same value text.

        var sameText = 'sameText'; 
        var separatorValue = sameText;
        
        var i = 1;
        while ($('#takenSelect option[value="' + separatorValue + '"]').length) {
            separatorValue = i + 'RRR_' + sameText;
            i++;
        }
    
        $('.tokenize-demo').tokenize2().trigger('tokenize:tokens:add', [separatorValue, sameText, true]);
    

    After using this code, if we will use 'hi' text again and again the the key will look like

    1RRR_hi 2RRR_hi 3RRR_hi ..

    and on UI the user can see 'hi' text multiple times.