Move this topic
autocomplete
in Using jQuery UI
•
9 years ago
hey guys...im trying to find how I'm able to add a hide suggestions text and function to the end of my autocomplete menu to allow user to hide autocomplete suggestions
I have seen it done...any tutorials, code available please?
thank you
1
Replies(4)
Re: autocomplete
9 years ago
$('#' + selector).data('ui-autocomplete')._renderItem = function (ul, item)
{
var re = new RegExp('^' + this.term, "i");
var t = item.label.replace(re, "<span id='dropdown-item-highlight'>" + "$&" + "</span>");
return $('<li></li>')
.data("item.autocomplete", item)
.append('<a>' + t + ' in ' + item.type + '</a>')
.addClass( 'dropdown-item' )
.appendTo(ul);
};
$('#' + selector).data('ui-autocomplete')._renderMenu = function (ul, item)
{
//not working
return $('<ul></ul>')
.append('<a>Hide Suggestion</a>')
.addClass('dropdown-menu');
};
here is the code I've started to develop but im unable to have Hide Suggestion at the bottom of my menu...anyone please?
Leave a comment on destramic's reply
Re: autocomplete
9 years ago
Something like this perhaps:
- $('#' + selector).data('ui-autocomplete')._renderMenu: function(ul, items) {
- var that = this;
- $.each(items, function(index, item) { // Render selection items
- that._renderItemData(ul, item);
- });
- $('<li></li>').append('<a>Hide suggestion</a>').appendTo(ul); // Add new item
- }
Leave a comment on kbwood.au's reply
Re: autocomplete
9 years ago
thank you for your reply but unfortunately when I add the _RenderMenu function it stops the _RenderItems function from creating the suggestions
here is bother functions:
$('#' + selector).data('ui-autocomplete')._renderItem = function (ul, item)
{
var re = new RegExp('^' + this.term, "i");
var t = item.label.replace(re, "<span id='dropdown-item-highlight'>" + "$&" + "</span>");
return $('<li></li>')
.data("item.autocomplete", item)
.append('<a>' + t + ' in ' + item.type + '</a>')
.addClass( 'dropdown-item' )
.appendTo(ul);
};
$('#' + selector).data('ui-autocomplete')._renderMenu = function (ul, items)
{
//not working
var that = this;
$.each(items, function(ul, item)
{
that._renderItemData(ul, item);
});
$('<li></li>').append('<a>Hide suggestion</a>').appendTo(ul);
};
Leave a comment on destramic's reply
Re: autocomplete
9 years ago
$('#' + selector).data('ui-autocomplete')._renderMenu = function (ul, items)
{
var that = this;
$.each( items, function( index, item )
{
that._renderItemData( ul, item );
});
$(ul)
.attr( 'tabindex', -1 )
.addClass( 'dropdown-menu' );
$('<li></li>')
.append('<a>Hide Suggestion</a>')
.addClass( 'dropdown-suggestion' )
.appendTo(ul);
};
sorted it
Leave a comment on destramic's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic
Reply to destramic's question
Statistics
- 4 Replies
- 1241 Views
- 0 Followers