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

fix for #890, #770 #899

Merged
merged 4 commits into from
May 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ uis.controller('uiSelectCtrl',
if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true);
break;
case KEY.ENTER:
if(ctrl.open && ctrl.activeIndex >= 0){
ctrl.select(ctrl.items[ctrl.activeIndex]); // Make sure at least one dropdown item is highlighted before adding.
if(ctrl.open && (ctrl.tagging.isActivated || ctrl.activeIndex >= 0)){
ctrl.select(ctrl.items[ctrl.activeIndex]); // Make sure at least one dropdown item is highlighted before adding if not in tagging mode
} else {
ctrl.activate(false, true); //In case its the search input in 'multiple' mode
}
Expand Down
52 changes: 52 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,58 @@ describe('ui-select tests', function() {
expect(scope.$model).toBe(scope.$item);
});

it('should allow creating tag in single select mode with tagging enabled', function() {

scope.taggingFunc = function (name) {
return name;
};

var el = compileTemplate(
'<ui-select ng-model="selection.selected" tagging="taggingFunc" tagging-label="false"> \
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
<ui-select-choices repeat="person in people | filter: $select.search"> \
<div ng-bind-html="person.name" | highlight: $select.search"></div> \
<div ng-bind-html="person.email | highlight: $select.search"></div> \
</ui-select-choices> \
</ui-select>'
);

clickMatch(el);

var searchInput = el.find('.ui-select-search');

setSearchText(el, 'idontexist');

triggerKeydown(searchInput, Key.Enter);

expect($(el).scope().$select.selected).toEqual('idontexist');
});

it('should allow creating tag on ENTER in multiple select mode with tagging enabled, no labels', function() {

scope.taggingFunc = function (name) {
return name;
};

var el = compileTemplate(
'<ui-select multiple ng-model="selection.selected" tagging="taggingFunc" tagging-label="false"> \
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
<ui-select-choices repeat="person in people | filter: $select.search"> \
<div ng-bind-html="person.name" | highlight: $select.search"></div> \
<div ng-bind-html="person.email | highlight: $select.search"></div> \
</ui-select-choices> \
</ui-select>'
);

var searchInput = el.find('.ui-select-search');

setSearchText(el, 'idontexist');

triggerKeydown(searchInput, Key.Enter);

expect($(el).scope().$select.selected).toEqual(['idontexist']);
});

it('should append/transclude content (with correct scope) that users add at <match> tag', function () {

var el = compileTemplate(
Expand Down