Skip to content

Instantly share code, notes, and snippets.

@Olivia5k
Created April 12, 2012 12:29
Show Gist options
  • Save Olivia5k/2366916 to your computer and use it in GitHub Desktop.
Save Olivia5k/2366916 to your computer and use it in GitHub Desktop.
jQuery Autocomplete custom _renderItem issue
I am having issues with jQuery Autocomplete. I am modding it to
show two kinds of items: actual matches to the search string and
suggestions (speling corrections, related keywords etc). The
backend does all the work on that; the Autocomplete is just
fed two lists.
A picture can explain better:
http://shot.ninjaloot.se/20120412.141112.png
(the data is just rasta dummy data while developing, and the
styling is not complete yet)
While the rendering works, selection (click or otherwise) of the
items throws an exception that is hard to debug:
TypeError: 'undefined' is not an object (evaluating 'ui.item.data') (jquery-ui-1.8.18.custom.js:5114)
As I get it, the menu.selected function is given a `ui` argument
that has an undefined `item` key.
Why does this happen and what can I do about it?'If I comment out
my custom renderer, selection works.
This is my custom renderer function. It's been lifted verbatim from the one in the
UI source files and then extended to do my custom haxing.
$input.data("autocomplete")._renderItem = function(ul, item) {
var cls = 'ui-menu-item';
if(item.label === null) {
cls += ' center disabled';
item.label = '-- perhaps thou meaneth --';
}
return $("<li></li>")
.data("item.data", item)
.append("<a class='ui-corner-all'>" + item.label + "</a>")
.addClass(cls)
.appendTo(ul);
};
If any more code is needed, I'd be happy to supply it!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment