mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-14 01:04:06 +00:00
Make query value to be set by the plugin. Fixes #48
This commit is contained in:
parent
a362ce1b06
commit
7af8d62091
@ -210,6 +210,41 @@ describe('Autocomplete', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Should not require orginal query value from the server', function () {
|
||||
var input = document.createElement('input'),
|
||||
ajaxExecuted = false,
|
||||
url = '/test-original-query',
|
||||
autocomplete = new $.Autocomplete(input, {
|
||||
serviceUrl: url
|
||||
});
|
||||
|
||||
$.mockjax({
|
||||
url: url,
|
||||
responseTime: 50,
|
||||
response: function () {
|
||||
ajaxExecuted = true;
|
||||
var response = {
|
||||
query: null,
|
||||
suggestions: ['A', 'B', 'C']
|
||||
};
|
||||
this.responseText = JSON.stringify(response);
|
||||
}
|
||||
});
|
||||
|
||||
input.value = 'A';
|
||||
autocomplete.onValueChange();
|
||||
|
||||
waitsFor(function () {
|
||||
return ajaxExecuted;
|
||||
}, 'Ajax call never completed.', 100);
|
||||
|
||||
runs(function () {
|
||||
expect(ajaxExecuted).toBe(true);
|
||||
expect(autocomplete.suggestions.length).toBe(3);
|
||||
expect(autocomplete.suggestions[0].value).toBe('A');
|
||||
});
|
||||
});
|
||||
|
||||
it('Should should not preventDefault when tabDisabled is set to false', function () {
|
||||
var input = document.createElement('input'),
|
||||
autocomplete = new $.Autocomplete(input, {
|
||||
|
@ -95,7 +95,9 @@
|
||||
},
|
||||
paramName: 'query',
|
||||
transformResult: function (response, originalQuery) {
|
||||
return typeof response === 'string' ? $.parseJSON(response) : response;
|
||||
var result = typeof response === 'string' ? $.parseJSON(response) : response;
|
||||
result.query = originalQuery;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
@ -491,7 +493,7 @@
|
||||
}
|
||||
|
||||
// Display suggestions only if returned query matches current value:
|
||||
if (result[options.paramName] === that.getQuery(that.currentValue)) {
|
||||
if (result.query === that.getQuery(that.currentValue)) {
|
||||
that.suggestions = result.suggestions;
|
||||
that.suggest();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user