diff --git a/tagmanager.js b/tagmanager.js index 03e7ce6..21dcf35 100644 --- a/tagmanager.js +++ b/tagmanager.js @@ -47,7 +47,7 @@ }, publicMethods = { - pushTag : function (tag, ignoreEvents, externalTagId) { + pushTag : function (tag, ignoreEvents, externalTagId, ignoreValidator) { var $self = $(this), opts = $self.data('opts'), alreadyInList, tlisLowerCase, max, tagId, tlis = $self.data("tlis"), tlid = $self.data("tlid"), idx, newTagId, newTagRemoveId, escaped, html, $el, lastTagId, lastTagObj; @@ -82,7 +82,7 @@ } // call the validator (if any) and do not let the tag pass if invalid - if (opts.validator && !opts.validator(tag)) { + if (!ignoreValidator && opts.validator && !opts.validator(tag)) { $self.trigger('tm:invalid', tag) return; } @@ -160,7 +160,11 @@ $(opts.tagsContainer).append($el); } else { if (tlid.length > 1) { - lastTagObj = $self.siblings("#" + $self.data("tm_rndid") + "_" + tlid[tlid.length - 2]); + var lastTagObjSelector = "#" + $self.data("tm_rndid") + "_" + tlid[tlid.length - 2]; + // If there's a typeahead, we'll need to go up one element + lastTagObj = $self.siblings(lastTagObjSelector).length > 0 + && $self.siblings(lastTagObjSelector) + || $self.parent().siblings(lastTagObjSelector); lastTagObj.after($el); } else { $self.before($el); @@ -306,9 +310,9 @@ var opts = $self.data('opts') $.each(pta, function (key, val) { if (opts.externalTagId === true) { - publicMethods.pushTag.call($self, val[opts.prefillValueFieldName], true, val[opts.prefillIdFieldName]); + publicMethods.pushTag.call($self, val[opts.prefillValueFieldName], true, val[opts.prefillIdFieldName], true); } else { - publicMethods.pushTag.call($self, val, true); + publicMethods.pushTag.call($self, val, true, false, true); } }); },