Skip to content

Commit e241976

Browse files
committed
Merge pull request #52 from DanielApt/patch-2
Fix for incorrect limit with remote
2 parents 43ac410 + bf60a90 commit e241976

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/typeahead/dataset.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ var Dataset = (function() {
269269
// do not render the suggestions as they've become outdated
270270
if (!canceled && rendered < that.limit) {
271271
that.cancel = $.noop;
272-
that._append(query, suggestions.slice(0, that.limit - rendered));
273-
rendered += suggestions.length;
274-
275-
that.async && that.trigger('asyncReceived', query);
272+
var idx = Math.abs(rendered - that.limit);
273+
rendered += idx;
274+
that._append(query, suggestions.slice(0, idx));
275+
that.async && that.trigger("asyncReceived", query);
276276
}
277277
}
278278
},

test/typeahead/dataset_spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ describe('Dataset', function() {
225225
});
226226

227227
it('should respect limit option in regard to async', function() {
228+
this.dataset.limit = 6;
228229
this.dataset.async = true;
229230
this.source.andCallFake(fakeGetWithAsyncSuggestions);
230231

@@ -233,7 +234,7 @@ describe('Dataset', function() {
233234
waits(100);
234235

235236
runs(function() {
236-
expect(this.dataset.$el.find('.tt-suggestion')).toHaveLength(5);
237+
expect(this.dataset.$el.find('.tt-suggestion')).toHaveLength(6);
237238
});
238239
});
239240

0 commit comments

Comments
 (0)