2
0
mirror of https://github.com/devbridge/jQuery-Autocomplete.git synced 2024-11-25 06:07:45 +00:00

Add beforeRender callback. Closes #84

This commit is contained in:
Tomas Kirda 2013-08-31 17:13:27 -05:00
parent 684bf9efd7
commit f7716b6551
3 changed files with 33 additions and 2 deletions

View File

@ -32,6 +32,7 @@ The standard jquery.autocomplete.js file is around 2.7KB when minified via Closu
* `noCache`: Boolean value indicating whether to cache suggestion results. Default `false`.
* `onSearchStart`: `function (query) {}` called before ajax request. `this` is bound to input element.
* `onSearchComplete`: `function (query) {}` called after ajax response is processed. `this` is bound to input element.
* `beforeRender`: `function (container) {}` called before displaying the suggestions. You may manipulate suggestions DOM before it is displayed.
* `tabDisabled`: Default `false`. Set to true to leave the cursor in the input field after the user tabs to select a suggestion.
* `paramName`: Default `query`. The name of the request parameter that contains the query.
* `transformResult`: `function(response, originalQuery) {}` called after the result of the query is ready. Converts the result into response.suggestions format.

View File

@ -438,4 +438,27 @@ describe('Autocomplete', function () {
expect(width).toBeGreaterThan(0);
});
it('Should call beforeRender and pass container jQuery object', function () {
var element = document.createElement('input'),
input = $(element),
instance,
elementCount,
context;
input.autocomplete({
lookup: [{ value: 'Jamaica', data: 'B' }],
beforeRender: function (container) {
context = this;
elementCount = container.length;
}
});
input.val('Jam');
instance = input.autocomplete();
instance.onValueChange();
expect(context).toBe(element);
expect(elementCount).toBe(1);
});
});

View File

@ -500,6 +500,7 @@
className = that.classes.suggestion,
classSelected = that.classes.selected,
container = $(that.suggestionsContainer),
beforeRender = that.options.beforeRender,
html = '',
width;
@ -517,8 +518,7 @@
container.width(width > 0 ? width : 300);
}
container.html(html).show();
that.visible = true;
container.html(html);
// Select first value by default:
if (that.options.autoSelectFirst) {
@ -526,6 +526,13 @@
container.children().first().addClass(classSelected);
}
if ($.isFunction(beforeRender)) {
beforeRender.call(that.element, container);
}
container.show();
that.visible = true;
that.findBestHint();
},