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

Commit

Permalink
Merge pull request #678 from angular-ui/fix-tagging-decline
Browse files Browse the repository at this point in the history
fix(tagging): allow to decline tag creation
  • Loading branch information
dimirc committed Feb 18, 2015
2 parents 86689b9 + 30470f0 commit 246b9e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@
if ( ctrl.taggingLabel === false ) {
if ( ctrl.activeIndex < 0 ) {
item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search;
if ( angular.equals( ctrl.items[0], item ) ) {
if (!item || angular.equals( ctrl.items[0], item ) ) {
return;
}
} else {
Expand All @@ -412,6 +412,7 @@
// use tagging function if we have one
if ( ctrl.tagging.fct !== undefined && typeof item === 'string' ) {
item = ctrl.tagging.fct(ctrl.search);
if (!item) return;
// if item type is 'string', apply the tagging label
} else if ( typeof item === 'string' ) {
// trim the trailing space
Expand Down Expand Up @@ -675,7 +676,7 @@
if ( ctrl.tagging.fct ) {
newItem = ctrl.tagging.fct( newItem );
}
ctrl.select( newItem, true);
if (newItem) ctrl.select(newItem, true);
});
}
}
Expand Down Expand Up @@ -758,6 +759,7 @@
if ( stashArr.filter( function (origItem) { return angular.equals( origItem, ctrl.tagging.fct(ctrl.search) ); } ).length > 0 ) {
return;
}
newItem.isTag = true;
// handle newItem string and stripping dupes in tagging string context
} else {
// find any tagging items already in the ctrl.items array and store them
Expand Down
15 changes: 15 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,21 @@ describe('ui-select tests', function() {
expect(isDropdownOpened(el3)).toEqual(true);
});

it('should allow decline tags when tagging function returns null', function() {
scope.taggingFunc = function (name) {
return null;
};

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

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

expect($(el).scope().$select.selected).not.toBeDefined();
});

it('should allow tagging if the attribute says so', function() {
var el = createUiSelect({tagging: true});
clickMatch(el);
Expand Down

0 comments on commit 246b9e8

Please sign in to comment.