mirror of
https://github.com/devbridge/jQuery-Autocomplete.git
synced 2024-11-22 12:55:12 +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);
|
||||
});
|
||||
});
|
@ -601,7 +601,7 @@
|
||||
return currentValue.substr(0, currentValue.length - parts[parts.length - 1].length) + value;
|
||||
},
|
||||
|
||||
dispose: function() {
|
||||
dispose: function () {
|
||||
var that = this;
|
||||
that.el.off('.autocomplete').removeData('autocomplete');
|
||||
that.disableKillerFn();
|
||||
@ -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