diff options
author | isteven <ignatius.steven@gmail.com> | 2014-03-30 14:52:41 +0800 |
---|---|---|
committer | isteven <ignatius.steven@gmail.com> | 2014-03-30 14:52:41 +0800 |
commit | 2359b0f927c4a75f60031818602913a85c7d0c4a (patch) | |
tree | e006de4e862d32462d80c1a37df5749bbb100e1f /angular-multi-select.js | |
parent | c4d841575715ddff4d766be35b47e092977f82ed (diff) | |
download | angular-multi-select-2359b0f927c4a75f60031818602913a85c7d0c4a.zip angular-multi-select-2359b0f927c4a75f60031818602913a85c7d0c4a.tar.gz angular-multi-select-2359b0f927c4a75f60031818602913a85c7d0c4a.tar.bz2 |
Bug fix, brought back the 'None selected' label
Diffstat (limited to 'angular-multi-select.js')
-rw-r--r-- | angular-multi-select.js | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/angular-multi-select.js b/angular-multi-select.js index 72dae75..f96d0f4 100644 --- a/angular-multi-select.js +++ b/angular-multi-select.js @@ -103,37 +103,42 @@ angular.module( 'multi-select', ['ng'] ).directive( 'multiSelect' , [ '$timeout' } } }); - + // Push into output model if ( typeof attrs.outputModel !== 'undefined' ) { $scope.outputModel = angular.copy( $scope.selectedItems ); } - var tempMaxLabels = $scope.selectedItems.length; - if ( typeof $scope.maxLabels !== 'undefined' && $scope.maxLabels !== '' && $scope.maxLabels !== "0" ) { - tempMaxLabels = $scope.maxLabels; + // Write label... + if ( $scope.selectedItems.length === 0 ) { + $scope.buttonLabel = 'None selected'; } + else { + var tempMaxLabels = $scope.selectedItems.length; + if ( typeof $scope.maxLabels !== 'undefined' && $scope.maxLabels !== '' && $scope.maxLabels !== "0" ) { + tempMaxLabels = $scope.maxLabels; + } - // If max amount of labels displayed.. - if ( $scope.selectedItems.length > tempMaxLabels ) { - $scope.more = true; - } - else { - $scope.more = false; - } + // If max amount of labels displayed.. + if ( $scope.selectedItems.length > tempMaxLabels ) { + $scope.more = true; + } + else { + $scope.more = false; + } - // Write label... - angular.forEach( $scope.selectedItems, function( value, key ) { - if ( typeof value !== 'undefined' ) { - if ( ctr < tempMaxLabels ) { - $scope.buttonLabel += ( $scope.buttonLabel.length > 0 ? ', ' : '') + $scope.writeLabel( value ); + angular.forEach( $scope.selectedItems, function( value, key ) { + if ( typeof value !== 'undefined' ) { + if ( ctr < tempMaxLabels ) { + $scope.buttonLabel += ( $scope.buttonLabel.length > 0 ? ', ' : '') + $scope.writeLabel( value ); + } + ctr++; } - ctr++; - } - }); + }); - if ( $scope.more === true ) { - $scope.buttonLabel += ', ... (Total: ' + $scope.selectedItems.length + ')'; + if ( $scope.more === true ) { + $scope.buttonLabel += ', ... (Total: ' + $scope.selectedItems.length + ')'; + } } } |