2

I'm currently extending the jQuery UI widget as follows:

$.widget( "custom.autocompleteCategorized", $.ui.autocomplete, {
    _renderMenu: function( ul, items ) {
        var self = this,
            currentCategory = "";
        $.each( items, function( index, item ) {
            if ( item.category != currentCategory ) {
                ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
                currentCategory = item.category;
            }
            self._renderItem( ul, item );
        });
    }    
});

This works fine, but I would now like to extend another function like so:

$.widget( "custom.autocompleteCategorized", $.ui.autocomplete, {
    _renderMenu: function( ul, items ) {
        var self = this,
            currentCategory = "";
        $.each( items, function( index, item ) {
            if ( item.category != currentCategory ) {
                ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
                currentCategory = item.category;
            }
            self._renderItem( ul, item );
        });
    }

    _response: function(contents){
        $.ui.autocomplete.prototype._response.apply(this, arguments);
        $(this.element).trigger("autocompletesearchcomplete", [contents]);
    }

});

Unfortunately this errors, what is the right way to extend multiple functions as seen above?

Thanks

3
  • looks to me as if you're missing a comma Commented Aug 21, 2012 at 0:40
  • Thanks I tried that but then I get a "Uncaught TypeError: undefined is not a function" after entering input in the autocompleter Commented Aug 21, 2012 at 0:42
  • Well, that's how you do it, though, more or less. Maybe something else is wrong. Commented Aug 21, 2012 at 0:47

1 Answer 1

2

missing comma i think

$.widget( "custom.autocompleteCategorized", $.ui.autocomplete, {
    _renderMenu: function( ul, items ) {
        var self = this,
            currentCategory = "";
        $.each( items, function( index, item ) {
            if ( item.category != currentCategory ) {
                ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
                currentCategory = item.category;
            }
            self._renderItem( ul, item );
        });

    }, // <--- you're missing this comma

    _response: function(contents){
        $.ui.autocomplete.prototype._response.apply(this, arguments);
        $(this.element).trigger("autocompletesearchcomplete", [contents]);
    }

});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.