dragonofmercy / Tokenize2

Tokenize2 is a plugin which allows your users to select multiple items from a predefined list or ajax, using autocompletion as they type to find each item. You may have seen a similar type of text entry when filling in the recipients field sending messages on facebook or tags on tumblr.
https://dragonofmercy.github.io/Tokenize2/
BSD 3-Clause "New" or "Revised" License
83 stars 25 forks source link

Select event fired multiple times on focus #48

Closed georges49 closed 6 years ago

georges49 commented 6 years ago

I attached a fiddle to illustrate the issue

https://jsfiddle.net/rxusrdhn/8/

I just tried to console log a value in the select event. When I click on the input and it has focus, the log is shown twice which means that the code I write (in my real use case) will be executed two times. Sometimes it is executed 3 times instead of 2 as well.

tommykamkcm commented 6 years ago

Hi @georges49 @zellerda

I probably found a workaround on this issue: making use of lodash's debounce function, here is the sample code $('.tokenize2') .on('tokenize:select', _.debounce((e) => { console.log('tokenize:select'); }, 100)) .tokenize2();

See if it works in your case. Cheers!

dragonofmercy commented 6 years ago

Try with the last commit and use tokenize:focus instead of tokenize:select