corejavascript / corejavascript/typeahead.js

How to update typeahead when fetching new data?

Open
#161 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
968
Forks
231
PR merge metrics
No merged PRs in 30d

Description

In 0.1.11 there was an "update" method for the typeahead instance, in 1.2.0 this method was removed from the source.

I am updating request string on custom click (adding some custom params, but the query is same) and fetching new data from server.
Before i just called "update" method with force:true

`$(selector).typeahead('update', true)`

Now i am at loss with this situation, i can call search from Bloodhound with query string and custom parameters on prefetch, but i need to reload typeahead dropdown result data at all.

```
var bloodhoundOptions, opts, typeaheadopts;
bloodhoundOptions = {
remote: {
url: this.options.accountsUrl,
prepare: _prepareRequest.bind(this),
transform: _transformResult.bind(this),
rateLimitWait: 500
}
};
this.driver = Typeahead.createBloodhound(bloodhoundOptions);
typeaheadopts = {
minLength: 2,
hint: false,
highlight: true
};
opts = {
display: 'text',
source: this.driver,
limit: Number.MAX_VALUE,
templates: ...........
};
```

```this.widgetTh = new Typeahead(selector, typeaheadopts, opts);```

```
var async, sync, query;
sync = (function(_this) {
return function(data) {};
})(this);
async = (function(_this) {
return function(data) {
_this.driver.add(data);
????? How to update typeahead ????
};
})(this);
return this.driver.search(query, sync, async);
```

Is there a way to force update typeahead with new data without reinitializing and destroying current widget instance?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.