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

Commit

Permalink
Merge pull request #899 from kshutkin/master
Browse files Browse the repository at this point in the history
fix for #890, #770
  • Loading branch information
Brian Feister committed May 28, 2015
2 parents 5f91e77 + 3d9cc37 commit bb3bfdf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,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

0 comments on commit bb3bfdf

Please sign in to comment.