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

Commit b7f2afe

Browse files
committed
Merge pull request #1573 from Slowvoice/master
fix (tagging): try all taggingTokens for splitting on paste
2 parents bd7654d + 835ebaf commit b7f2afe

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/uiSelectController.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,18 @@ uis.controller('uiSelectCtrl',
588588
if (data && data.length > 0) {
589589
// If tagging try to split by tokens and add items
590590
if (ctrl.taggingTokens.isActivated) {
591-
var separator = KEY.toSeparator(ctrl.taggingTokens.tokens[0]);
592-
var items = data.split(separator || ctrl.taggingTokens.tokens[0]); // split by first token only
593-
if (items && items.length > 0) {
591+
var items = [];
592+
for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { // split by first token that is contained in data
593+
var separator = KEY.toSeparator(ctrl.taggingTokens.tokens[i]) || ctrl.taggingTokens.tokens[i];
594+
if (data.indexOf(separator) > -1) {
595+
items = data.split(separator);
596+
break; // only split by one token
597+
}
598+
}
599+
if (items.length === 0) {
600+
items = [data];
601+
}
602+
if (items.length > 0) {
594603
var oldsearch = ctrl.search;
595604
angular.forEach(items, function (item) {
596605
var newItem = ctrl.tagging.fct ? ctrl.tagging.fct(item) : item;

test/select.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,6 +2504,22 @@ describe('ui-select tests', function() {
25042504
expect($(el).scope().$select.selected.length).toBe(3);
25052505
});
25062506

2507+
it('should split pastes on tagging token that is not the first token', function() {
2508+
var el = createUiSelectMultiple({tagging: true, taggingTokens: ",|ENTER|TAB"});
2509+
clickMatch(el);
2510+
triggerPaste(el.find('input'), "tag1\ntag2\ntag3\ntag4");
2511+
2512+
expect($(el).scope().$select.selected).toEqual(['tag1', 'tag2', 'tag3', 'tag4']);
2513+
});
2514+
2515+
it('should split pastes only on first tagging token found in paste string', function() {
2516+
var el = createUiSelectMultiple({tagging: true, taggingTokens: ",|ENTER|TAB"});
2517+
clickMatch(el);
2518+
triggerPaste(el.find('input'), "tag1\ntag2\ntag3\ttag4");
2519+
2520+
expect($(el).scope().$select.selected).toEqual(['tag1', 'tag2', 'tag3\ttag4']);
2521+
});
2522+
25072523
it('should add an id to the search input field', function () {
25082524
var el = createUiSelectMultiple({inputId: 'inid'});
25092525
var searchEl = $(el).find('input.ui-select-search');

0 commit comments

Comments
 (0)