Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#8928 closed feature (duplicate)

Possibility to add class to autocomplete ul elements

Reported by: dickz Owned by:
Priority: minor Milestone: 1.10.0
Component: ui.autocomplete Version: 1.9.2
Keywords: Cc:
Blocked by: Blocking:


It would be very useful to be able to specify a class that would be added to the <ul> elements that the autocomplete widget creates.

This could work in a way similar to what is possible with the dialog widget which allows you to specify a dialogClass in the options.

That way you could for example have different autocomplete widgets with different styling on the same page.

The workaround solution that I have used so far is to override the _renderMenu function, but it does not feel like a simple or good way to do it.

Change History (3)

comment:1 Changed 5 years ago by Scott González

Resolution: duplicate
Status: newclosed

Duplicate of #7053.
Overriding _renderMenu() is the correct thing to do today.

I'm closing as a duplicate of #7053, because it's either all or nothing. The dialogClass option needs to go away.

comment:2 Changed 5 years ago by Scott González

I should clarify a bit. Overriding _renderMenu() is only correct if you're building an extension that adds an option to add a class. The proper solution for end users is:

$( elem ).autocomplete({
    source: ...
}).autocomplete( "widget" ).addClass( "whatever" );

comment:3 Changed 5 years ago by dickz

Thank you for your quick reply. I had not understood/discovered the widget method earlier, but your last example is exactly what I really wanted, rather than overriding _renderMenu. Perhaps it would be a good idea to add it as a "code example" for the widget method?

Note: See TracTickets for help on using tickets.