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

Commit 5a42bef

Browse files
committed
Merge pull request #1533 from user378230/fix-id-attr
fix(uiSelectChoices) broken id interpolation
2 parents 331b256 + b6219d2 commit 5a42bef

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
@@ -412,6 +412,23 @@ describe('ui-select tests', function() {
412412
expect(getMatchLabel(el)).toEqual('Samantha');
413413
});
414414

415+
it('should correctly render initial state with track by $index', function () {
416+
417+
var el = compileTemplate(
418+
'<ui-select ng-model="selection.selected"> \
419+
<ui-select-match placeholder="Pick one...">{{$select.selected.name}}</ui-select-match> \
420+
<ui-select-choices repeat="person in people track by $index"> \
421+
{{person.email}} \
422+
</ui-select-choices> \
423+
</ui-select>'
424+
);
425+
426+
openDropdown(el);
427+
428+
var generatedId = el.scope().$select.generatedId;
429+
expect($(el).find('[id="ui-select-choices-row-' + generatedId + '-0"]').length).toEqual(1);
430+
});
431+
415432
it('should utilize wrapper directive ng-model', function() {
416433
var el = compileTemplate('<wrapper-ui-select ng-model="selection.selected"/>');
417434
scope.selection.selected = { name: 'Samantha', email: 'something different than array source', group: 'bar', age: 30 };

0 commit comments

Comments
 (0)