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

Commit 2f14045

Browse files
committed
fix(tagging multiple): hide tagging item if null returned
1 parent 2b4a9ea commit 2f14045

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/uiSelectMultipleDirective.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
320320
});
321321
return;
322322
}
323-
newItem.isTag = true;
323+
if (newItem) newItem.isTag = true;
324324
// handle newItem string and stripping dupes in tagging string context
325325
} else {
326326
// find any tagging items already in the $select.items array and store them
@@ -369,7 +369,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
369369
items = items.slice(dupeIndex+1,items.length-1);
370370
} else {
371371
items = [];
372-
items.push(newItem);
372+
if (newItem) items.push(newItem);
373373
items = items.concat(stashArr);
374374
}
375375
scope.$evalAsync( function () {

test/select.spec.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ describe('ui-select tests', function() {
567567
var el = createUiSelect({tagging: 'taggingFunc'});
568568
clickMatch(el);
569569

570-
$(el).scope().$select.search = 'idontexist';
570+
showChoicesForSearch(el, 'idontexist');
571571
$(el).scope().$select.activeIndex = 0;
572572
$(el).scope().$select.select('idontexist');
573573

@@ -2231,6 +2231,32 @@ describe('ui-select tests', function() {
22312231
expect(scope.slowTaggingFunc.calls.count()).not.toBe(15);
22322232
});
22332233

2234+
it('should allow decline tags when tagging function returns null in multiple select mode', function() {
2235+
scope.taggingFunc = function (name) {
2236+
if (name == 'idontexist') return null;
2237+
return {
2238+
name: name,
2239+
email: name + '@email.com',
2240+
group: 'Foo',
2241+
age: 12
2242+
};
2243+
};
2244+
2245+
var el = createUiSelectMultiple({tagging: 'taggingFunc'});
2246+
2247+
showChoicesForSearch(el, 'amalie');
2248+
expect(el.find('.ui-select-choices-row-inner').size()).toBe(2);
2249+
expect(el.scope().$select.items[0]).toEqual(jasmine.objectContaining({name: 'amalie', isTag: true}));
2250+
expect(el.scope().$select.items[1]).toEqual(jasmine.objectContaining({name: 'Amalie'}));
2251+
2252+
showChoicesForSearch(el, 'idoexist');
2253+
expect(el.find('.ui-select-choices-row-inner').size()).toBe(1);
2254+
expect(el.find('.ui-select-choices-row-inner').is(':contains(idoexist@email.com)')).toBeTruthy();
2255+
2256+
showChoicesForSearch(el, 'idontexist');
2257+
expect(el.find('.ui-select-choices-row-inner').size()).toBe(0);
2258+
});
2259+
22342260
it('should allow paste tag from clipboard', function() {
22352261
scope.taggingFunc = function (name) {
22362262
return {

0 commit comments

Comments
 (0)