Jquery ui.autocomplete () does not fire when the same letter is entered after blur ()

Sample code here: http://jsbin.com/etaziy (using http://jqueryui.com/demos/autocomplete/ )

If you type โ€œj,โ€ you get 3 names: โ€œJohn,โ€ โ€œJack,โ€ and โ€œJoe.โ€ If you then blur, I clear the input by simply making the inputs val (''). Then, if you go back in and type j again, will nothing happen? This is not until you type the second matching letter, which you will receive a pop-up window.

My example may seem a little strange, but in essence it is a really shortened version of what I'm working on. I need to clear input after blur () and clear it after selection. Doing this makes subsequent samples distorted.

I kind of think that this is intended functionality, but for my purpose this is not what I want. I really need a popup with a list to show as soon as a letter is typed.

Greetings.

+7
source share
2 answers

The problem is that autocomplete keeps track of the value that it matches inside, so when you first enter j , it sets this internal value to 'j', and then it was not reset for the empty string when you changed the input to empty.

Having looked at the autocomplete source, I couldnโ€™t find out how to directly access the internal variable, but you can force autocomplete to update it for you by running another search after you change the input to empty (and with a length of zero it actually does not 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 } }); }); 
+10
source

Just replace line 98 with jquery.ui.autocomplete.js

 if ( self.term != self.element.val() ) { // only search if the value has changed 

with if(true){

+4
source

All Articles