Skip to content

Instantly share code, notes, and snippets.

@doxavore
Created December 10, 2010 19:00
Show Gist options
  • Save doxavore/736619 to your computer and use it in GitHub Desktop.
Save doxavore/736619 to your computer and use it in GitHub Desktop.
// jQuery barfs because $(empty).data("autocomplete") => undefined
$(".course-autocomplete").autocomplete({
source: "/courses/autocomplete.json"
}).data("autocomplete")._renderItem = function(ul, item) {
return $("<li>")
.data("item.autocomplete", item)
.append("<a>" + item.name + "</a>")
.appendTo(ul);
};
// jQuery likes but my fingers don't
$(".course-autocomplete").autocomplete({
source: "/courses/autocomplete.json"
});
if ($(".course-autocomplete").length) {
$(".course-autocomplete").data("autocomplete")._renderItem = function(ul, item) {
return $("<li>")
.data("item.autocomplete", item)
.append("<a>" + item.name + "</a>")
.appendTo(ul);
}
};
// Acceptable compromise?
$(".course-autocomplete").autocomplete({
source: "/courses/autocomplete.json"
}).each(function(i,elem) {
$(elem).data("autocomplete")._renderItem = function(ul, item) {
return $("<li>")
.data("item.autocomplete", item)
.append("<a>" + item.name + "</a>")
.appendTo(ul);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment