itemAdded issue Bootstrap tags

To the current project I am working on I had to add this functionliaty, and let the users add their owns tags when they need. All the implementation of this plugin was a success I implemented the itemAdded event too, but when I tested the predefined tags I saw this event is triggered even if the tag is predefined. So I started to search on google for other plugins but in the end I come back to this plguin and I tried to fix it. 

After an hour of searches on google I found the solution on github and I made a print screen. In the following I will put the image to see what you should add on the bootstrap main file script, and the code to just copy and paste the new lines of code.

penguin arts bootstrap tag input

 

 

And the code is below:

    * Constructor function
    */
   function TagsInput(element, options) {
+    this.isInit = true;
     this.itemsArray = [];
 
     this.$element = $(element);
@@ -50,6 +51,7 @@
     this.$element.before(this.$container);
 
     this.build(options);
+    this.isInit = false;
   }
 
   TagsInput.prototype = {
@@ -157,7 +159,11 @@
       if (self.options.maxTags === self.itemsArray.length || self.items().toString().length === self.options.maxInputLength)
         self.$container.addClass('bootstrap-tagsinput-max');
 
-      self.$element.trigger($.Event('itemAdded', { item: item, options: options }));
+      if (this.isInit) {
+        self.$element.trigger($.Event('itemAddedOnInit', { item: item, options: options }));
+      } else {
+        self.$element.trigger($.Event('itemAdded', { item: item, options: options }));
+      }
     },
 
     /**

 

The file that should be change is: bootstrap-tagsinput.js

I hope this will help you.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x