Duplicate values gets deleted when removing a tag even when allowDuplicates: true
Opened this issue · 1 comments
jahkey commented
jahkey commented
Traced JS code and found that the reason of the issue is that grep was used to remove all occurrence with the same value.
Fixed issue by adding a few lines in removeTag to find the exact index of which tag is actually being deleted
tag = $(tag);
tag_index = tag.index(); //ADDED TO GET THE INDEX OF THE ITEM BEING DELETED
// DEPRECATED.
this._trigger('onTagRemoved', null, tag);
if (this._trigger('beforeTagRemoved', null, {tag: tag, tagLabel: this.tagLabel(tag)}) === false) {
return;
}
if (this.options.singleField) {
var tags = this.assignedTags();
var removedTagLabel = this.tagLabel(tag);
/*
OLD buggy implementation
tags = $.grep(tags, function(el){
return el != removedTagLabel;
});
*/
tags.splice(tag_index, 1); //ADDED THIS TO REMOVE THE VALUE IN THE CORRECT INDEX
this._updateSingleTagsField(tags);