Skip to content

Commit 86b8e8a

Browse files
author
pkempenaers
committed
Merge branch 'develop'
2 parents 1dfd972 + 314b313 commit 86b8e8a

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

src/app/component/dropdown-toggle/dropdown-toggle.template.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
ng-click="$ctrl.toggleDropdown()"
33
ng-keydown="$ctrl.dropdownToggleKeyDown($event)">
44
<span class="selection-text">
5-
<span ng-if="$ctrl.selectedOptions.length === 0">
6-
Select {{$ctrl.texts.optionNames}}
7-
</span>
8-
<span ng-if="$ctrl.selectedOptions.length > 0">
9-
{{$ctrl.selectedOptions.length}} {{$ctrl.texts.optionNames}} selected
10-
</span>
5+
{{$ctrl.getButtonText()}}
116
</span>
127
<span ng-class="$ctrl.settings.dropdownToggleIconClass"></span>
138
</button>

src/app/component/dropdownTree.controller.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@
7878
}
7979
}
8080

81+
$doCheck() {
82+
if (angular.isDefined(this.externalSelection) &&
83+
!this.dropdownTreeService.areSameSelections(this.externalSelection, this.selectedOptions)) {
84+
this.selectedOptions = angular.extend([], this.externalSelection);
85+
}
86+
}
87+
8188
toggleDropdown() {
8289
this.open = !this.open;
8390
if (this.open) {
@@ -239,4 +246,14 @@
239246
focusSelf() {
240247
this.$element.find('button')[0].focus();
241248
}
249+
250+
getButtonText() {
251+
if (angular.isFunction(this.settings.getButtonText)) {
252+
return this.settings.getButtonText(this.selectedOptions, this.options);
253+
}
254+
if (this.selectedOptions.length === 0) {
255+
return `Select ${this.texts.optionNames}`;
256+
}
257+
return `${this.selectedOptions.length} ${this.texts.optionNames} selected`;
258+
}
242259
}

src/app/main/main.controller.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default class MainController {
1+
export default class MainController {
22
constructor($log) {
33
'ngInject';
44

@@ -37,6 +37,12 @@ export default class MainController {
3737
disableSearch: false,
3838
closeOnBlur: true,
3939
folderSelectable: true,
40+
getButtonText(selection) {
41+
if (selection.length > 0) {
42+
return selection.map(v => v.name).join(', ');
43+
}
44+
return 'Select items';
45+
},
4046
};
4147
}
4248

src/app/main/main.template.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ <h3>Settings</h3>
253253
be passed from where in the array an option should be removed (front/back)
254254
</td>
255255
</tr>
256+
<tr>
257+
<td>getButtonText</td>
258+
<td>undefined</td>
259+
<td>function</td>
260+
<td>
261+
Should return the string that you want to display in the dropdown toggle. Is called with as first argument the current selection and second argument the selection-array.
262+
</td>
263+
</tr>
256264
</tbody>
257265
</table>
258266
</div>

0 commit comments

Comments
 (0)