From 464602fd53d85f6ccb35d2c526c343af1028ea1f Mon Sep 17 00:00:00 2001 From: Houssam Haidar Date: Fri, 12 Dec 2014 17:59:50 -0500 Subject: [PATCH 1/2] Fix selector issue that caused typeahead.js to not work --- tagmanager.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tagmanager.js b/tagmanager.js index 03e7ce6..e954185 100644 --- a/tagmanager.js +++ b/tagmanager.js @@ -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); From 8cb81372ff3eae8c9e2db40574da89e3486417ed Mon Sep 17 00:00:00 2001 From: Houssam Haidar Date: Tue, 27 Jan 2015 11:29:15 -0500 Subject: [PATCH 2/2] Make prefilled tags not go through validation This prevents the plugin from breaking if existing tags do not comply. --- tagmanager.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tagmanager.js b/tagmanager.js index e954185..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; } @@ -310,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); } }); },