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

Commit 68228d0

Browse files
committed
fix(uiSelectController): invoke onRemove callback method for single select on clear selection
Closes #1225
1 parent 7e4e11b commit 68228d0

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/uiSelectController.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,15 @@ uis.controller('uiSelectCtrl',
454454
};
455455

456456
ctrl.clear = function($event) {
457+
var model = angular.copy(ctrl.ngModel.$modelValue);
458+
457459
ctrl.select(null);
458460
$event.stopPropagation();
459461
$timeout(function() {
462+
ctrl.onRemoveCallback($scope, {
463+
$item: ctrl.items[ctrl.activeIndex],
464+
$model: model
465+
});
460466
ctrl.focusser[0].focus();
461467
}, 0, false);
462468
};

test/select.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,35 @@ describe('ui-select tests', function () {
14251425

14261426
});
14271427

1428+
it('should invoke remove callback on remove for single select with allowClear enabled', function () {
1429+
scope.selection.selected = scope.people[5].name;
1430+
1431+
scope.onRemoveFn = function ($item, $model) {
1432+
scope.$item = $item;
1433+
scope.$model = $model;
1434+
};
1435+
1436+
var el = compileTemplate(
1437+
'<ui-select on-remove="onRemoveFn($item, $model)" ng-model="selection.selected"> \
1438+
<ui-select-match allow-clear="true" placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
1439+
<ui-select-choices repeat="person.name as 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+
expect(scope.$item).toBeFalsy();
1447+
expect(scope.$model).toBeFalsy();
1448+
1449+
el.find('.glyphicon.glyphicon-remove').click();
1450+
$timeout.flush();
1451+
1452+
expect(scope.$item).toBe(scope.people[5]);
1453+
expect(scope.$model).toBe('Samantha');
1454+
1455+
});
1456+
14281457
it('should set $item & $model correctly when invoking callback on remove and no single prop. binding', function () {
14291458

14301459
scope.onRemoveFn = function ($item, $model, $label) {

0 commit comments

Comments
 (0)