0

My understanding of javascript is too limited to do this. I've seen this solved by overriding _renderMenu with another jQuery plugin here: Limit the result in jQuery Autocomplete but not with the jQuery UI plugin. How can a limit be used on the jQuery UI autocomplete?

In the jquery-ui.js I modified this code to limit the results however I'd like to leave the library code alone and just override it in the client code.

_renderMenu: function( ul, items ) {
    var self = this;
    $.each( items, function( index, item ) {
        self._renderItem( ul, item );
    });
}

suggest-search.js:

            $("#global-search").autocomplete({
                source: response,
                minLength: 1,
                delay: 100,
                select: function (event, ui) {
                    //bzzz
                }

            }).data( "autocomplete" )._renderItem = function( ul, item ) {

                var imgFilename = item.filename;
                imgFilename = imgFilename.replace(/ /g,"_");

                return $( "<li></li>" )
                    .data( "item.autocomplete", item )
                    .append('<a class="clearfix"><img src="http://localhost/img/' + imgFilename + '" width="40" height="63" />'+
                            '<div class="ac-menu-item"><div><span class="ac-publish-title">' + item.title + '</span></div><div class="faded">'+item.year+'</div></div></a>' )
                    .appendTo(ul);

            }

        }
Community
  • 1
  • 1
el_pup_le
  • 11,711
  • 26
  • 85
  • 142

1 Answers1

1

Simplest would be for your source callback function to limit the number of items it puts in the return array.

Barmar
  • 741,623
  • 53
  • 500
  • 612