Skip to content

Commit e572acf

Browse files
author
Tomas Kirda
committed
Do not try to highlight suggestion if current value is empty, resolves #434
Prevents inserting strong tag after each character when input value is empty.
1 parent fef68b6 commit e572acf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/jquery.autocomplete.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,13 @@
127127
$.Autocomplete = Autocomplete;
128128

129129
Autocomplete.formatResult = function (suggestion, currentValue) {
130-
var pattern = '(' + utils.escapeRegExChars(currentValue) + ')';
130+
// Do not replace anything if there current value is empty
131+
if (!currentValue) {
132+
return suggestion.value;
133+
}
131134

135+
var pattern = '(' + utils.escapeRegExChars(currentValue) + ')';
136+
132137
return suggestion.value
133138
.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>')
134139
.replace(/&/g, '&amp;')

0 commit comments

Comments
 (0)