diff --git a/src/app/component/angularjs-dropdown-multiselect.controller.js b/src/app/component/angularjs-dropdown-multiselect.controller.js index f6324298..e837cc99 100644 --- a/src/app/component/angularjs-dropdown-multiselect.controller.js +++ b/src/app/component/angularjs-dropdown-multiselect.controller.js @@ -230,6 +230,10 @@ export default function dropdownMultiselectController( function getButtonText() { if ($scope.settings.dynamicTitle && $scope.selectedModel && $scope.selectedModel.length > 0) { + if (angular.isFunction($scope.settings.smartButtonTextProvider)) { + return $scope.settings.smartButtonTextProvider($scope.selectedModel); + } + if ($scope.settings.smartButtonMaxItems > 0) { const paddingWidth = 12 * 2; const borderWidth = 1 * 2; diff --git a/src/app/main/main.controller.js b/src/app/main/main.controller.js index c9edb050..581d4a8e 100644 --- a/src/app/main/main.controller.js +++ b/src/app/main/main.controller.js @@ -324,5 +324,18 @@ export default class MainController { $scope.idPropertySettings = { idProperty: 'id', }; + + $scope.smartButtonTextProviderModel = [ + ]; + $scope.smartButtonTextProviderData = [ + { id: 1, label: 'David' }, + { id: 2, label: 'Jhon' }, + { id: 3, label: 'Danny' }, + ]; + $scope.smartButtonTextProviderSettings = { + smartButtonTextProvider(selectionArray) { + return selectionArray.length + 2; + }, + }; } } diff --git a/src/app/main/main.template.html b/src/app/main/main.template.html index 32d4bc94..999dbce6 100644 --- a/src/app/main/main.template.html +++ b/src/app/main/main.template.html @@ -1058,6 +1058,48 @@ <h3>Code</h3> ]; $scope.idPropertySettings = { idProperty: 'id', +}; + </div> + </div> + </div> + </div> + <div uib-accordion-group heading="Button text provider"> + <div class="row"> + <div class="col-xs-12"> + When there is a selection this method will be called with the selection as a parameter. The function is supposed to return the text that you want to display on the button. + </div> + </div> + <div class="row"> + <div class="col-xs-12 col-sm-6"> + <h3>Demo</h3> + <div class="well"> + <div ng-dropdown-multiselect="" options="smartButtonTextProviderData" selected-model="smartButtonTextProviderModel" extra-settings="smartButtonTextProviderSettings"> + </div> + </div> + </div> + <div class="col-xs-12 col-sm-6"> + <h3>The model:</h3> + <pre>{{smartButtonTextProviderModel|json}}</pre> + </div> + </div> + <div class="row"> + <div class="col-md-12"> + <h3>Code</h3> + <div hljs language="javascript"> +// HTML +<div ng-dropdown-multiselect="" options="idPropertyData" selected-model="idPropertyModel" extra-settings="idPropertySettings"> +</div> + +$scope.smartButtonTextProviderModel = []; +$scope.smartButtonTextProviderData = [ + { id: 1, label: 'David' }, + { id: 2, label: 'Jhon' }, + { id: 3, label: 'Danny' }, +]; +$scope.idPropertySettings = { + smartButtonTextProvider(selectionArray) { + return selectionArray.length + 2; + }, }; </div> </div>