Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 6126585

Browse files
author
Brian Feister
committed
Merge pull request #504 from brianfeister/master
Fix for #477
2 parents 445fdd9 + 451050d commit 6126585

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/select.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,13 @@
403403
// ctrl.tagging pushes items to ctrl.items, so we only have empty val
404404
// for `item` if it is a detected duplicate
405405
if ( item === undefined ) return;
406-
// create new item on the fly
407-
item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : item.replace(ctrl.taggingLabel,'').trim();
406+
// create new item on the fly if we don't already have one;
407+
// use tagging function if we have one, otherwise, push a string
408+
if ( ctrl.tagging.fct !== undefined && item === undefined ) {
409+
item = ctrl.tagging.fct(ctrl.search);
410+
} else if ( typeof item === 'string' ) {
411+
item = item.replace(ctrl.taggingLabel,'');
412+
}
408413
}
409414
}
410415
// search ctrl.selected for dupes potentially caused by tagging and return early if found
@@ -455,9 +460,9 @@
455460
// Toggle dropdown
456461
ctrl.toggle = function(e) {
457462
if (ctrl.open) {
458-
ctrl.close();
463+
ctrl.close();
459464
e.preventDefault();
460-
e.stopPropagation();
465+
e.stopPropagation();
461466
} else {
462467
ctrl.activate();
463468
}
@@ -646,7 +651,7 @@
646651
}
647652
if ( tagged ) {
648653
$timeout(function() {
649-
_searchInput.triggerHandler('tagged', ctrl.items);
654+
_searchInput.triggerHandler('tagged');
650655
var newItem = ctrl.search.replace(KEY.MAP[e.keyCode],'').trim();
651656
if ( ctrl.tagging.fct ) {
652657
newItem = ctrl.tagging.fct( newItem );

0 commit comments

Comments
 (0)