mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-09 23:01:00 +00:00
Merge branch 'develop'
This commit is contained in:
commit
6e055c1a58
@ -385,4 +385,40 @@ describe('Autocomplete', function () {
|
||||
|
||||
expect(instance instanceof $.Autocomplete).toBe(true);
|
||||
});
|
||||
|
||||
it('Should construct serviceUrl via callback function.', function () {
|
||||
var input = $(document.createElement('input')),
|
||||
dynamicUrl,
|
||||
data;
|
||||
|
||||
input.autocomplete({
|
||||
ignoreParams: true,
|
||||
serviceUrl: function (query) {
|
||||
return '/dynamic-url/' + encodeURIComponent(query).replace(/%20/g, "+");
|
||||
}
|
||||
});
|
||||
|
||||
$.mockjax({
|
||||
url: '/dynamic-url/*',
|
||||
responseTime: 5,
|
||||
response: function (settings) {
|
||||
dynamicUrl = settings.url;
|
||||
data = settings.data;
|
||||
var response = {
|
||||
suggestions: []
|
||||
};
|
||||
this.responseText = JSON.stringify(response);
|
||||
}
|
||||
});
|
||||
|
||||
input.val('Hello World');
|
||||
input.autocomplete().onValueChange();
|
||||
|
||||
waits(10);
|
||||
|
||||
runs(function () {
|
||||
expect(dynamicUrl).toBe('/dynamic-url/Hello+World');
|
||||
expect(data).toBeFalsy();
|
||||
});
|
||||
});
|
||||
});
|
@ -381,7 +381,8 @@
|
||||
getSuggestions: function (q) {
|
||||
var response,
|
||||
that = this,
|
||||
options = that.options;
|
||||
options = that.options,
|
||||
serviceUrl = options.serviceUrl;
|
||||
|
||||
response = that.isLocal ? that.getSuggestionsLocal(q) : that.cachedResponse[q];
|
||||
|
||||
@ -390,10 +391,15 @@
|
||||
that.suggest();
|
||||
} else if (!that.isBadQuery(q)) {
|
||||
options.params[options.paramName] = q;
|
||||
options.onSearchStart.call(that.element, options.params);
|
||||
if (options.onSearchStart.call(that.element, options.params) === false) {
|
||||
return;
|
||||
}
|
||||
if ($.isFunction(options.serviceUrl)) {
|
||||
serviceUrl = options.serviceUrl.call(that.element, q);
|
||||
}
|
||||
$.ajax({
|
||||
url: options.serviceUrl,
|
||||
data: options.params,
|
||||
url: serviceUrl,
|
||||
data: options.ignoreParams ? null : options.params,
|
||||
type: options.type,
|
||||
dataType: options.dataType
|
||||
}).done(function (data) {
|
||||
|
Loading…
Reference in New Issue
Block a user