I have a problem with jQuery autocomplete. On keydown, the selected item isn't "Item1", it would be the full unordered-list including span and the ul.
<ul>
<li>
<span>Items</span>
<ul>
<li><a>Item1</a></li>
<li><a>Item2</a></li>
</ul>
</li>
<li>
<span>Cars</span>
<ul>
<li><a>Car1</a></li>
<li><a>Car2</a></li>
</ul>
</li>
<li>
<span>Test</span>
<ul>
<li><a>Test1</a></li>
<li><a>Test2</a></li>
</ul>
</li>
</ul>
Problem is:
On keydown -> menufocus: ui.item.data("ui-autocomplete-item") -> ui.item is undefined (in jquery.ui.js file)
ul-parameter in menufocus is full list of "Items" (<ul><li><a>Item1</a></li><li>...</li></ul>).
What I want: On keydown select Item1, next Item2, next Car1, Car2 and so on...
_renderMenu:
$.each( items, function( index, item ) {
...
if ( item.category != currentCategory ) {
categoryIndex++;
//Create "li"s for every category and append a span and the new ul to it.
var myLi = "<li class='ui-autocomplete-category'><span class='ui-autocomplete-category-head'><i class='" + category.icon + "'></i> " + category.name + "</span></li>";
var myLi = $(myLi).removeData("item.autocomplete-item");
myLi.append("<ul class='ui-autocomplete-inner-ul' role='listbox' aria-labelledby='cat" + categoryIndex + "' id='innerUlCat"+categoryIndex+"' aria-readonly='true'>");
var myUl = ul.append(myLi);
currentCategory = item.category;
}
var currentUl = $(ul).find("#innerUlCat"+categoryIndex) || ul;
li = that._renderItemData( currentUl, item );
});
_renderItemData: return this._renderItemOwn( ul, item );
_renderItemOwn:
return $( "<li></li>" )
.data( "ui-autocomplete-item", item )
.append( "<a class='ui-autocomplete-item'>" + item.label + "</a>" )
.appendTo( ul );
In _renderItemOwn i added the data "ui-autocomplete-item" but it doesn't work.
Are there any solutions? Thank you!