2
0
mirror of https://github.com/devbridge/jQuery-Autocomplete.git synced 2024-11-25 06:07:45 +00:00

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.
This commit is contained in:
Tomas Kirda 2015-11-01 19:25:25 -06:00
parent fef68b6e4c
commit e572acf56f

View File

@ -127,8 +127,13 @@
$.Autocomplete = Autocomplete;
Autocomplete.formatResult = function (suggestion, currentValue) {
var pattern = '(' + utils.escapeRegExChars(currentValue) + ')';
// Do not replace anything if there current value is empty
if (!currentValue) {
return suggestion.value;
}
var pattern = '(' + utils.escapeRegExChars(currentValue) + ')';
return suggestion.value
.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>')
.replace(/&/g, '&amp;')