I am wondering how to make the matched part of the autocomplete suggestions bold when using jquery ui autocomplete?
So for example if you type in "ja" and the suggestions are javascript and java (like in the example on the jquery ui demo page) then I would like to make "ja" bold in both suggestions.
Anyone knows how to do that?
Thanks a lot for the help...
addClass("boldText");
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.
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.
I'm not sure why the autocomplete is so bare-bone compared to the other functionalities it contains (e.g. droppable, sortable, draggable etc.).
It should really offer you with a stylable option, e.g. wrapping it with <span class="ui-autocomplete-term">term</span>
or something similar.
You could do it like this
It should be pretty self-explanatory; if not, gimme a shout.
In jQuery UI 1.11.1, here is the code I used to make it work (case insensitive):
open: function (e, ui) {
var acData = $(this).data('ui-autocomplete');
acData
.menu
.element
.find('li')
.each(function () {
var me = $(this);
var keywords = acData.term.split(' ').join('|');
me.text(me.text().replace(new RegExp("(" + keywords + ")", "gi"), '<b>$1</b>'));
});
}
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