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

Commit 11e24d1

Browse files
author
Konstantin Fedorov
committed
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
1 parent d1994fb commit 11e24d1

File tree

2 files changed

+38
-9
lines changed

2 files changed

+38
-9
lines changed

src/uiSelectController.js

Lines changed: 11 additions & 7 deletions
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,11 @@ 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+
var manualSelection = false;
380+
if($event && $event.type === 'click' && item)
381+
manualSelection = true;
382+
if(ctrl.tagging.isActivated && manualSelection === false) {
379383
// if taggingLabel is disabled and item is undefined we pull from ctrl.search
380384
if ( ctrl.taggingLabel === false ) {
381385
if ( ctrl.activeIndex < 0 ) {
@@ -472,7 +476,7 @@ uis.controller('uiSelectCtrl',
472476
}
473477
};
474478

475-
// Set default function for locked choices - avoids unnecessary
479+
// Set default function for locked choices - avoids unnecessary
476480
// logic if functionality is not being used
477481
ctrl.isLocked = function () {
478482
return false;
@@ -484,7 +488,7 @@ uis.controller('uiSelectCtrl',
484488

485489
function _initaliseLockedChoices(doInitalise) {
486490
if(!doInitalise) return;
487-
491+
488492
var lockedItems = [];
489493

490494
function _updateItemLocked(item, isLocked) {
@@ -518,7 +522,7 @@ uis.controller('uiSelectCtrl',
518522
return isLocked;
519523
};
520524
}
521-
525+
522526

523527
var sizeWatch = null;
524528
var updaterScheduled = false;

test/select.spec.js

Lines changed: 27 additions & 2 deletions
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)