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

Commit 3dfde71

Browse files
kfedorovaaronroberson
authored andcommitted
fix(uiSelectController): Select by click on non-multiple tagging (bis) (#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
1 parent 81c33d0 commit 3dfde71

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

Diff for: src/uiSelectController.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,15 @@ uis.controller('uiSelectCtrl',
340340
function _isItemDisabled(item) {
341341
return disabledItems.indexOf(item) > -1;
342342
}
343-
343+
344344
ctrl.isDisabled = function(itemScope) {
345345

346346
if (!ctrl.open) return;
347347

348348
var item = itemScope[ctrl.itemProperty];
349349
var itemIndex = ctrl.items.indexOf(item);
350350
var isDisabled = false;
351-
351+
352352
if (itemIndex >= 0 && (angular.isDefined(ctrl.disableChoiceExpression) || ctrl.multiple)) {
353353

354354
if (item.isTag) return false;
@@ -360,7 +360,7 @@ uis.controller('uiSelectCtrl',
360360
if (!isDisabled && angular.isDefined(ctrl.disableChoiceExpression)) {
361361
isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression));
362362
}
363-
363+
364364
_updateItemDisabled(item, isDisabled);
365365
}
366366

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

377377
if (!item || !_isItemDisabled(item)) {
378-
if(ctrl.tagging.isActivated) {
378+
// if click is made on existing item, prevent from tagging, ctrl.search does not matter
379+
ctrl.clickTriggeredSelect = false;
380+
if($event && $event.type === 'click' && item)
381+
ctrl.clickTriggeredSelect = true;
382+
383+
if(ctrl.tagging.isActivated && ctrl.clickTriggeredSelect === false) {
379384
// if taggingLabel is disabled and item is undefined we pull from ctrl.search
380385
if ( ctrl.taggingLabel === false ) {
381386
if ( ctrl.activeIndex < 0 ) {
@@ -431,9 +436,6 @@ uis.controller('uiSelectCtrl',
431436
if (ctrl.closeOnSelect) {
432437
ctrl.close(skipFocusser);
433438
}
434-
if ($event && $event.type === 'click') {
435-
ctrl.clickTriggeredSelect = true;
436-
}
437439
}
438440
}
439441
};
@@ -472,7 +474,7 @@ uis.controller('uiSelectCtrl',
472474
}
473475
};
474476

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

485487
function _initaliseLockedChoices(doInitalise) {
486488
if(!doInitalise) return;
487-
489+
488490
var lockedItems = [];
489491

490492
function _updateItemLocked(item, isLocked) {
@@ -518,7 +520,7 @@ uis.controller('uiSelectCtrl',
518520
return isLocked;
519521
};
520522
}
521-
523+
522524

523525
var sizeWatch = null;
524526
var updaterScheduled = false;

Diff for: test/select.spec.js

+27-2
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,31 @@ describe('ui-select tests', function() {
14271427
expect($(el).scope().$select.selected).toEqual(['idontexist']);
14281428
});
14291429

1430+
it('should allow selecting an item (click) in single select mode with tagging enabled', function() {
1431+
1432+
scope.taggingFunc = function (name) {
1433+
return name;
1434+
};
1435+
1436+
var el = compileTemplate(
1437+
'<ui-select ng-model="selection.selected" tagging="taggingFunc" tagging-label="false"> \
1438+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
1439+
<ui-select-choices repeat="person in people | filter: $select.search"> \
1440+
<div ng-bind-html="person.name" | highlight: $select.search"></div> \
1441+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1442+
</ui-select-choices> \
1443+
</ui-select>'
1444+
);
1445+
1446+
clickMatch(el);
1447+
setSearchText(el, 'Sam');
1448+
clickItem(el, 'Samantha');
1449+
1450+
expect(scope.selection.selected).toBe(scope.people[5]);
1451+
expect(getMatchLabel(el)).toEqual('Samantha');
1452+
});
1453+
1454+
14301455
it('should remove a choice when multiple and remove-selected is not given (default is true)', function () {
14311456

14321457
var el = compileTemplate(
@@ -2527,7 +2552,7 @@ describe('ui-select tests', function() {
25272552
expect(el.scope().$select.items[1]).toEqual(jasmine.objectContaining({name: 'Amalie', email: '[email protected]'}));
25282553
});
25292554

2530-
2555+
25312556
it('should have tolerance for undefined values', function () {
25322557

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

25642589
expect($(el).scope().$select.selected).toEqual([]);
25652590
});
2566-
2591+
25672592
it('should allow paste tag from clipboard', function() {
25682593
scope.taggingFunc = function (name) {
25692594
return {

0 commit comments

Comments
 (0)