Skip to content

Commit 2ef3dc3

Browse files
committed
allow granular input-model update
1 parent 2865bd8 commit 2ef3dc3

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

angular-multi-select.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,15 +394,27 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$sce', '$
394394
validate();
395395
$scope.refreshSelectedItems();
396396

397-
// Watch for changes in input model (allow dynamic input)
397+
// Watch for changes in input model
398+
// Updates multi-select when user select/deselect a single checkbox programatically
399+
// https://github.com/isteven/angular-multi-select/issues/8
398400
$scope.$watch( 'inputModel' , function( oldVal, newVal ) {
399-
if ( $scope.inputModel !== 'undefined' ) {
401+
if ( $scope.newVal !== 'undefined' ) {
402+
validateProperties( $scope.itemLabel.split( ' ' ), $scope.inputModel );
403+
validateProperties( new Array( $scope.tickProperty ), $scope.inputModel );
404+
}
405+
$scope.refreshSelectedItems();
406+
}, true);
407+
408+
// Watch for changes in input model
409+
// This on updates the multi-select when a user load a whole new input-model. We also update the $scope.backUp variable
410+
$scope.$watch( 'inputModel' , function( oldVal, newVal ) {
411+
if ( $scope.newVal !== 'undefined' ) {
400412
validateProperties( $scope.itemLabel.split( ' ' ), $scope.inputModel );
401413
validateProperties( new Array( $scope.tickProperty ), $scope.inputModel );
402414
}
403415
$scope.backUp = angular.copy( $scope.inputModel );
404416
$scope.refreshSelectedItems();
405-
});
417+
});
406418

407419
// Watch for changes in directive state (disabled or enabled)
408420
$scope.$watch( 'isDisabled' , function( newVal ) {

angular-multi-select.min.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)