Skip to content

Commit 04e8c6b

Browse files
author
isteven
committed
fixed on-item-click callback parameter
1 parent 14f0edb commit 04e8c6b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

angular-multi-select.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
120120
$scope.selectedItems = [];
121121
$scope.formElements = [];
122122
$scope.tabIndex = 0;
123+
$scope.clickedItem = null;
123124
prevTabIndex = 0;
124125
helperItems = [];
125126
helperItemsLength = 0;
@@ -376,12 +377,11 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
376377

377378
// single item click
378379
else {
379-
$scope.filteredModel[ index ][ $scope.tickProperty ] = !$scope.filteredModel[ index ][ $scope.tickProperty ];
380+
$scope.filteredModel[ index ][ $scope.tickProperty ] = !$scope.filteredModel[ index ][ $scope.tickProperty ];
380381

381382
// we refresh input model as well
382383
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 ];
385385

386386
// If it's single selection mode
387387
if ( attrs.selectionMode && $scope.selectionMode.toUpperCase() === 'SINGLE' ) {
@@ -393,9 +393,9 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
393393
}
394394
$scope.toggleCheckboxes( e );
395395
}
396-
}
396+
}
397397

398-
$scope.onItemClick( { data: item } );
398+
$scope.clickedItem = angular.copy( item );
399399

400400
// We update the index here
401401
prevTabIndex = $scope.tabIndex;
@@ -831,11 +831,15 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
831831
// watch1, for changes in input model property
832832
// updates multi-select when user select/deselect a single checkbox programatically
833833
// https://github.com/isteven/angular-multi-select/issues/8
834-
$scope.$watch( 'inputModel' , function( newVal ) {
834+
$scope.$watch( 'inputModel' , function( newVal ) {
835835
if ( newVal ) {
836836
$scope.refreshSelectedItems();
837837
$scope.refreshOutputModel();
838-
$scope.refreshButton();
838+
$scope.refreshButton();
839+
if ( $scope.clickedItem !== null ) {
840+
$scope.onItemClick( { data: $scope.clickedItem } );
841+
$scope.clickedItem = null;
842+
}
839843
}
840844
}, true);
841845

0 commit comments

Comments
 (0)