mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-25 22:27:39 +00:00
Return instance of Autocomplete for the first matched element if called without arguments.
This commit is contained in:
parent
c650a51a15
commit
41543d98a4
@ -373,4 +373,16 @@ describe('Autocomplete', function () {
|
||||
expect(input.data('autocomplete')).toBeUndefined();
|
||||
expect(div.children().length).toBe(0);
|
||||
});
|
||||
|
||||
it('Should return Autocomplete instance if called without arguments', function () {
|
||||
var input = $(document.createElement('input'));
|
||||
|
||||
input.autocomplete({
|
||||
serviceUrl: '/test-dispose'
|
||||
});
|
||||
|
||||
var instance = input.autocomplete();
|
||||
|
||||
expect(instance instanceof $.Autocomplete).toBe(true);
|
||||
});
|
||||
});
|
@ -611,9 +611,15 @@
|
||||
|
||||
// Create chainable jQuery plugin:
|
||||
$.fn.autocomplete = function (options, args) {
|
||||
var dataKey = 'autocomplete';
|
||||
// If function invoked without argument return
|
||||
// instance of the first matched element:
|
||||
if (arguments.length === 0) {
|
||||
return this.first().data(dataKey);
|
||||
}
|
||||
|
||||
return this.each(function () {
|
||||
var dataKey = 'autocomplete',
|
||||
inputElement = $(this),
|
||||
var inputElement = $(this),
|
||||
instance = inputElement.data(dataKey);
|
||||
|
||||
if (typeof options === 'string') {
|
||||
|
Loading…
Reference in New Issue
Block a user