Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Commit

Permalink
Added the smartButtonTextProvider setting
Browse files Browse the repository at this point in the history
  • Loading branch information
pkempenaers committed Apr 25, 2017
1 parent e7e6003 commit a2726ed
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions src/app/main/main.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
};
}
}
42 changes: 42 additions & 0 deletions src/app/main/main.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit a2726ed

Please sign in to comment.