bootstrap-tags
bootstrap-tags copied to clipboard
Remove all tags/Reinitialize
How can we remove all tags from the input box?
The library itself doesn't support it. Is the use case that a user would want to clear all the tags at once?
You could clear them all with something like (nb: there may be syntax errors here):
var tagger = $('.tags').getTags();
var currentTags = tagger.getTags();
var i;
for (i = 0; i < currentTags.length; i++) {
tagger. removeTag(currentTags[i]);
}
I had the same problem, then I created a tricky solution: $('#div-input-tag-holder').html('<input type=text id=tags'); So I rewrite input elemnt into its div holder.
couldn't find destroy method which is needed for SPA applications for cleaning resources... are you planning to add it?
@maxwells I second this request. This seems like a basic requirement. The code that you provide only removes all tags up to the last one. Why doesn't it also remove the last tag as well? Why do you have a removeTag function and a removeLastTag? Couldn't you take this loop and stick it in a new function called removeTags()?
I have tried some workaround for this it works for me pefectly. var tagData = $("#small").tags().tagData; if (tagData.length > 0) { $.each( tagData, function( index, value ){ for(var tItem=0 ; tItem < tagData.length;) { $("#small").tags().removeTag(tagData[tItem]); } }); }