Thursday, April 19, 2012

Jquery autocomplete combobox button click event

Weird behavior of my autocomplete Jquery plugin, the click event show clearly that if input.autocomplete("widget") is visible, that is if it has display:block, then close the widget. But if I change focus from input element to widget itself and lets say scroll a bit, then when i click again on buton , the widget is created again.



My solution wolud be in closing the widget even if focus is transfered to widget itself and not the input element?



Any ideas how to modify this code so it beahaives this way?



 this.button = $("<button type='button'>&nbsp;</button>")
.attr("tabIndex", -1)
.attr("title", "Show all items")
.insertAfter(input)
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass("ui-corner-all")
.addClass("ui-corner-right ui-button-icon")
.click(function () {

// when i put breakpoint here, and my focus is not on input,
// then this if steatment is false????

if (input.autocomplete("widget").is(":visible")) {
input.autocomplete("close");
return;
}

// work around a bug (likely same cause as #5265)
$(this).blur();

// pass empty string as value to search for, displaying all results
input.autocomplete("search", "");
input.focus();
});




No comments:

Post a Comment