Overview

Tokenize2 is event based, all major calls are triggered through events.

Usage

In the example below, we catch tokenize:dropdown:itemAdd event to print in the console the value of the item inserted in the dropdown.

$('.tokenize-demo').on('tokenize:dropdown:itemAdd', function(e, value){
    console.log(value);
});

The first agrument e is never used but has to be writed in the code.

If you want to add a token in Tokenize2, you have to use the event system as the example below.

$('.tokenize-demo').tokenize2().trigger('tokenize:tokens:add', ['token value', 'token display text', true]);

Note that the third argument must be set to true if tokensAllowCustom is set to false.

Events

Below the list of all events used by Tokenize2.

Events Arguments Description
tokenize:load none Fired on Tokenize2 initialization
tokenize:clear none Fired when clear tokens
tokenize:remap none Fired when Tokenize2 match the select with tokens
tokenize:focus none Fired when focus
tokenize:deselect none Fired when blur
tokenize:search [string] Fired when search
tokenize:paste none Fired when paste a text in search input
tokenize:clear none Fired when clear tokens
tokenize:dropdown:up none Fired when type up in dropdown
tokenize:dropdown:down none Fired when type down in dropdown
tokenize:dropdown:clear none Fired when dropdown items are cleared
tokenize:dropdown:show none Fired when dropdown show
tokenize:dropdown:hide none Fired when dropdown hide
tokenize:dropdown:fill [array of object] Fired when dropdown items are added
tokenize:dropdown:itemAdd [object] Fired when dropdown item is added
tokenize:keypress [event] Fired when keypress
tokenize:keydown [event] Fired when keydown
tokenize:keyup [event] Fired when keyup
tokenize:tokens:reorder none Fired when tokens are reordered
tokenize:tokens:add [string, string, boolean] Fired before token is added
tokenize:tokens:added [string, string] Fired when token is added
tokenize:tokens:remove [string] Fired when token is removed