Skip to main content

Engineering Notes

Custom-rendering jQuery UI autocomplete results

jQuery UI’s autocomplete shipped as a plain list of matching strings — fine for tags, poor for products. This 2014 note showed how to take control of how each suggestion renders. The library has aged; the reason you would do this has not.

By Prabin Silwal Published Substantially revised 4 min read

Historical project. This tutorial describes the jQuery UI widget as used in 2014, preserved as an engineering retrospective. The closing section notes today’s equivalents.

Why autocomplete earns its place

The original article’s framing is product thinking, not plumbing: when a user enters, say, a product name, autocomplete against the existing catalogue means they pick a valid, canonical value instead of typing a near-duplicate. Fewer typos, fewer orphan records, faster entry — assurance, as the author put it, “that they’re providing valid inputs”.

The default widget

The stock jQuery UI widget needed only a source array and one call:

$(function() {
  var availableTags = ["ActionScript", "AppleScript", "Asp", "BASIC", "C",
                       "C++", "Java", "JavaScript", "PHP", "Python", "Ruby"];
  $("#tags").autocomplete({ source: availableTags });
});
jQuery UI autocomplete showing a plain dropdown of language name suggestions
The default rendering: functional, and visually indistinguishable entries (original 2014 screenshot).

Taking over the rendering

The technique the article shared was the widget’s official extension point: override how each item becomes markup. That unlocks rich suggestions — an image, a price, a category caption — instead of bare text:

$("#product").autocomplete({ source: products })
  .autocomplete("instance")._renderItem = function(ul, item) {
    return $("<li>")
      .append("<div><img src='" + item.icon + "' alt=''> "
              + "<strong>" + item.label + "</strong>"
              + "<small>" + item.category + "</small></div>")
      .appendTo(ul);
  };

Same data flow, same keyboard behaviour — the widget still manages matching and selection — but each suggestion now carries enough context to choose confidently at a glance.

The same idea today

Present-day editorial perspective.

jQuery UI has left the mainstream, but this article’s real content — suggestions should be rendered as informative objects, not strings — is now standard practice in every combobox component and search-as-you-type interface, and in the typeahead patterns we build into SaaS products today. The library was the vehicle; the UX judgement was the cargo.