Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit d24c96e

Browse files
authored
Replace escaped tagging tokens when tagging on ENTER or TAB with no tagging label (#5)
1 parent a8d1b69 commit d24c96e

File tree

7 files changed

+54
-26
lines changed

7 files changed

+54
-26
lines changed

dist/select.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* ui-select
33
* http://github.com/angular-ui/ui-select
4-
* Version: 0.19.6 - 2017-06-14T06:02:26.871Z
4+
* Version: 0.19.6 - 2017-06-14T23:04:00.478Z
55
* License: MIT
66
*/
77

dist/select.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* ui-select
33
* http://github.com/angular-ui/ui-select
4-
* Version: 0.19.6 - 2017-06-14T06:02:26.658Z
4+
* Version: 0.19.6 - 2017-06-14T23:04:00.285Z
55
* License: MIT
66
*/
77

@@ -682,7 +682,9 @@ uis.controller('uiSelectCtrl',
682682
if ( ctrl.taggingLabel === false ) {
683683
if ( ctrl.activeIndex < 0 ) {
684684
if (item === undefined) {
685-
item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search;
685+
// when pulling from ctrl.search, deal with tagging tokens
686+
item = _replaceAllTaggingTokens(ctrl.search);
687+
if (ctrl.tagging.fct) item = ctrl.tagging.fct(item);
686688
}
687689
if (!item || angular.equals( ctrl.items[0], item ) ) {
688690
return;
@@ -894,6 +896,8 @@ uis.controller('uiSelectCtrl',
894896
}
895897

896898
function _replaceTaggingTokens(search, token) {
899+
if (token.length > 1) return search; // do not replace token if it is a special key
900+
897901
var tokenRegex = new RegExp(token + '$');
898902
if ( ctrl.taggingTokenEscape ) {
899903
// replace escaped tagging tokens with just the token
@@ -908,6 +912,16 @@ uis.controller('uiSelectCtrl',
908912
return search;
909913
}
910914

915+
function _replaceAllTaggingTokens(search) {
916+
if (ctrl.taggingTokens.isActivated) {
917+
for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) {
918+
var token = ctrl.taggingTokens.tokens[i];
919+
search = _replaceTaggingTokens(search, token);
920+
}
921+
}
922+
return search;
923+
}
924+
911925
// Bind to keyboard shortcuts
912926
ctrl.searchInput.on('keydown', function(e) {
913927

@@ -1018,15 +1032,7 @@ uis.controller('uiSelectCtrl',
10181032
if (ctrl.tagging.isActivated && ctrl.tagOnBlur) {
10191033
$timeout(function() {
10201034
ctrl.searchInput.triggerHandler('tagged');
1021-
var newItem = ctrl.search;
1022-
1023-
// replace all tagging tokens
1024-
if (ctrl.taggingTokens.isActivated) {
1025-
for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) {
1026-
newItem = _replaceTaggingTokens(newItem, ctrl.taggingTokens.tokens[i]);
1027-
}
1028-
}
1029-
1035+
var newItem = _replaceAllTaggingTokens(ctrl.search);
10301036
if ( ctrl.tagging.fct ) {
10311037
newItem = ctrl.tagging.fct( newItem );
10321038
}

dist/select.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/select.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/select.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uiSelectController.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,9 @@ uis.controller('uiSelectCtrl',
402402
if ( ctrl.taggingLabel === false ) {
403403
if ( ctrl.activeIndex < 0 ) {
404404
if (item === undefined) {
405-
item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search;
405+
// when pulling from ctrl.search, deal with tagging tokens
406+
item = _replaceAllTaggingTokens(ctrl.search);
407+
if (ctrl.tagging.fct) item = ctrl.tagging.fct(item);
406408
}
407409
if (!item || angular.equals( ctrl.items[0], item ) ) {
408410
return;
@@ -614,6 +616,8 @@ uis.controller('uiSelectCtrl',
614616
}
615617

616618
function _replaceTaggingTokens(search, token) {
619+
if (token.length > 1) return search; // do not replace token if it is a special key
620+
617621
var tokenRegex = new RegExp(token + '$');
618622
if ( ctrl.taggingTokenEscape ) {
619623
// replace escaped tagging tokens with just the token
@@ -628,6 +632,16 @@ uis.controller('uiSelectCtrl',
628632
return search;
629633
}
630634

635+
function _replaceAllTaggingTokens(search) {
636+
if (ctrl.taggingTokens.isActivated) {
637+
for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) {
638+
var token = ctrl.taggingTokens.tokens[i];
639+
search = _replaceTaggingTokens(search, token);
640+
}
641+
}
642+
return search;
643+
}
644+
631645
// Bind to keyboard shortcuts
632646
ctrl.searchInput.on('keydown', function(e) {
633647

@@ -738,15 +752,7 @@ uis.controller('uiSelectCtrl',
738752
if (ctrl.tagging.isActivated && ctrl.tagOnBlur) {
739753
$timeout(function() {
740754
ctrl.searchInput.triggerHandler('tagged');
741-
var newItem = ctrl.search;
742-
743-
// replace all tagging tokens
744-
if (ctrl.taggingTokens.isActivated) {
745-
for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) {
746-
newItem = _replaceTaggingTokens(newItem, ctrl.taggingTokens.tokens[i]);
747-
}
748-
}
749-
755+
var newItem = _replaceAllTaggingTokens(ctrl.search);
750756
if ( ctrl.tagging.fct ) {
751757
newItem = ctrl.tagging.fct( newItem );
752758
}

test/select.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,22 @@ describe('ui-select tests', function() {
28542854
expect($(el).scope().$select.selected).toEqual(['tag,']);
28552855
});
28562856

2857+
it('should convert escaped token to token when tagging with ENTER with no tagging label', function () {
2858+
var el = createUiSelectMultiple({tagging: true, taggingTokenEscape: '^', taggingTokens: ',', taggingLabel: 'false'});
2859+
var searchInput = el.find('.ui-select-search');
2860+
setSearchText(el, 'tag^,');
2861+
triggerKeydown(searchInput, Key.Enter);
2862+
expect($(el).scope().$select.selected).toEqual(['tag,']);
2863+
});
2864+
2865+
it('should convert escaped token to token when tagging with TAB with no tagging label', function () {
2866+
var el = createUiSelectMultiple({tagging: true, taggingTokenEscape: '^', taggingTokens: ',', taggingLabel: 'false'});
2867+
var searchInput = el.find('.ui-select-search');
2868+
setSearchText(el, 'tag^,');
2869+
triggerKeydown(searchInput, Key.Tab);
2870+
expect($(el).scope().$select.selected).toEqual(['tag,']);
2871+
});
2872+
28572873
it('should not remove tagging token in the middle', function () {
28582874
var el = createUiSelectMultiple({tagging: true, taggingTokenEscape: '^', taggingTokens: ','});
28592875
var searchInput = el.find('.ui-select-search');

0 commit comments

Comments
 (0)