From a2726eda9c1885d5df82b9c77c3c81b805bcfe41 Mon Sep 17 00:00:00 2001 From: pkempenaers Date: Tue, 25 Apr 2017 22:16:24 +0200 Subject: [PATCH] Added the smartButtonTextProvider setting --- ...gularjs-dropdown-multiselect.controller.js | 4 ++ src/app/main/main.controller.js | 13 ++++++ src/app/main/main.template.html | 42 +++++++++++++++++++ 3 files changed, 59 insertions(+) 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 @@

Code

]; $scope.idPropertySettings = { idProperty: 'id', +}; + + + + +
+
+
+ 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. +
+
+
+
+

Demo

+
+
+
+
+
+
+

The model:

+
{{smartButtonTextProviderModel|json}}
+
+
+
+
+

Code

+
+// HTML +
+
+ +$scope.smartButtonTextProviderModel = []; +$scope.smartButtonTextProviderData = [ + { id: 1, label: 'David' }, + { id: 2, label: 'Jhon' }, + { id: 3, label: 'Danny' }, +]; +$scope.idPropertySettings = { + smartButtonTextProvider(selectionArray) { + return selectionArray.length + 2; + }, };