Skip to content

Commit

Permalink
Merge pull request angular-ui#501 from gotenxds/master
Browse files Browse the repository at this point in the history
on-remove and on-select should fire AFTER addition/removal of the item
  • Loading branch information
Brian Feister committed Dec 14, 2014
2 parents aa13ee3 + 517ec79 commit e8931b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,11 @@
ctrl.selected = item;
}

ctrl.onSelectCallback($scope, {
$timeout(function(){
ctrl.onSelectCallback($scope, {
$item: item,
$model: ctrl.parserResult.modelMapper($scope, locals)
});
});

if (!ctrl.multiple || ctrl.closeOnSelect) {
Expand Down Expand Up @@ -495,9 +497,12 @@
ctrl.activeMatchIndex = -1;
ctrl.sizeSearchInput();

ctrl.onRemoveCallback($scope, {
$item: removedChoice,
$model: ctrl.parserResult.modelMapper($scope, locals)
// Give some time for scope propagation.
$timeout(function(){
ctrl.onRemoveCallback($scope, {
$item: removedChoice,
$model: ctrl.parserResult.modelMapper($scope, locals)
});
});
};

Expand Down
5 changes: 5 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@ describe('ui-select tests', function() {
expect(scope.$model).toBeFalsy();

clickItem(el, 'Samantha');
$timeout.flush();


expect(scope.selection.selected).toBe('Samantha');

expect(scope.$item).toEqual(scope.people[5]);
Expand Down Expand Up @@ -858,6 +861,7 @@ describe('ui-select tests', function() {
clickItem(el, 'Samantha');
clickItem(el, 'Adrian');
el.find('.ui-select-match-item').first().find('.ui-select-match-close').click();
$timeout.flush();

expect(scope.$item).toBe(scope.people[5]);
expect(scope.$model).toBe('Samantha');
Expand Down Expand Up @@ -887,6 +891,7 @@ describe('ui-select tests', function() {
clickItem(el, 'Samantha');
clickItem(el, 'Adrian');
el.find('.ui-select-match-item').first().find('.ui-select-match-close').click();
$timeout.flush();

expect(scope.$item).toBe(scope.people[5]);
expect(scope.$model).toBe(scope.$item);
Expand Down

0 comments on commit e8931b9

Please sign in to comment.