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

Cast other data types to string when highlighting #1027

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ var uis = angular.module('ui.select', [])
}

return function(matchItem, query) {
matchItem = String(matchItem);
return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '<span class="ui-select-highlight">$&</span>') : matchItem;
};
})
Expand Down
19 changes: 19 additions & 0 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,25 @@ describe('ui-select tests', function() {
expect(scope.selection.selected).toBe('Samantha');
});

it('should highlight matched value correctly when it is a number', function() {
var el = compileTemplate(
'<ui-select ng-model="selection.selected"> \
<ui-select-match placeholder="Pick one...">{{$select.selected.age}}</ui-select-match> \
<ui-select-choices repeat="person.age as person in people | filter: $select.search"> \
<div ng-bind-html="person.age | highlight: $select.search"></div> \
</ui-select-choices> \
</ui-select>'
);
openDropdown(el);
setSearchText(el, '43');

var choices = $(el).find('.ui-select-choices-row');
expect(choices.length).toEqual(1);

clickItem(el, '43');
expect(scope.selection.selected).toBe(43);
});

it('should invoke select callback on select', function () {

scope.onSelectFn = function ($item, $model, $label) {
Expand Down