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

Commit

Permalink
fix(tagging multiple): hide tagging item if null returned
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Mar 29, 2016
1 parent 2b4a9ea commit 2f14045
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/uiSelectMultipleDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
});
return;
}
newItem.isTag = true;
if (newItem) newItem.isTag = true;
// handle newItem string and stripping dupes in tagging string context
} else {
// find any tagging items already in the $select.items array and store them
Expand Down Expand Up @@ -369,7 +369,7 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
items = items.slice(dupeIndex+1,items.length-1);
} else {
items = [];
items.push(newItem);
if (newItem) items.push(newItem);
items = items.concat(stashArr);
}
scope.$evalAsync( function () {
Expand Down
28 changes: 27 additions & 1 deletion test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ describe('ui-select tests', function() {
var el = createUiSelect({tagging: 'taggingFunc'});
clickMatch(el);

$(el).scope().$select.search = 'idontexist';
showChoicesForSearch(el, 'idontexist');
$(el).scope().$select.activeIndex = 0;
$(el).scope().$select.select('idontexist');

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

it('should allow decline tags when tagging function returns null in multiple select mode', function() {
scope.taggingFunc = function (name) {
if (name == 'idontexist') return null;
return {
name: name,
email: name + '@email.com',
group: 'Foo',
age: 12
};
};

var el = createUiSelectMultiple({tagging: 'taggingFunc'});

showChoicesForSearch(el, 'amalie');
expect(el.find('.ui-select-choices-row-inner').size()).toBe(2);
expect(el.scope().$select.items[0]).toEqual(jasmine.objectContaining({name: 'amalie', isTag: true}));
expect(el.scope().$select.items[1]).toEqual(jasmine.objectContaining({name: 'Amalie'}));

showChoicesForSearch(el, 'idoexist');
expect(el.find('.ui-select-choices-row-inner').size()).toBe(1);
expect(el.find('.ui-select-choices-row-inner').is(':contains(idoexist@email.com)')).toBeTruthy();

showChoicesForSearch(el, 'idontexist');
expect(el.find('.ui-select-choices-row-inner').size()).toBe(0);
});

it('should allow paste tag from clipboard', function() {
scope.taggingFunc = function (name) {
return {
Expand Down

0 comments on commit 2f14045

Please sign in to comment.