From 9f60d38c7c5958f41748d02744ef9360a3c5e9cd Mon Sep 17 00:00:00 2001 From: Torsten Rudolf Date: Fri, 17 Jun 2016 16:04:11 +1000 Subject: [PATCH] fix(tagging): Support paste with tagging enabled and tagging-label="false" Fixes #1668 --- src/uiSelectController.js | 26 +++++++++++++------------- test/select.spec.js | 9 +++++++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index b12592b84..09721ef6a 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -350,10 +350,12 @@ uis.controller('uiSelectCtrl', if (!item || !item._uiSelectChoiceDisabled) { if(ctrl.tagging.isActivated) { - // if taggingLabel is disabled, we pull from ctrl.search val + // if taggingLabel is disabled and item is undefined we pull from ctrl.search if ( ctrl.taggingLabel === false ) { if ( ctrl.activeIndex < 0 ) { - item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; + if (item === undefined) { + item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search; + } if (!item || angular.equals( ctrl.items[0], item ) ) { return; } @@ -606,18 +608,16 @@ uis.controller('uiSelectCtrl', if (items.length === 0) { items = [data]; } - if (items.length > 0) { var oldsearch = ctrl.search; - angular.forEach(items, function (item) { - var newItem = ctrl.tagging.fct ? ctrl.tagging.fct(item) : item; - if (newItem) { - ctrl.select(newItem, true); - } - }); - ctrl.search = oldsearch || EMPTY_SEARCH; - e.preventDefault(); - e.stopPropagation(); - } + angular.forEach(items, function (item) { + var newItem = ctrl.tagging.fct ? ctrl.tagging.fct(item) : item; + if (newItem) { + ctrl.select(newItem, true); + } + }); + ctrl.search = oldsearch || EMPTY_SEARCH; + e.preventDefault(); + e.stopPropagation(); } else if (ctrl.paste) { ctrl.paste(data); ctrl.search = EMPTY_SEARCH; diff --git a/test/select.spec.js b/test/select.spec.js index 106244532..e502c3995 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -1728,6 +1728,7 @@ describe('ui-select tests', function() { if (attrs.closeOnSelect !== undefined) { attrsHtml += ' close-on-select="' + attrs.closeOnSelect + '"'; } if (attrs.tagging !== undefined) { attrsHtml += ' tagging="' + attrs.tagging + '"'; } if (attrs.taggingTokens !== undefined) { attrsHtml += ' tagging-tokens="' + attrs.taggingTokens + '"'; } + if (attrs.taggingLabel !== undefined) { attrsHtml += ' tagging-label="' + attrs.taggingLabel + '"'; } if (attrs.inputId !== undefined) { attrsHtml += ' input-id="' + attrs.inputId + '"'; } if (attrs.groupBy !== undefined) { choicesAttrsHtml += ' group-by="' + attrs.groupBy + '"'; } } @@ -2570,6 +2571,14 @@ describe('ui-select tests', function() { expect($(el).scope().$select.selected).toEqual(['tag1', 'tag2', 'tag3\ttag4']); }); + it('should allow paste with tagging-tokens and tagging-label=="false"', function() { + var el = createUiSelectMultiple({tagging: true, taggingLabel: false, taggingTokens: ","}); + clickMatch(el); + triggerPaste(el.find('input'), 'tag1'); + + expect($(el).scope().$select.selected).toEqual(['tag1']); + }); + it('should add an id to the search input field', function () { var el = createUiSelectMultiple({inputId: 'inid'}); var searchEl = $(el).find('input.ui-select-search');