bootstrap-tags icon indicating copy to clipboard operation
bootstrap-tags copied to clipboard

Remove all tags/Reinitialize

Open karan173 opened this issue 10 years ago • 5 comments

How can we remove all tags from the input box?

karan173 avatar Mar 23 '14 16:03 karan173

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]);
}

maxwells avatar Mar 23 '14 20:03 maxwells

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.

hosseinimh avatar Feb 11 '15 16:02 hosseinimh

couldn't find destroy method which is needed for SPA applications for cleaning resources... are you planning to add it?

deedarb avatar Feb 17 '15 12:02 deedarb

@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()?

havok2063 avatar May 05 '15 16:05 havok2063

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]); } }); }

nikulchauhan avatar Sep 28 '17 08:09 nikulchauhan