RuntimeException
RuntimeException

Reputation: 1135

jquery autocomplete source code explanation

I want to make jquery's autocomplete work to custom events. Potentially I might need to tweak source code. I'm trying to understand it but not sure how 'function( request, response )' works. How this is getting called and where the parameters are coming from?

_initSource: function() {
        var array, url,
            that = this;
        if ( $.isArray(this.options.source) ) {
            array = this.options.source;
            this.source = function( request, response ) {
                response( $.ui.autocomplete.filter( array, request.term ) );
            };
        } else if ( typeof this.options.source === "string" ) {
            url = this.options.source;
            this.source = function( request, response ) {
                if ( that.xhr ) {
                    that.xhr.abort();
                }
                that.xhr = $.ajax({
                    url: url,
                    data: request,
                    dataType: "json",
                    success: function( data ) {
                        response( data );
                    },
                    error: function() {
                        response( [] );
                    }
                });
            };
        } else {
            this.source = this.options.source;
        }
    }

Upvotes: 0

Views: 68

Answers (1)

Cezary
Cezary

Reputation: 219

it's getting called from different method inside autocomplete.

like here :

this.source( { term: value }, this._response() );

it's in _search method.

Upvotes: 1

Related Questions