Skip to content

Commit f756a44

Browse files
author
Tomas Kirda
committed
Allow to override formatGroup callback via options, closes #505, #387
1 parent 19a9790 commit f756a44

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ The standard jquery.autocomplete.js file is around 13KB when minified.
5050
* `beforeRender`: `function (container, suggestions) {}` called before displaying the suggestions. You may manipulate suggestions DOM before it is displayed.
5151
* `formatResult`: `function (suggestion, currentValue) {}` custom function to
5252
format suggestion entry inside suggestions container, optional.
53+
* `formatGroup`: `function (suggestion, category) {}` custom function to
54+
format group header, optional.
5355
* `groupBy`: property name of the suggestion `data` object, by which results should be grouped.
5456
* `maxHeight`: Maximum height of the suggestions container in pixels. Default: `300`.
5557
* `width`: Suggestions container width in pixels, e.g.: 300, `flex` for max suggestion size and `auto` takes input field width. Default: `auto`

src/jquery.autocomplete.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
deferRequestBy: 0,
6868
params: {},
6969
formatResult: Autocomplete.formatResult,
70+
formatGroup: Autocomplete.formatGroup,
7071
delimiter: null,
7172
zIndex: 9999,
7273
type: 'GET',
@@ -143,6 +144,10 @@
143144
.replace(/&lt;(\/?strong)&gt;/g, '<$1>');
144145
};
145146

147+
Autocomplete.formatGroup = function (suggestion, category) {
148+
return '<div class="autocomplete-group"><strong>' + category + '</strong></div>';
149+
};
150+
146151
Autocomplete.prototype = {
147152

148153
killerFn: null,
@@ -671,7 +676,7 @@
671676

672677
category = currentCategory;
673678

674-
return '<div class="autocomplete-group"><strong>' + category + '</strong></div>';
679+
return options.formatGroup(suggestion, category);
675680
};
676681

677682
if (options.triggerSelectOnValidInput && that.isExactMatch(value)) {

0 commit comments

Comments
 (0)