Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added support for singleField option when using removeTagByName

  • Loading branch information...
commit e7f70ef17743557eb92a6f4670ee5231af8ec534 1 parent 32af28b
Marconi Moreto authored
Showing with 9 additions and 3 deletions.
  1. +7 −1 js/tag-it.js
  2. +2 −2 js/tag-it.min.js
View
8 js/tag-it.js
@@ -493,7 +493,13 @@
},
removeTagByName: function(tagName, animate) {
- var toRemove = this._tags().find("input[value='" + tagName + "']").closest('.tagit-choice');
+ var toRemove = [];
+ if (this.options.singleField) {
+ existingTags = $(this.options.singleFieldNode).val().split(",");
+ toRemove = this._tags().find("span.tagit-label:contains('" + tagName + "')").closest('.tagit-choice');
+ } else {
+ toRemove = this._tags().find("input[value='" + tagName + "']").closest('.tagit-choice');
+ }
if (toRemove.length === 0) {
throw "No such tag exists with the name '" + tagName + "'";
}
View
4 js/tag-it.min.js
@@ -11,5 +11,5 @@ b(a).children("input").val()},_showAutocomplete:function(){this.tagInput.autocom
d,c){var e=this,a=b.trim(a);if(""===a)return!1;if(!this.allowDuplicates&&!this._isNew(a))return a=this._existingTag(a),!1!==this._trigger("onTagExists",null,{existingTag:a,duringInitialization:c})&&this._effectExists("highlight")&&a.effect("highlight"),!1;var g=b(this.options.onTagClicked?'<a class="tagit-label"></a>':'<span class="tagit-label"></span>').text(a),f=b("<li></li>").addClass("tagit-choice ui-widget-content ui-state-default ui-corner-all").addClass(d).append(g);this.options.readOnly?f.addClass("tagit-choice-read-only"):
(f.addClass("tagit-choice-editable"),d=b("<span></span>").addClass("ui-icon ui-icon-close"),d=b('<a><span class="text-icon">\u00d7</span></a>').addClass("tagit-close").append(d).click(function(){e.removeTag(f)}),f.append(d));this.options.singleField?(g=this.assignedTags(),g.push(a),this._updateSingleTagsField(g)):(a=g.html(),f.append('<input type="hidden" style="display:none;" value="'+a+'" name="'+this.options.itemName+"["+this.options.fieldName+'][]" />'));this._trigger("onTagAdded",null,f);!1!==
this._trigger("beforeTagAdded",null,{tag:f,duringInitialization:c})&&(this.tagInput.val(""),this.tagInput.parent().before(f),this._trigger("afterTagAdded",null,{tag:f,duringInitialization:c}),this.options.showAutocompleteOnFocus&&!c&&setTimeout(function(){e._showAutocomplete()},0))},removeTag:function(a,d){d="undefined"===typeof d?this.options.animate:d;a=b(a);this._trigger("onTagRemoved",null,a);if(!1!==this._trigger("beforeTagRemoved",null,{tag:a})){if(this.options.singleField){var c=this.assignedTags(),
-e=this.tagLabel(a),c=b.grep(c,function(a){return a!=e});this._updateSingleTagsField(c)}d?(a.addClass("removed"),c=this._effectExists("blind")?["blind",{direction:"horizontal"},"fast"]:["fast"],c.push(function(){a.remove()}),a.fadeOut("fast").hide.apply(a,c).dequeue()):a.remove();this._trigger("afterTagRemoved",null,{tag:a})}},removeTagByName:function(a,b){var c=this._tags().find("input[value='"+a+"']").closest(".tagit-choice");if(0===c.length)throw"No such tag exists with the name '"+a+"'";this.removeTag(c,
-b)},removeAll:function(){var a=this;this._tags().each(function(b,c){a.removeTag(c,!1)})}})})(jQuery);
+e=this.tagLabel(a),c=b.grep(c,function(a){return a!=e});this._updateSingleTagsField(c)}d?(a.addClass("removed"),c=this._effectExists("blind")?["blind",{direction:"horizontal"},"fast"]:["fast"],c.push(function(){a.remove()}),a.fadeOut("fast").hide.apply(a,c).dequeue()):a.remove();this._trigger("afterTagRemoved",null,{tag:a})}},removeTagByName:function(a,d){var c=[];this.options.singleField?(existingTags=b(this.options.singleFieldNode).val().split(","),c=this._tags().find("span.tagit-label:contains('"+
+a+"')").closest(".tagit-choice")):c=this._tags().find("input[value='"+a+"']").closest(".tagit-choice");if(0===c.length)throw"No such tag exists with the name '"+a+"'";this.removeTag(c,d)},removeAll:function(){var a=this;this._tags().each(function(b,c){a.removeTag(c,!1)})}})})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.