From 8e59e1afcd0d9add34529eef558b5cb31f2d981c Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 7 Mar 2017 22:16:17 -0600 Subject: [PATCH 1/4] Remove taggingLabel from item even when clicked --- src/uiSelectController.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index d6023d0b9..c6f6b7325 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -440,6 +440,8 @@ uis.controller('uiSelectCtrl', ctrl.close(skipFocusser); return; } + } else if ( typeof item === 'string') { + item = item.replace(ctrl.taggingLabel,'').trim(); } _resetSearchInput(); $scope.$broadcast('uis:select', item); From e3d31dcec9600ce005f73f7027d75c179c9cbb09 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 13 Feb 2018 09:19:13 -0600 Subject: [PATCH 2/4] Extract into function to avoid duplicate code --- src/uiSelectController.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index c6f6b7325..6a4f2f73a 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -388,6 +388,9 @@ uis.controller('uiSelectCtrl', return isDisabled; }; + function _replaceTaggingLabelAndTrim(item, taggingLabel) { + return item.replace(taggingLabel, '').trim(); + } // When the user selects an item with ENTER or clicks the dropdown ctrl.select = function(item, skipFocusser, $event) { @@ -431,7 +434,7 @@ uis.controller('uiSelectCtrl', // if item type is 'string', apply the tagging label } else if ( typeof item === 'string' ) { // trim the trailing space - item = item.replace(ctrl.taggingLabel,'').trim(); + item = _replaceTaggingLabelAndTrim(item, ctrl.taggingLabel); } } } @@ -441,7 +444,7 @@ uis.controller('uiSelectCtrl', return; } } else if ( typeof item === 'string') { - item = item.replace(ctrl.taggingLabel,'').trim(); + item = _replaceTaggingLabelAndTrim(item, ctrl.taggingLabel); } _resetSearchInput(); $scope.$broadcast('uis:select', item); From a636c2a4ecaece5293e7eee7251f1bdd859b51c0 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 13 Feb 2018 09:29:17 -0600 Subject: [PATCH 3/4] Match spaces --- src/uiSelectController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uiSelectController.js b/src/uiSelectController.js index 6a4f2f73a..13604a378 100644 --- a/src/uiSelectController.js +++ b/src/uiSelectController.js @@ -443,7 +443,7 @@ uis.controller('uiSelectCtrl', ctrl.close(skipFocusser); return; } - } else if ( typeof item === 'string') { + } else if ( typeof item === 'string' ) { item = _replaceTaggingLabelAndTrim(item, ctrl.taggingLabel); } _resetSearchInput(); From 47ab07375b10c1ed841f17cca3ab4c7fcabf1dfa Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 13 Feb 2018 10:35:38 -0600 Subject: [PATCH 4/4] Add tests --- test/select.spec.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/select.spec.js b/test/select.spec.js index 7add0ade5..88f32a057 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -161,6 +161,7 @@ describe('ui-select tests', function () { if (attrs.theme !== undefined) { attrsHtml += ' theme="' + attrs.theme + '"'; } if (attrs.tabindex !== undefined) { attrsHtml += ' tabindex="' + attrs.tabindex + '"'; } if (attrs.tagging !== undefined) { attrsHtml += ' tagging="' + attrs.tagging + '"'; } + if (attrs.taggingLabel !== undefined) { attrsHtml += ' tagging-label="' + attrs.taggingLabel + '"'; } if (attrs.taggingTokens !== undefined) { attrsHtml += ' tagging-tokens="' + attrs.taggingTokens + '"'; } if (attrs.title !== undefined) { attrsHtml += ' title="' + attrs.title + '"'; } if (attrs.appendToBody !== undefined) { attrsHtml += ' append-to-body="' + attrs.appendToBody + '"'; } @@ -682,6 +683,15 @@ describe('ui-select tests', function () { expect($(el).scope().$select.selected).toEqual("I don't exist"); }); + it('should not include tagging label if the selection is clicked', function () { + var el = createUiSelect({tagging: true, taggingLabel: ' (default)'}); + clickMatch(el); + + $(el).scope().$select.select("I don't exist (default)", undefined, { type: 'click' }); + + expect($(el).scope().$select.selected).toEqual("I don't exist"); + }); + it('should format new items using the tagging function when the attribute is a function', function () { scope.taggingFunc = function (name) { return { @@ -2730,6 +2740,17 @@ describe('ui-select tests', function () { expect(el.scope().$select.items[1]).toEqual(jasmine.objectContaining({ name: 'Amalie', email: 'amalie@email.com' })); }); + it('should not include tagging label if the selection is clicked', function () { + var el = createUiSelectMultiple({tagging: true, taggingLabel: ' (default)'}); + clickMatch(el); + + $(el).scope().$select.select("I don't exist (default)", undefined, { type: 'click' }); + $(el).scope().$select.select("I also don't exist (default)", undefined, { type: 'click' }); + + expect($(el).scope().$select.selected[0]).toEqual("I don't exist"); + expect($(el).scope().$select.selected[1]).toEqual("I also don't exist"); + }); + it('should have tolerance for undefined values', function () {