Skip to content

Commit bb3bfdf

Browse files
author
Brian Feister
committed
Merge pull request angular-ui#899 from kshutkin/master
fix for angular-ui#890, angular-ui#770
2 parents 5f91e77 + 3d9cc37 commit bb3bfdf

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

src/uiSelectController.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ uis.controller('uiSelectCtrl',
378378
if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true);
379379
break;
380380
case KEY.ENTER:
381-
if(ctrl.open && ctrl.activeIndex >= 0){
382-
ctrl.select(ctrl.items[ctrl.activeIndex]); // Make sure at least one dropdown item is highlighted before adding.
381+
if(ctrl.open && (ctrl.tagging.isActivated || ctrl.activeIndex >= 0)){
382+
ctrl.select(ctrl.items[ctrl.activeIndex]); // Make sure at least one dropdown item is highlighted before adding if not in tagging mode
383383
} else {
384384
ctrl.activate(false, true); //In case its the search input in 'multiple' mode
385385
}

test/select.spec.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,58 @@ describe('ui-select tests', function() {
10251025
expect(scope.$model).toBe(scope.$item);
10261026
});
10271027

1028+
it('should allow creating tag in single select mode with tagging enabled', function() {
1029+
1030+
scope.taggingFunc = function (name) {
1031+
return name;
1032+
};
1033+
1034+
var el = compileTemplate(
1035+
'<ui-select ng-model="selection.selected" tagging="taggingFunc" tagging-label="false"> \
1036+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
1037+
<ui-select-choices repeat="person in people | filter: $select.search"> \
1038+
<div ng-bind-html="person.name" | highlight: $select.search"></div> \
1039+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1040+
</ui-select-choices> \
1041+
</ui-select>'
1042+
);
1043+
1044+
clickMatch(el);
1045+
1046+
var searchInput = el.find('.ui-select-search');
1047+
1048+
setSearchText(el, 'idontexist');
1049+
1050+
triggerKeydown(searchInput, Key.Enter);
1051+
1052+
expect($(el).scope().$select.selected).toEqual('idontexist');
1053+
});
1054+
1055+
it('should allow creating tag on ENTER in multiple select mode with tagging enabled, no labels', function() {
1056+
1057+
scope.taggingFunc = function (name) {
1058+
return name;
1059+
};
1060+
1061+
var el = compileTemplate(
1062+
'<ui-select multiple ng-model="selection.selected" tagging="taggingFunc" tagging-label="false"> \
1063+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
1064+
<ui-select-choices repeat="person in people | filter: $select.search"> \
1065+
<div ng-bind-html="person.name" | highlight: $select.search"></div> \
1066+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1067+
</ui-select-choices> \
1068+
</ui-select>'
1069+
);
1070+
1071+
var searchInput = el.find('.ui-select-search');
1072+
1073+
setSearchText(el, 'idontexist');
1074+
1075+
triggerKeydown(searchInput, Key.Enter);
1076+
1077+
expect($(el).scope().$select.selected).toEqual(['idontexist']);
1078+
});
1079+
10281080
it('should append/transclude content (with correct scope) that users add at <match> tag', function () {
10291081

10301082
var el = compileTemplate(

0 commit comments

Comments
 (0)