javascriptjquerytokenize2

How to clear Tokenize2 input fieds?


Are there anyway to clear the select option in Tokenize2 by using javascript or jquery?

And this is my code.

<select class="select-continent" multiple>
    <option value="Africa">Africa</option>
    <option value="Americas">Americas</option>
    <option value="Asia">Asia</option>
    <option value="Europe">Europe</option>
    <option value="Oceania">Oceania</option>
</select>

$('.select-continent').tokenize2({
    dataSource: 'select'
});

After i select some option as the result. How can i clear all select option in the input field?

enter image description here


Solution

  • Check out the events documentation: https://dragonofmercy.github.io/Tokenize2/events.html

    You can clear by triggering the clear event:

    $('.select-continent').tokenize2().trigger('tokenize:clear')