Skip to content

Commit

Permalink
Patches typeahead.bundle.js to fix an error in results shown
Browse files Browse the repository at this point in the history
When the server returns less suggestions than what is configured as limit for
the autocompleter, it only shows the first one, not adding the others to the
suggestions list. This is a bug detected in Typeahead library, see
twitter/typeahead.js#1232.

This library seems not to be actively maintained by Twitter anymore (latest commits
were in 2015). I've taken the patch from a fork, Corejs Typeahead.js
https://github.com/corejavascript/typeahead.js

https://github.com/corejavascript/typeahead.js/blob/107a9b0d002e549be746d93a1fbcde05853d745a/src/typeahead/dataset.js#L269-L281
  • Loading branch information
juanluisrp committed Dec 6, 2018
1 parent fb632ab commit 744130a
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1718,11 +1718,15 @@
}
function async(suggestions) {
suggestions = suggestions || [];

// if the update has been canceled or if the query has changed
// do not render the suggestions as they've become outdated
if (!canceled && rendered < that.limit) {
that.cancel = $.noop;
rendered += suggestions.length;
that._append(query, suggestions.slice(0, that.limit - rendered));
that.async && that.trigger("asyncReceived", query);
var idx = Math.abs(rendered - that.limit);
rendered += idx;
that._append(query, suggestions.slice(0, idx));
that.async && that.trigger('asyncReceived', query, that.name);
}
}
},
Expand Down

0 comments on commit 744130a

Please sign in to comment.