Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit 2d39f77

Browse files
committed
Once again, fixing handling of numeric data
1 parent 1b69262 commit 2d39f77

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

angucomplete-alt.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,10 @@
236236
// Escape user input to be treated as a literal string within a regular expression
237237
re = new RegExp(str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'i');
238238
if (!target) { return; }
239-
matches = target.toString().match(re);
239+
if (!target.match || !target.replace) { target = target.toString(); }
240+
matches = target.match(re);
240241
if (matches) {
241-
result = target.toString().replace(re,
242+
result = target.replace(re,
242243
'<span class="'+ scope.matchClass +'">'+ matches[0] +'</span>');
243244
}
244245
else {

test/angucomplete-alt.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,5 +1582,31 @@ describe('angucomplete-alt', function() {
15821582
$timeout.flush();
15831583
expect(element.find('.angucomplete-row').length).toBe(1);
15841584
});
1585+
1586+
it('should handle match class, multiple matches ', function() {
1587+
var element = angular.element('<div angucomplete-alt id="ex1" placeholder="Search IDs" selected-object="selectedUser" local-data="users" search-fields="id" title-field="id" description-field="amount" minlength="2" match-class="highlight"/>');
1588+
$scope.selectedUser = undefined;
1589+
$scope.users = [
1590+
{name: 'Alice', id: 100, amount: 100},
1591+
{name: 'Bob', id: 101, amount: 123},
1592+
{name: 'Chris', id: 110, amount: 200}
1593+
];
1594+
$compile(element)($scope);
1595+
$scope.$digest();
1596+
var inputField = element.find('#ex1_value');
1597+
var e = $.Event('keyup');
1598+
1599+
e.which = '1'.charCodeAt(0);
1600+
inputField.val(1);
1601+
inputField.trigger('input');
1602+
inputField.trigger(e);
1603+
1604+
e.which = '0'.charCodeAt(0);
1605+
inputField.val(10);
1606+
inputField.trigger('input');
1607+
inputField.trigger(e);
1608+
$timeout.flush();
1609+
expect(element.find('.angucomplete-row').length).toBe(3);
1610+
});
15851611
});
15861612
});

0 commit comments

Comments
 (0)