Skip to content

Commit

Permalink
add removeTagByName
Browse files Browse the repository at this point in the history
  • Loading branch information
aehlke committed Nov 23, 2012
1 parent 98d0536 commit f39adfa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ Adds new tag to the list. The `additionalClass` parameter is an optional way to

$("#mytags").tagit("createTag", "brand-new-tag");

### removeTagByName(tagName, animate)
Finds the tag with the value `tagName` and removes it. If no such tag is found, it'll throw an exception.

$("#mytags").tagit("removeTagByName", "my-tag");

### removeAll()
Clears the widget of all tags -- removes each tag it contains, so the onTagRemoved event callback (if set in the options) will be called for each.

Expand Down
1 change: 1 addition & 0 deletions examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ <h3>Methods</h3>
<p>Demos the available widget methods. Click the links below the widget to try them.</p>
<ul id="methodTags"></ul>
<p><a href="#" onclick="var inp=prompt('Enter a tag value to test the createTag method.');$('#methodTags').tagit('createTag', inp);return false;">Create tag</a></p>
<p><a href="#" onclick="var inp=prompt('Enter a tag value to test the removeTagByName method.');$('#methodTags').tagit('removeTagByName', inp);return false;">Remove tag by name</a></p>
<p><a href="#" onclick="$('#methodTags').tagit('removeAll');return false;">Clear tags</a></p>
<input type="submit" value="Submit">
</form>
Expand Down
8 changes: 8 additions & 0 deletions js/tag-it.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@
}
},

removeTagByName: function(tagName, animate) {
var toRemove = this._tags().find("input[value='" + tagName + "']").closest('.tagit-choice');
if (toRemove.length === 0) {
throw "No such tag exists with the name '" + tagName + "'";
}
this.removeTag(toRemove, animate);
},

removeAll: function() {
// Removes all tags.
var that = this;
Expand Down
3 changes: 2 additions & 1 deletion js/tag-it.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f39adfa

Please sign in to comment.