@@ -120,6 +120,7 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
120
120
$scope . selectedItems = [ ] ;
121
121
$scope . formElements = [ ] ;
122
122
$scope . tabIndex = 0 ;
123
+ $scope . clickedItem = null ;
123
124
prevTabIndex = 0 ;
124
125
helperItems = [ ] ;
125
126
helperItemsLength = 0 ;
@@ -376,12 +377,11 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
376
377
377
378
// single item click
378
379
else {
379
- $scope . filteredModel [ index ] [ $scope . tickProperty ] = ! $scope . filteredModel [ index ] [ $scope . tickProperty ] ;
380
+ $scope . filteredModel [ index ] [ $scope . tickProperty ] = ! $scope . filteredModel [ index ] [ $scope . tickProperty ] ;
380
381
381
382
// we refresh input model as well
382
383
inputModelIndex = $scope . filteredModel [ index ] [ $scope . indexProperty ] ;
383
- $scope . inputModel [ inputModelIndex ] [ $scope . tickProperty ] = $scope . filteredModel [ index ] [ $scope . tickProperty ] ;
384
-
384
+ $scope . inputModel [ inputModelIndex ] [ $scope . tickProperty ] = $scope . filteredModel [ index ] [ $scope . tickProperty ] ;
385
385
386
386
// If it's single selection mode
387
387
if ( attrs . selectionMode && $scope . selectionMode . toUpperCase ( ) === 'SINGLE' ) {
@@ -393,9 +393,9 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
393
393
}
394
394
$scope . toggleCheckboxes ( e ) ;
395
395
}
396
- }
396
+ }
397
397
398
- $scope . onItemClick ( { data : item } ) ;
398
+ $scope . clickedItem = angular . copy ( item ) ;
399
399
400
400
// We update the index here
401
401
prevTabIndex = $scope . tabIndex ;
@@ -831,11 +831,15 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
831
831
// watch1, for changes in input model property
832
832
// updates multi-select when user select/deselect a single checkbox programatically
833
833
// https://github.com/isteven/angular-multi-select/issues/8
834
- $scope . $watch ( 'inputModel' , function ( newVal ) {
834
+ $scope . $watch ( 'inputModel' , function ( newVal ) {
835
835
if ( newVal ) {
836
836
$scope . refreshSelectedItems ( ) ;
837
837
$scope . refreshOutputModel ( ) ;
838
- $scope . refreshButton ( ) ;
838
+ $scope . refreshButton ( ) ;
839
+ if ( $scope . clickedItem !== null ) {
840
+ $scope . onItemClick ( { data : $scope . clickedItem } ) ;
841
+ $scope . clickedItem = null ;
842
+ }
839
843
}
840
844
} , true ) ;
841
845
0 commit comments