From 5d8cb94566d8d4a2485febd2a1fba2935b6a1282 Mon Sep 17 00:00:00 2001 From: Slawek Kolodziej Date: Thu, 18 Jun 2015 23:12:51 +0200 Subject: [PATCH] Cast other data types to string when highlighting --- src/common.js | 1 + test/select.spec.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/common.js b/src/common.js index efc7a5b9f..aa3d1edd4 100644 --- a/src/common.js +++ b/src/common.js @@ -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'), '$&') : matchItem; }; }) diff --git a/test/select.spec.js b/test/select.spec.js index 2ba86fb2a..381d47ddf 100644 --- a/test/select.spec.js +++ b/test/select.spec.js @@ -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( + ' \ + {{$select.selected.age}} \ + \ +
\ +
\ +
' + ); + 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) {