Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 7a45bf2

Browse files
author
user378230
committed
fix(uiSelectMultiple) support data-multiple attribute
uiSelectMatch was a special case where the non-normalised attribute is checked, therefore using data-multiple resulted in the single select match template being loaded. Closes #1451
1 parent 68eccac commit 7a45bf2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/uiSelectMatchDirective.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) {
1010

1111
// Gets theme attribute from parent (ui-select)
1212
var theme = tElement.parent().attr('theme') || uiSelectConfig.theme;
13-
var multi = tElement.parent().attr('multiple');
13+
14+
var multi = angular.isDefined(tElement.parent().attr('multiple')) ||
15+
angular.isDefined(tElement.parent().attr('data-multiple'));
16+
1417
return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html');
1518
},
1619
link: function(scope, element, attrs, $select) {

test/select.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,6 +1603,25 @@ describe('ui-select tests', function() {
16031603
expect(el.find('.ui-select-match-item').length).toBe(0);
16041604
});
16051605

1606+
it('should render intial state with data-multiple attribute', function () {
1607+
// ensure match template has been loaded by having more than one selection
1608+
scope.selection.selectedMultiple = [scope.people[0], scope.people[1]];
1609+
1610+
var el = compileTemplate(
1611+
'<ui-select data-multiple ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
1612+
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
1613+
<ui-select-choices repeat="person in people | filter: $select.search"> \
1614+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
1615+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
1616+
</ui-select-choices> \
1617+
</ui-select>'
1618+
);
1619+
1620+
expect(el).toHaveClass('ui-select-multiple');
1621+
expect(el.scope().$select.selected.length).toBe(2);
1622+
expect(el.find('.ui-select-match-item').length).toBe(2);
1623+
});
1624+
16061625
it('should set model as an empty array if ngModel isnt defined after an item is selected', function () {
16071626

16081627
// scope.selection.selectedMultiple = [];

0 commit comments

Comments
 (0)