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

Commit 2520085

Browse files
committed
fix(uiSelectController): invoke onRemove callback method for single select on clear selection
Closes #1225
1 parent 912a70a commit 2520085

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/uiSelectController.js

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

456456
ctrl.clear = function($event) {
457+
var locals = {};
458+
locals[ctrl.parserResult.itemName] = ctrl.selected;
459+
457460
ctrl.select(null);
458461
$event.stopPropagation();
459462
$timeout(function() {
463+
ctrl.onRemoveCallback($scope, {
464+
$item: ctrl.items[ctrl.activeIndex],
465+
$model: ctrl.parserResult.modelMapper($scope, locals)
466+
});
460467
ctrl.focusser[0].focus();
461468
}, 0, false);
462469
};

test/select.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ describe('ui-select tests', function () {
174174
if (attrs.backspaceReset !== undefined) { attrsHtml += ' backspace-reset="' + attrs.backspaceReset + '"'; }
175175
if (attrs.uiDisableChoice !== undefined) { choicesAttrsHtml += ' ui-disable-choice="' + attrs.uiDisableChoice + '"'; }
176176
if (attrs.removeSelected !== undefined) { attrsHtml += ' remove-selected="' + attrs.removeSelected + '"'; }
177+
if (attrs.onRemove !== undefined) { attrsHtml += ' on-remove="' + attrs.onRemove + '"'; }
177178
}
178179

179180
return compileTemplate(
@@ -1369,6 +1370,27 @@ describe('ui-select tests', function () {
13691370

13701371
});
13711372

1373+
it('should invoke remove callback on remove for single select with allowClear enabled', function () {
1374+
scope.selection.selected = scope.people[5];
1375+
1376+
scope.onRemoveFn = function ($item, $model) {
1377+
scope.$item = $item;
1378+
scope.$model = $model;
1379+
};
1380+
1381+
var el = createUiSelect({ onRemove: 'onRemoveFn($item, $model)', allowClear: true });
1382+
1383+
expect(scope.$item).toBeFalsy();
1384+
expect(scope.$model).toBeFalsy();
1385+
1386+
el.find('.glyphicon.glyphicon-remove').click();
1387+
$timeout.flush();
1388+
1389+
expect(scope.$item).toEqual(scope.people[5]);
1390+
expect(scope.$model).toEqual(scope.$item);
1391+
1392+
});
1393+
13721394
it('should set $item & $model correctly when invoking callback on remove and no single prop. binding', function () {
13731395

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

0 commit comments

Comments
 (0)