Skip to content

Commit 7cde891

Browse files
author
Sebastian Hammerl
committed
Added max-width attribute
- This defines the max width of the drop down button in pixels. Ellipsis is used if text is cut off. Also added the title attribute with the complete content of the currently selected item
1 parent dcd6543 commit 7cde891

File tree

7 files changed

+42
-8
lines changed

7 files changed

+42
-8
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Sebastian Hammerl, Getslash GmbH
3+
Copyright (c) 2015 Sebastian Hammerl, Getslash GmbH
44
Copyright (c) 2014 Amitava Saha
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ Add "ui.multiselect" to your modules list. Then you can use it like follows:
2626
data-multiple="true" // true for multi-select mode
2727
data-compare-by="id" // set key to compare objects, otherwise is has to be equal to options
2828
scroll-after-rows="5" // Show scroll bar after 5 rows
29-
filter-after-rows="5"> // Show filter input after 5 rows
29+
filter-after-rows="5 // Show filter input after 5 rows
30+
max-width="100"> // The maximum width of the multiselect dropdown button
3031
</multiselect>
3132
```
3233

@@ -46,7 +47,7 @@ $ karma start
4647

4748
### License
4849

49-
Copyright (c) 2014 Sebastian Hammerl, Getslash GmbH
50+
Copyright (c) 2015 Sebastian Hammerl, Getslash GmbH
5051

5152
Copyright (c) 2014 Amitava Saha
5253

angular-bootstrap-multiselect.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ angular.module("ui.multiselect", ["multiselect.tpl.html"])
3434
var isMultiple = attrs.multiple ? true : false;
3535
var compareByKey = attrs.compareBy;
3636
var scrollAfterRows = attrs.scrollAfterRows;
37+
var maxWidth = attrs.maxWidth;
3738
var required = false;
3839
var scope = originalScope.$new();
3940
scope.filterAfterRows = attrs.filterAfterRows;
@@ -48,6 +49,9 @@ angular.module("ui.multiselect", ["multiselect.tpl.html"])
4849
if(scrollAfterRows !== undefined && parseInt(scrollAfterRows).toString() === scrollAfterRows) {
4950
scope.ulStyle = {"max-height": (scrollAfterRows*26+14)+"px", "overflow-y": "auto", "overflow-x": "hidden"};
5051
}
52+
if(maxWidth !== undefined && parseInt(maxWidth).toString() === maxWidth) {
53+
scope.maxWidth = {"max-width": maxWidth + "px"};
54+
}
5155

5256
originalScope.$on("$destroy", function() {
5357
scope.$destroy();
@@ -309,8 +313,8 @@ angular.module("ui.multiselect", ["multiselect.tpl.html"])
309313
angular.module("multiselect.tpl.html", []).run(["$templateCache", function($templateCache) {
310314
$templateCache.put("multiselect.tpl.html",
311315
"<div class=\"btn-group\">\n" +
312-
" <button type=\"button\" class=\"btn btn-default dropdown-toggle\" ng-click=\"toggleSelect()\" ng-disabled=\"disabled\" ng-class=\"{'error': !valid()}\">\n" +
313-
" {{header}} <span class=\"caret\"></span>\n" +
316+
" <button title=\"{{header}}\" type=\"button\" class=\"btn btn-default dropdown-toggle\" ng-click=\"toggleSelect()\" ng-disabled=\"disabled\" ng-class=\"{'error': !valid()}\">\n" +
317+
" <div ng-style=\"maxWidth\" style=\"padding-right: 13px; overflow: hidden; text-overflow: ellipsis;\">{{header}}</div><span class=\"caret\" style=\"position:absolute;right:10px;top:14px;\"></span>\n" +
314318
" </button>\n" +
315319
" <ul class=\"dropdown-menu\" style=\"margin-bottom:30px;padding-left:5px;padding-right:5px;\" ng-style=\"ulStyle\">\n" +
316320
" <input ng-show=\"items.length > filterAfterRows\" ng-model=\"filter\" style=\"padding: 0px 3px;margin-right: 15px; margin-bottom: 4px;\" placeholder=\"Type to filter options\">" +

app.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ angular.module("angular-bootstrap-multiselect-test", ["ui.multiselect"]).control
1414
name: "Apples",
1515
bla: "blubb"
1616
},
17+
"",
1718
""
1819
];
1920
$scope.multiselectModel = [
@@ -80,4 +81,11 @@ angular.module("angular-bootstrap-multiselect-test", ["ui.multiselect"]).control
8081
name: "Peaches"
8182
}
8283
];
84+
$scope.selectOptionsLongEntries = [
85+
"ThisIsATestWithVeryLongEntries11111",
86+
"ThisIsATestWithVeryLongEntries22222",
87+
"ThisIsATestWithVeryLongEntries33333",
88+
"ThisIsATestWithVeryLongEntries44444",
89+
"ThisIsATestWithVeryLongEntries55555",
90+
];
8391
});

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-bootstrap-multiselect",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"authors": [
55
"Sebastian Hammerl, Getslash GmbH",
66
"Amitava Saha"

index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ <h3>Single select Long List, scroll after 5 rows, filter after 5 rows</h3>
100100
&gt;&lt;/multiselect&gt</pre>
101101
<br>
102102

103+
<h3>Single select, very long entries</h3>
104+
<multiselect ng-model="singleselectModel[6]" options="c for c in selectOptionsLongEntries" data-multiple="false" max-width="100"></multiselect>
105+
<br><br>
106+
Model: {{singleselectModel[6]}}
107+
<br><br>
108+
<pre>&lt;multiselect
109+
ng-model="singleselectModel[6]"
110+
options="c for c in selectOptionsLongEntries"
111+
data-multiple="false"
112+
max-width="100"
113+
&gt;&lt;/multiselect&gt</pre>
114+
<br>
115+
103116

104117

105118
<h3>Multi select</h3>
@@ -179,6 +192,7 @@ <h3>app.js:</h3>
179192
name: "Apples",
180193
bla: "blubb"
181194
},
195+
"",
182196
""
183197
];
184198
$scope.multiselectModel = [
@@ -245,6 +259,13 @@ <h3>app.js:</h3>
245259
name: "Peaches"
246260
}
247261
];
262+
$scope.selectOptionsLongEntries = [
263+
"ThisIsATestWithVeryLongEntries11111",
264+
"ThisIsATestWithVeryLongEntries22222",
265+
"ThisIsATestWithVeryLongEntries33333",
266+
"ThisIsATestWithVeryLongEntries44444",
267+
"ThisIsATestWithVeryLongEntries55555",
268+
];
248269
});
249270
</pre>
250271

karma.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module.exports = function(config) {
55
config.set({
6-
basePath : '',
6+
basePath : "",
77
frameworks : ["ng-scenario"],
88
files : [
99
"angular-bootstrap-multiselect.js",
@@ -13,7 +13,7 @@ module.exports = function(config) {
1313
],
1414
exclude : [],
1515
preprocessors: {},
16-
reporters : ['progress'],
16+
reporters : ["progress"],
1717
port : 8001,
1818
colors : true,
1919
logLevel : config.LOG_INFO,

0 commit comments

Comments
 (0)