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

Commit ec914d4

Browse files
author
user378230
committed
fix(uiSelectChoices) broken id interpolation
The id attribute on ui-select-choices-row is no longer interpolated correctly when using ui select with angular v1.5+. This change switches to using ng-attr-id to ensure the id value is correctly interpolated before being assigned to the element. Fixes #1522
1 parent 04eb3f6 commit ec914d4

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/bootstrap/choices.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<li class="ui-select-choices-group" id="ui-select-choices-{{ $select.generatedId }}" >
55
<div class="divider" ng-show="$select.isGrouped && $index > 0"></div>
66
<div ng-show="$select.isGrouped" class="ui-select-choices-group-label dropdown-header" ng-bind="$group.name"></div>
7-
<div id="ui-select-choices-row-{{ $select.generatedId }}-{{$index}}" class="ui-select-choices-row"
7+
<div ng-attr-id="ui-select-choices-row-{{ $select.generatedId }}-{{$index}}" class="ui-select-choices-row"
88
ng-class="{active: $select.isActive(this), disabled: $select.isDisabled(this)}" role="option">
99
<a href="" class="ui-select-choices-row-inner"></a>
1010
</div>

src/select2/choices.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div ng-show="$select.choiceGrouped($group)" class="ui-select-choices-group-label select2-result-label" ng-bind="$group.name"></div>
44
<ul role="listbox"
55
id="ui-select-choices-{{ $select.generatedId }}" ng-class="{'select2-result-sub': $select.choiceGrouped($group), 'select2-result-single': !$select.choiceGrouped($group) }">
6-
<li role="option" id="ui-select-choices-row-{{ $select.generatedId }}-{{$index}}" class="ui-select-choices-row" ng-class="{'select2-highlighted': $select.isActive(this), 'select2-disabled': $select.isDisabled(this)}">
6+
<li role="option" ng-attr-id="ui-select-choices-row-{{ $select.generatedId }}-{{$index}}" class="ui-select-choices-row" ng-class="{'select2-highlighted': $select.isActive(this), 'select2-disabled': $select.isDisabled(this)}">
77
<div class="select2-result-label ui-select-choices-row-inner"></div>
88
</li>
99
</ul>

test/select.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,23 @@ describe('ui-select tests', function() {
399399
expect(getMatchLabel(el)).toEqual('Samantha');
400400
});
401401

402+
it('should correctly render initial state with track by $index', function () {
403+
404+
var el = compileTemplate(
405+
'<ui-select ng-model="selection.selected"> \
406+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
407+
<ui-select-choices repeat="person in people track by $index"> \
408+
{{person.email}} \
409+
</ui-select-choices> \
410+
</ui-select>'
411+
);
412+
413+
openDropdown(el);
414+
415+
var generatedId = el.scope().$select.generatedId;
416+
expect($(el).find('[id$="row-' + generatedId + '-0"]').length).toEqual(1);
417+
});
418+
402419
it('should utilize wrapper directive ng-model', function() {
403420
var el = compileTemplate('<wrapper-ui-select ng-model="selection.selected"/>');
404421
scope.selection.selected = { name: 'Samantha', email: 'something different than array source', group: 'bar', age: 30 };

0 commit comments

Comments
 (0)