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

fix(tagging): allow to decline tag creation #678

Merged
merged 1 commit into from
Feb 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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