Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions dist/js/bootstrap-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
this.caseInsensitive || (this.caseInsensitive = false);
this.readOnlyEmptyMessage || (this.readOnlyEmptyMessage = "No tags to display...");
this.maxNumTags || (this.maxNumTags = -1);
this.allowDuplicates || (this.allowDuplicates = false);
this.beforeAddingTag || (this.beforeAddingTag = function(tag) {});
this.afterAddingTag || (this.afterAddingTag = function(tag) {});
this.beforeDeletingTag || (this.beforeDeletingTag = function(tag) {});
Expand Down Expand Up @@ -98,11 +99,13 @@
};
};
this.hasTag = function(tag) {
return _this.tagsArray.indexOf(tag) > -1;
if (!_this.allowDuplicates) {
return _this.tagsArray.indexOf(tag) > -1;
}
};
this.removeTagClicked = function(e) {
if (e.currentTarget.tagName === "A") {
_this.removeTag($("span", e.currentTarget.parentElement).html());
_this.removeTag($("span", e.currentTarget.parentElement).text());
$(e.currentTarget.parentNode).remove();
}
return _this;
Expand Down Expand Up @@ -190,7 +193,7 @@
e.preventDefault();
_this.pressedReturn(e);
tag = e.target.value;
if (_this.suggestedIndex !== -1) {
if (_this.suggestedIndex != null && _this.suggestedIndex !== -1) {
tag = _this.suggestionList[_this.suggestedIndex];
}
_this.addTag(tag);
Expand Down Expand Up @@ -253,8 +256,10 @@
$.each(this.suggestions, function(i, suggestion) {
var suggestionVal;
suggestionVal = _this.caseInsensitive ? suggestion.substring(0, str.length).toLowerCase() : suggestion.substring(0, str.length);
if (_this.tagsArray.indexOf(suggestion) < 0 && suggestionVal === str && (str.length > 0 || overrideLengthCheck)) {
return _this.suggestionList.push(suggestion);
if (_this.allowDuplicates || _this.tagsArray.indexOf(suggestion) < 0) {
if (suggestionVal === str && (str.length > 0 || overrideLengthCheck)) {
return _this.suggestionList.push(suggestion);
}
}
});
return this.suggestionList;
Expand Down
8 changes: 5 additions & 3 deletions src/bootstrap-tags.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jQuery ->
@caseInsensitive ||= false
@readOnlyEmptyMessage ||= 'No tags to display...'
@maxNumTags ||= -1
@allowDuplicates ||= false

# callbacks
@beforeAddingTag ||= (tag) ->
Expand Down Expand Up @@ -86,7 +87,7 @@ jQuery ->
tag: @tagsArray[index], content: @popoverArray[index]

@hasTag = (tag) =>
@tagsArray.indexOf(tag) > -1
if !@allowDuplicates then @tagsArray.indexOf(tag) > -1

####################
# add/remove methods
Expand Down Expand Up @@ -221,8 +222,9 @@ jQuery ->
str = str.toLowerCase() if @caseInsensitive
$.each @suggestions, (i, suggestion) =>
suggestionVal = if @caseInsensitive then suggestion.substring(0, str.length).toLowerCase() else suggestion.substring(0, str.length)
if @tagsArray.indexOf(suggestion) < 0 and suggestionVal == str and (str.length > 0 or overrideLengthCheck)
@suggestionList.push suggestion
if @allowDuplicates or @tagsArray.indexOf(suggestion) < 0
if suggestionVal == str and (str.length > 0 or overrideLengthCheck)
@suggestionList.push suggestion
@suggestionList

# makeSuggestions creates auto suggestions that match the value in the input
Expand Down