mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-09 23:01:00 +00:00
Construct serviceUrl via callback function. Fixes #66.
This commit is contained in:
parent
941c8ee4e3
commit
d48616adb5
@ -385,4 +385,40 @@ describe('Autocomplete', function () {
|
|||||||
|
|
||||||
expect(instance instanceof $.Autocomplete).toBe(true);
|
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) {
|
getSuggestions: function (q) {
|
||||||
var response,
|
var response,
|
||||||
that = this,
|
that = this,
|
||||||
options = that.options;
|
options = that.options,
|
||||||
|
serviceUrl = options.serviceUrl;
|
||||||
|
|
||||||
response = that.isLocal ? that.getSuggestionsLocal(q) : that.cachedResponse[q];
|
response = that.isLocal ? that.getSuggestionsLocal(q) : that.cachedResponse[q];
|
||||||
|
|
||||||
@ -393,9 +394,12 @@
|
|||||||
if (options.onSearchStart.call(that.element, options.params) === false) {
|
if (options.onSearchStart.call(that.element, options.params) === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ($.isFunction(options.serviceUrl)) {
|
||||||
|
serviceUrl = options.serviceUrl.call(that.element, q);
|
||||||
|
}
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: options.serviceUrl,
|
url: serviceUrl,
|
||||||
data: options.params,
|
data: options.ignoreParams ? null : options.params,
|
||||||
type: options.type,
|
type: options.type,
|
||||||
dataType: options.dataType
|
dataType: options.dataType
|
||||||
}).done(function (data) {
|
}).done(function (data) {
|
||||||
|
Loading…
Reference in New Issue
Block a user