1

I have $('input').on('itemAdded', function (event) event from bootstrap tagsInput.js library. I am listening on event to add an item to array but the problem is that “self.update()” is called twice adding duplicate items to array.

if I put the event outside mount/update, then it is not fired at all.

I have my code like this:

self.on(“update”, function() {
   $('input').on('itemAdded', function (event) {
   console.log("ITEM ADDED"); // called twice here
   self.parent.data.ivrList[event.currentTarget.id].agentList.push(self.data.MapAgents[event.item]); 
});

According to API, it say “In the function this refers to the current tag instance. After the handler is called this.update() is automatically called reflecting all the possible changes to the UI”. I am not sure if this statement refers to my problem above.

How do I fix this?

kittu
  • 6,662
  • 21
  • 91
  • 185
  • I created a similar plugin using riot tags https://github.com/vitogit/riot_tag_input maybe it could be useful. Could you create a plunker (http://riotjs.com/examples/plunker/?app=bug-reporter) with your problem? Also remember that there are other events to listen like 'updated' http://riotjs.com/api/#events – vitomd Oct 27 '16 at 17:29
  • @vitmod I know the tag life cycle events but why does it have to be inside those events. Can't I have my own events out side mount or update or updated etc?? – kittu Oct 27 '16 at 18:18
  • Yes I don't know if that's the best place to add the function, but I would need to see a code sample to know how to handle, I'm not familiar with that tag plugin – vitomd Oct 28 '16 at 01:05

0 Answers0