Example code here: http://jsbin.com/etaziy (using http://jqueryui.com/demos/autocomplete/)
If you type in a 'j' you get the 3 names, 'John' 'Jack' and 'Joe'. If you then blur away, I clear the input, just by making the inputs val(''). Then if you go back to the input, and type a 'j' again, nothing happens? It's not until you type a second matching letter that you get the popup showing.
My example might seem a bit odd, but essentially this is a really cut back version of what I'm working on. I need to clear the input after a blur(), and clear it after a selection is made. Doing this is making subsequent selections look buggy.
I'm partly thinking this is intended functionality, but for my purpose, its not what i want. I really need the popup with the list to show as soon as any letter is typed.
Cheers.
The problem is that the autocomplete keeps track of the value it is matching on internally, so when you first type j
it sets this internal value to 'j' and then it wasn't being reset to the empty string when you changed the input to be empty.
After looking at the autocomplete source I wasn't able to find out how to directly access the internal variable, but you can force the autocomplete to update it for you by running another search once you've changed the input to be empty (and with a length of zero it won't actually do the search).
$(function() {
$("#search").autocomplete({
source: data,
change: function() { // Triggered when the field is blurred, if the value has changed; ui.item refers to the selected item.
$("#search").val("");
$("#search").autocomplete("search", ""); //THIS IS THE NEW LINE THAT MAKES IT HAPPY
}
});
});
Just replace line 98 in jquery.ui.autocomplete.js
if ( self.term != self.element.val() ) { // only search if the value has changed
with if(true){
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With