PDA

View Full Version : Autocomplete Result Not Being Selected



round
12-20-2012, 11:53 AM
Hello, I am almost done but I am facing an issue like when auto suggest give result I am not able to select it. Error comes in console that is of jquery only.
Please type A or a inside top textbox

http://xhtmljunkies.net/custom_phpld/

Can you please help?

Thanks
Kaushal

jscheuer1
12-22-2012, 05:45 AM
You left out an important part of the custom _renderMenu function, or perhaps are using one that goes with an older version of the UI. Replace:


$.ui.autocomplete.prototype._renderMenu = function( ul, items ) {
var self = this;
$.each( items, function( index, item ) {
if (index < 10) // here we define how many results to show
{self._renderItem( ul, item );}
});
}

with


$.ui.autocomplete.prototype._renderMenu = function( ul, items ) {
var that = this;
$.each( items, function( index, item ) {
if (index < 10) // here we define how many results to show
{that._renderItemData( ul, item );}
});
}


The use of that instead of self as a variable name is probably minor but 'self' could confuse some browsers, it's synonymous with window and this in the global scope and because of that may even be reserved in some browsers. The important change is _renderItemData. Without that you get the error.

And doing it like so:


$.ui.autocomplete.prototype._renderMenu = function( ul, items ) {
var that = this;
$.each( items, function( index, item ) {
if (index > 9) {return false;} // here we define how many results to show
that._renderItemData( ul, item );
});
}

would be more efficient because it stops looping as soon as 10 matches are found.

round
12-31-2012, 01:29 PM
Hi jscheuer1, Sorry for the late reply. I just came after many days. This is awesome. Thank you very much for this my friend :)

You are awesome. I am having over 1500000 records so whenever I search like just pressing "A", my browser always get hanged so tha's why I thought it should be like limit 10 even if there exists 10 to 15 lakh records.

Because of you only it is working now. Thanks Jscheuer1 :) I really appreciate your knowledge.

Thanks again.
Kaushal