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

Commit

Permalink
fix(uiSelectController): Select by click on non-multiple tagging (bis) (
Browse files Browse the repository at this point in the history
#1727)

* When in tagging mode, not multiple (taggingLabel === false), selecting
an item by click was instead calling taggingFunc(). This fix checks
for this manual selection, whether ctrl.search is filled or not and
acts accordingly.

Same changes mad in #1439 that were mysteriously lost.
Fixes #1357, #1496 and #1409

* Simplification to combine ctrl.clickTriggeredSelect in one assignment
  • Loading branch information
kfedorov authored and aaronroberson committed Jul 19, 2016
1 parent 81c33d0 commit 3dfde71
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
22 changes: 12 additions & 10 deletions src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ uis.controller('uiSelectCtrl',
function _isItemDisabled(item) {
return disabledItems.indexOf(item) > -1;
}

ctrl.isDisabled = function(itemScope) {

if (!ctrl.open) return;

var item = itemScope[ctrl.itemProperty];
var itemIndex = ctrl.items.indexOf(item);
var isDisabled = false;

if (itemIndex >= 0 && (angular.isDefined(ctrl.disableChoiceExpression) || ctrl.multiple)) {

if (item.isTag) return false;
Expand All @@ -360,7 +360,7 @@ uis.controller('uiSelectCtrl',
if (!isDisabled && angular.isDefined(ctrl.disableChoiceExpression)) {
isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression));
}

_updateItemDisabled(item, isDisabled);
}

Expand All @@ -375,7 +375,12 @@ uis.controller('uiSelectCtrl',
if ( ! ctrl.items && ! ctrl.search && ! ctrl.tagging.isActivated) return;

if (!item || !_isItemDisabled(item)) {
if(ctrl.tagging.isActivated) {
// if click is made on existing item, prevent from tagging, ctrl.search does not matter
ctrl.clickTriggeredSelect = false;
if($event && $event.type === 'click' && item)
ctrl.clickTriggeredSelect = true;

if(ctrl.tagging.isActivated && ctrl.clickTriggeredSelect === false) {
// if taggingLabel is disabled and item is undefined we pull from ctrl.search
if ( ctrl.taggingLabel === false ) {
if ( ctrl.activeIndex < 0 ) {
Expand Down Expand Up @@ -431,9 +436,6 @@ uis.controller('uiSelectCtrl',
if (ctrl.closeOnSelect) {
ctrl.close(skipFocusser);
}
if ($event && $event.type === 'click') {
ctrl.clickTriggeredSelect = true;
}
}
}
};
Expand Down Expand Up @@ -472,7 +474,7 @@ uis.controller('uiSelectCtrl',
}
};

// Set default function for locked choices - avoids unnecessary
// Set default function for locked choices - avoids unnecessary
// logic if functionality is not being used
ctrl.isLocked = function () {
return false;
Expand All @@ -484,7 +486,7 @@ uis.controller('uiSelectCtrl',

function _initaliseLockedChoices(doInitalise) {
if(!doInitalise) return;

var lockedItems = [];

function _updateItemLocked(item, isLocked) {
Expand Down Expand Up @@ -518,7 +520,7 @@ uis.controller('uiSelectCtrl',
return isLocked;
};
}


var sizeWatch = null;
var updaterScheduled = false;
Expand Down
29 changes: 27 additions & 2 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,31 @@ describe('ui-select tests', function() {
expect($(el).scope().$select.selected).toEqual(['idontexist']);
});

it('should allow selecting an item (click) 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);
setSearchText(el, 'Sam');
clickItem(el, 'Samantha');

expect(scope.selection.selected).toBe(scope.people[5]);
expect(getMatchLabel(el)).toEqual('Samantha');
});


it('should remove a choice when multiple and remove-selected is not given (default is true)', function () {

var el = compileTemplate(
Expand Down Expand Up @@ -2527,7 +2552,7 @@ describe('ui-select tests', function() {
expect(el.scope().$select.items[1]).toEqual(jasmine.objectContaining({name: 'Amalie', email: 'amalie@email.com'}));
});


it('should have tolerance for undefined values', function () {

scope.modelValue = undefined;
Expand Down Expand Up @@ -2563,7 +2588,7 @@ describe('ui-select tests', function() {

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

it('should allow paste tag from clipboard', function() {
scope.taggingFunc = function (name) {
return {
Expand Down

0 comments on commit 3dfde71

Please sign in to comment.