Skip to content

Commit

Permalink
added remove all tags function "removeAllTags()" this will resolve th…
Browse files Browse the repository at this point in the history
…e issue "Remove all tags/Reinitialize maxwells#31" Can be view in demo3.html
  • Loading branch information
iamsalmanafzal committed Apr 27, 2017
1 parent 5e82a9c commit 9ca61e6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ function | return type | description
`addTag(tag:string)` | `Tagger` | add a tag
`renameTag(tag:string, newTag:string)` | `Tagger` | rename one tag to another value
`removeLastTag()` | `Tagger` | removes last tag if it exists
`removeAllTags()` | `Tagger` | removes all tags
`removeTag(tag:string)` | `Tagger` | removes tag specified by string if it exists
`addTagWithContent(tag:string, popoverContent:string)` | `Tagger` | Add a tag with associated popover content
`setPopover(tag:string, popoverContent:string)` | `Tagger` | update a tag's associated popover content, if that tag exists
Expand Down
2 changes: 1 addition & 1 deletion demo-3.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h3>Bootstrap 3.0.3</h3>
});

$('#removeAllTags').click(function(){
newTagsInialized.smallTags.removeAllTag();
newTagsInialized.smallTags.removeAllTags();
});
});
</script>
Expand Down
9 changes: 4 additions & 5 deletions dist/js/bootstrap-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
};
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 All @@ -116,9 +116,8 @@
}
return _this;
};
this.removeAllTag = function() {
this.removeAllTags = function() {
if (_this.tagsArray.length > 0) {
var arrayLength = _this.tagsArray.length
_this.tagsArray = [];
_this.renderTags();
if (_this.canAddByMaxNum()) {
Expand Down Expand Up @@ -201,7 +200,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 @@ -458,7 +457,7 @@
this.removeTag = function() {};
this.removeTagClicked = function() {};
this.removeLastTag = function() {};
this.removeAllTag = function() {};
this.removeAllTags = function() {};
this.addTag = function() {};
this.addTagWithContent = function() {};
this.renameTag = function() {};
Expand Down
2 changes: 1 addition & 1 deletion dist/js/bootstrap-tags.min.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions spec/bootstrap-tags-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@
});
});
});
describe("when the enter key is pressed before any text is entered", function() {
beforeEach(function() {
this.tags = newTagger("tagger2", {});
return $('#tagger2 .tags-input').trigger($.Event('keydown', {
which: 13
}));
});
return it("does not add any tags", function() {
return expect(this.tags.getTags()).toEqual([]);
});
});
return describe("when normally operating", function() {
beforeEach(function() {
this.initTagData = ['one', 'two', 'three'];
Expand Down
9 changes: 9 additions & 0 deletions src/bootstrap-tags.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ jQuery ->
@enableInput() if @canAddByMaxNum()
@

# removeAllTags removes All tags.
@removeAllTags = =>
if @tagsArray.length > 0
@tagsArray = []
@renderTags()
@enableInput() if @canAddByMaxNum()
@

# removeTag removes specified tag.
# - Helper method for removeTagClicked and removeLast Tag
# - also an exposed method (can be called from page javascript)
Expand Down Expand Up @@ -404,6 +412,7 @@ jQuery ->
@removeTag = ->
@removeTagClicked = ->
@removeLastTag = ->
@removeAllTags = ->
@addTag = ->
@addTagWithContent = ->
@renameTag = ->
Expand Down

0 comments on commit 9ca61e6

Please sign in to comment.