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

Commit

Permalink
fix(tagging): Support paste with tagging enabled and tagging-label="f…
Browse files Browse the repository at this point in the history
…alse"

Closes #1668
  • Loading branch information
torstenrudolf authored and user378230 committed Jun 24, 2016
1 parent ec41b61 commit 668a0f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '"'; }
}
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 668a0f3

Please sign in to comment.