Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix beforeTagAdded callback timing for singleField

  • Loading branch information...
commit d5fe008090b03a9a40dd2e1c8a257ddb69cad3b3 1 parent 5ba933a
@aehlke authored
Showing with 14 additions and 12 deletions.
  1. +10 −8 js/tag-it.js
  2. +4 −4 js/tag-it.min.js
View
18 js/tag-it.js
@@ -427,18 +427,11 @@
}
// Unless options.singleField is set, each tag has a hidden input field inline.
- if (this.options.singleField) {
- var tags = this.assignedTags();
- tags.push(value);
- this._updateSingleTagsField(tags);
- } else {
+ if (!this.options.singleField) {
var escapedValue = label.html();
tag.append('<input type="hidden" style="display:none;" value="' + escapedValue + '" name="' + this.options.fieldName + '" />');
}
- // DEPRECATED.
- this._trigger('onTagAdded', null, tag);
-
if (this._trigger('beforeTagAdded', null, {
tag: tag,
tagLabel: this.tagLabel(tag),
@@ -447,6 +440,15 @@
return;
}
+ if (this.options.singleField) {
+ var tags = this.assignedTags();
+ tags.push(value);
+ this._updateSingleTagsField(tags);
+ }
+
+ // DEPRECATED.
+ this._trigger('onTagAdded', null, tag);
+
this.tagInput.val('');
// Insert tag.
View
8 js/tag-it.min.js
@@ -9,7 +9,7 @@ return!1}},b.extend(d,this.options.autocomplete),d.source=this.options.tagSource
assignedTags:function(){var a=this,c=[];this.options.singleField?(c=b(this.options.singleFieldNode).val().split(this.options.singleFieldDelimiter),""===c[0]&&(c=[])):this._tags().each(function(){c.push(a.tagLabel(this))});return c},_updateSingleTagsField:function(a){b(this.options.singleFieldNode).val(a.join(this.options.singleFieldDelimiter)).trigger("change")},_subtractArray:function(a,c){for(var d=[],e=0;e<a.length;e++)-1==b.inArray(a[e],c)&&d.push(a[e]);return d},tagLabel:function(a){return this.options.singleField?
b(a).find(".tagit-label:first").text():b(a).find("input:first").val()},_showAutocomplete:function(){this.tagInput.autocomplete("search","")},_findTagByLabel:function(a){var c=this,d=null;this._tags().each(function(){if(c._formatStr(a)==c._formatStr(c.tagLabel(this)))return d=b(this),!1});return d},_isNew:function(a){return!this._findTagByLabel(a)},_formatStr:function(a){return this.options.caseSensitive?a:b.trim(a.toLowerCase())},_effectExists:function(a){return Boolean(b.effects&&(b.effects[a]||
b.effects.effect&&b.effects.effect[a]))},createTag:function(a,c,d){var e=this,a=b.trim(a);if(""===a)return!1;if(!this.allowDuplicates&&!this._isNew(a))return a=this._findTagByLabel(a),!1!==this._trigger("onTagExists",null,{existingTag:a,duringInitialization:d})&&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(c).append(g);
-this.options.readOnly?f.addClass("tagit-choice-read-only"):(f.addClass("tagit-choice-editable"),c=b("<span></span>").addClass("ui-icon ui-icon-close"),c=b('<a><span class="text-icon">\u00d7</span></a>').addClass("tagit-close").append(c).click(function(){e.removeTag(f)}),f.append(c));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.fieldName+'" />'));this._trigger("onTagAdded",
-null,f);!1!==this._trigger("beforeTagAdded",null,{tag:f,tagLabel:this.tagLabel(f),duringInitialization:d})&&(this.tagInput.val(""),this.tagInput.parent().before(f),this._trigger("afterTagAdded",null,{tag:f,tagLabel:this.tagLabel(f),duringInitialization:d}),this.options.showAutocompleteOnFocus&&!d&&setTimeout(function(){e._showAutocomplete()},0))},removeTag:function(a,c){c="undefined"===typeof c?this.options.animate:c;a=b(a);this._trigger("onTagRemoved",null,a);if(!1!==this._trigger("beforeTagRemoved",
-null,{tag:a,tagLabel:this.tagLabel(a)})){if(this.options.singleField){var d=this.assignedTags(),e=this.tagLabel(a),d=b.grep(d,function(a){return a!=e});this._updateSingleTagsField(d)}c?(a.addClass("removed"),d=this._effectExists("blind")?["blind",{direction:"horizontal"},"fast"]:["fast"],d.push(function(){a.remove()}),a.fadeOut("fast").hide.apply(a,d).dequeue()):a.remove();this._trigger("afterTagRemoved",null,{tag:a,tagLabel:this.tagLabel(a)})}},removeTagByLabel:function(a,b){var d=this._findTagByLabel(a);
-if(!d)throw"No such tag exists with the name '"+a+"'";this.removeTag(d,b)},removeAll:function(){var a=this;this._tags().each(function(b,d){a.removeTag(d,!1)})}})})(jQuery);
+this.options.readOnly?f.addClass("tagit-choice-read-only"):(f.addClass("tagit-choice-editable"),c=b("<span></span>").addClass("ui-icon ui-icon-close"),c=b('<a><span class="text-icon">\u00d7</span></a>').addClass("tagit-close").append(c).click(function(){e.removeTag(f)}),f.append(c));this.options.singleField||(g=g.html(),f.append('<input type="hidden" style="display:none;" value="'+g+'" name="'+this.options.fieldName+'" />'));!1!==this._trigger("beforeTagAdded",null,{tag:f,tagLabel:this.tagLabel(f),
+duringInitialization:d})&&(this.options.singleField&&(g=this.assignedTags(),g.push(a),this._updateSingleTagsField(g)),this._trigger("onTagAdded",null,f),this.tagInput.val(""),this.tagInput.parent().before(f),this._trigger("afterTagAdded",null,{tag:f,tagLabel:this.tagLabel(f),duringInitialization:d}),this.options.showAutocompleteOnFocus&&!d&&setTimeout(function(){e._showAutocomplete()},0))},removeTag:function(a,c){c="undefined"===typeof c?this.options.animate:c;a=b(a);this._trigger("onTagRemoved",
+null,a);if(!1!==this._trigger("beforeTagRemoved",null,{tag:a,tagLabel:this.tagLabel(a)})){if(this.options.singleField){var d=this.assignedTags(),e=this.tagLabel(a),d=b.grep(d,function(a){return a!=e});this._updateSingleTagsField(d)}c?(a.addClass("removed"),d=this._effectExists("blind")?["blind",{direction:"horizontal"},"fast"]:["fast"],d.push(function(){a.remove()}),a.fadeOut("fast").hide.apply(a,d).dequeue()):a.remove();this._trigger("afterTagRemoved",null,{tag:a,tagLabel:this.tagLabel(a)})}},removeTagByLabel:function(a,
+b){var d=this._findTagByLabel(a);if(!d)throw"No such tag exists with the name '"+a+"'";this.removeTag(d,b)},removeAll:function(){var a=this;this._tags().each(function(b,d){a.removeTag(d,!1)})}})})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.