I have the jQuery UI Autocomplete setup to my liking and working perfectly, but there is one fatal flaw. In my autocomplete I use a custom display like this example. I have something very similar built but with on exception...
The only difference is that I have multiple autocomplete elements of the same class on that one page. Only the first element shows the extra data line, the rest only show the basic autocomplete.
I can get the desired result by just iterating all of those class elements and calling the autocomplete on them, but I was hoping there was a better way of calling it once and having it "just work".
Here's how I'm adding the extra line:
.data( 'autocomplete' )._renderItem = function( ul, item ) {
return $( '<li></li>' )
.data( 'item.autocomplete', item )
.append( '<a>' + item.label + '<br/><small>' + item.desc + '<small></a>' )
.appendTo( ul );
};
I should note that I'm not getting any console exceptions at all.
AutoComplete control allows you to select multiple values from the suggestions list by using the MultiSelectMode property. Multiple values can be selected when MultiSelectMode value is set to VisualMode or Delimiter. Delimiter mode separates multiple items by using a separator character defined.
In the process of searching a specific value, the jQuery UI autocomplete selection feature provides the user with some string suggestions for the input area which effectively saves time. The autocomplete select action is triggered when the user selects one of the options from the pre-populated list.
Syntax: $("TagId"). autocomplete({ source : itemList // List of Words. })
Autocomplete mechanism is frequently used in modern websites to provide the users a list of suggestion while typing the beginning word in the text box. It facilitates the user to select an item from the list, which will be displayed in the input field.
The only way I can make this work is by changing my code from:
addautocomplete($('.tagEntry'));
To:
$('.tagEntry').each(function() {
addautocomplete(this);
});
You simply need to override the function via the object prototype, instead of on a single instance.
$.ui.autocomplete.prototype._renderItem = function( ul, item ) {
return $( '<li></li>' )
.data( 'item.autocomplete', item )
.append( '<a>' + item.label + '<br/><small>' + item.desc + '<small></a>' )
.appendTo( ul );
};
Overwrite the function before activating any autocompletes, but after the script has loaded.
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