Bug?: Autocomplete with autoFocus and show options on focus
Hey guys,
I've come across an issue when using autocomplete with autoFocus=true and using:
- .click(function (e) {
- $(this).autocomplete("search");
- })
to open the list of options.
There's some kind of race condition where the first element in the list is selected for a second and then becomes deselected.
Both features work independently but when combined there is an issue.
Is this a know bug? Is there a fix or workaround?
Here's some code. (I have extended autocomplete for categories, i also tried without category extension with same results):
- $.widget("ui.catcomplete", $.ui.autocomplete, {
- _renderMenu: function (ul, items) {
- var self = this,
- currentCategory = "";
- $.each(items, function (index, item) {
- if (item.category !== currentCategory) {
- ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
- currentCategory = item.category;
- }
- self._renderItemData(ul, item);
- });
- }
- });
- var memberSearchTags = [{
- anchor: "ObjectModel.DataStore.Add"
- category: "Methods"
- label: "Add(...)"
- }, {
- anchor: "ObjectModel.TextMessage"
- category: "Objects"
- label: "TextMessage"
- }];
- $("#mysearch")
- .catcomplete({
- source: memberSearchTags,
- select: function (event, ui) {
- $(this).val("");
- return false;
- },
- autoFocus: true,
- minLength: 0
- })
- .click(function (e) {
- $(this).catcomplete("search");
- });
Thanks much!
Steve