Wednesday, April 1, 2009

[jQuery] [autocomplete] Problem with focus after selection with autocomplete input box should be hided on blur

Hi,
I have created some widget to search the database for some entries.
I used the autocomplete script to show the results.

I wanted to hide the search box after a result is selected (the
searchbox will be shown on a click of a button)
Everything works fine exept in IE.

Cause I hide my input box with
$("#'.$id.' .inputNav input").onblur(.blur(function(){
$("#'.$id.' .inputNav").hide();
}

The IE couldn't focus the input field which is in the autocomplete.js
when creating the list.

Line 567 ff:

if(target(event).nodeName && target(event).nodeName.toUpperCase() ==
'LI') {
active = $("li", list).removeClass(CLASSES.ACTIVE).index
(target(event));
$(target(event)).addClass(CLASSES.ACTIVE);
}
}).click(function(event) {
$(target(event)).addClass(CLASSES.ACTIVE);
select();
// TODO provide option to avoid setting focus again after
selection? useful for cleanup-on-focus

input.focus(); << Troublemaker

return false;
}).
And in line 756

field.focus();

Is there a possibility to avoid this?
Opera and Firefox works as expected and also IE if I remove that
"line".
(sure I can change the js script but on a next update I could get the
problem back again and it would be nice to have another solution).

A simple $(input).is(':hidden')?null:input.focus(); would also do the
trick.

regards Benjamin

No comments: