mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2025-01-23 07:08:26 +00:00
onSearchComplete
receives suggestions as second parameter
Added functionality and it’s specs. In line 648 there is no need to serialise `result` as it will be already serialised on line `511`.
This commit is contained in:
parent
0ee2ba58dc
commit
0b7f00dad0
@ -136,12 +136,15 @@ describe('Autocomplete', function () {
|
||||
it('Should execute onSearchComplete', function () {
|
||||
var input = document.createElement('input'),
|
||||
completeQuery,
|
||||
mockupSuggestion = { value: 'A', data: 'A' },
|
||||
resultSuggestions,
|
||||
ajaxExecuted = false,
|
||||
url = '/test-completed',
|
||||
autocomplete = new $.Autocomplete(input, {
|
||||
serviceUrl: url,
|
||||
onSearchComplete: function (query) {
|
||||
onSearchComplete: function (query, suggestions) {
|
||||
completeQuery = query;
|
||||
resultSuggestions = suggestions;
|
||||
}
|
||||
});
|
||||
|
||||
@ -153,7 +156,7 @@ describe('Autocomplete', function () {
|
||||
var query = settings.data.query,
|
||||
response = {
|
||||
query: query,
|
||||
suggestions: []
|
||||
suggestions: [mockupSuggestion]
|
||||
};
|
||||
this.responseText = JSON.stringify(response);
|
||||
}
|
||||
@ -169,6 +172,8 @@ describe('Autocomplete', function () {
|
||||
runs(function () {
|
||||
expect(ajaxExecuted).toBe(true);
|
||||
expect(completeQuery).toBe('A');
|
||||
expect(resultSuggestions[0].value).toBe('A');
|
||||
expect(resultSuggestions[0].data).toBe('A');
|
||||
});
|
||||
});
|
||||
|
||||
@ -649,4 +654,4 @@ describe('Autocomplete', function () {
|
||||
expect(ajaxCount).toBe(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -506,9 +506,11 @@
|
||||
type: options.type,
|
||||
dataType: options.dataType
|
||||
}).done(function (data) {
|
||||
var result;
|
||||
that.currentRequest = null;
|
||||
that.processResponse(data, q, cacheKey);
|
||||
options.onSearchComplete.call(that.element, q);
|
||||
result = options.transformResult(data);
|
||||
that.processResponse(result, q, cacheKey);
|
||||
options.onSearchComplete.call(that.element, q, result.suggestions);
|
||||
}).fail(function (jqXHR, textStatus, errorThrown) {
|
||||
options.onSearchError.call(that.element, q, jqXHR, textStatus, errorThrown);
|
||||
});
|
||||
@ -642,10 +644,9 @@
|
||||
return suggestions;
|
||||
},
|
||||
|
||||
processResponse: function (response, originalQuery, cacheKey) {
|
||||
processResponse: function (result, originalQuery, cacheKey) {
|
||||
var that = this,
|
||||
options = that.options,
|
||||
result = options.transformResult(response, originalQuery);
|
||||
options = that.options;
|
||||
|
||||
result.suggestions = that.verifySuggestionsFormat(result.suggestions);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user