Skip to content

Commit 9f60d38

Browse files
committed
fix(tagging): Support paste with tagging enabled and tagging-label="false"
Fixes angular-ui#1668
1 parent ec41b61 commit 9f60d38

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/uiSelectController.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,12 @@ uis.controller('uiSelectCtrl',
350350

351351
if (!item || !item._uiSelectChoiceDisabled) {
352352
if(ctrl.tagging.isActivated) {
353-
// if taggingLabel is disabled, we pull from ctrl.search val
353+
// if taggingLabel is disabled and item is undefined we pull from ctrl.search
354354
if ( ctrl.taggingLabel === false ) {
355355
if ( ctrl.activeIndex < 0 ) {
356-
item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search;
356+
if (item === undefined) {
357+
item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search;
358+
}
357359
if (!item || angular.equals( ctrl.items[0], item ) ) {
358360
return;
359361
}
@@ -606,18 +608,16 @@ uis.controller('uiSelectCtrl',
606608
if (items.length === 0) {
607609
items = [data];
608610
}
609-
if (items.length > 0) {
610611
var oldsearch = ctrl.search;
611-
angular.forEach(items, function (item) {
612-
var newItem = ctrl.tagging.fct ? ctrl.tagging.fct(item) : item;
613-
if (newItem) {
614-
ctrl.select(newItem, true);
615-
}
616-
});
617-
ctrl.search = oldsearch || EMPTY_SEARCH;
618-
e.preventDefault();
619-
e.stopPropagation();
620-
}
612+
angular.forEach(items, function (item) {
613+
var newItem = ctrl.tagging.fct ? ctrl.tagging.fct(item) : item;
614+
if (newItem) {
615+
ctrl.select(newItem, true);
616+
}
617+
});
618+
ctrl.search = oldsearch || EMPTY_SEARCH;
619+
e.preventDefault();
620+
e.stopPropagation();
621621
} else if (ctrl.paste) {
622622
ctrl.paste(data);
623623
ctrl.search = EMPTY_SEARCH;

test/select.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,7 @@ describe('ui-select tests', function() {
17281728
if (attrs.closeOnSelect !== undefined) { attrsHtml += ' close-on-select="' + attrs.closeOnSelect + '"'; }
17291729
if (attrs.tagging !== undefined) { attrsHtml += ' tagging="' + attrs.tagging + '"'; }
17301730
if (attrs.taggingTokens !== undefined) { attrsHtml += ' tagging-tokens="' + attrs.taggingTokens + '"'; }
1731+
if (attrs.taggingLabel !== undefined) { attrsHtml += ' tagging-label="' + attrs.taggingLabel + '"'; }
17311732
if (attrs.inputId !== undefined) { attrsHtml += ' input-id="' + attrs.inputId + '"'; }
17321733
if (attrs.groupBy !== undefined) { choicesAttrsHtml += ' group-by="' + attrs.groupBy + '"'; }
17331734
}
@@ -2570,6 +2571,14 @@ describe('ui-select tests', function() {
25702571
expect($(el).scope().$select.selected).toEqual(['tag1', 'tag2', 'tag3\ttag4']);
25712572
});
25722573

2574+
it('should allow paste with tagging-tokens and tagging-label=="false"', function() {
2575+
var el = createUiSelectMultiple({tagging: true, taggingLabel: false, taggingTokens: ","});
2576+
clickMatch(el);
2577+
triggerPaste(el.find('input'), 'tag1');
2578+
2579+
expect($(el).scope().$select.selected).toEqual(['tag1']);
2580+
});
2581+
25732582
it('should add an id to the search input field', function () {
25742583
var el = createUiSelectMultiple({inputId: 'inid'});
25752584
var searchEl = $(el).find('input.ui-select-search');

0 commit comments

Comments
 (0)