Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ A suggestion is an object of the form `{ value: string, data: any }`. `data`
is passed through untouched to `formatResult`, `onSelect`, and the grouping
key resolver.

To match regardless of accents (so `cafe` finds `Café`), pass a custom
`lookupFilter` that strips diacritics from both sides:

```js
const fold = (text) => text.normalize('NFD').replace(/\p{M}/gu, '').toLowerCase();

$('#autocomplete').devbridgeAutocomplete({
lookup: countries,
lookupFilter: (suggestion, query) => fold(suggestion.value).includes(fold(query)),
});
```

The default `formatResult` still highlights only exact (case-insensitive)
matches, so an accent-folded match is listed but not highlighted.

### Ajax-only settings

| Setting | Default | Description |
Expand Down Expand Up @@ -212,6 +227,20 @@ Minimal CSS to get started:
`cursor: pointer` on `.autocomplete-suggestion` is required for tap-to-select
to fire on mobile Safari — see issue #542.

To highlight matches with a different element, e.g. `<mark>`, wrap the
default formatter. It escapes everything except its own `<strong>` tags, so
swapping the tag is safe:

```js
$('#autocomplete').devbridgeAutocomplete({
lookup: countries,
formatResult: (suggestion, currentValue) =>
$.Autocomplete.defaults
.formatResult(suggestion, currentValue)
.replace(/<(\/?)strong>/g, '<$1mark>'),
});
```

## Response format

The server must respond with JSON in this shape:
Expand Down
Loading