Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#5918 closed enhancement (wontfix)

Using HTML in Autocomplete

Reported by: pauleee Owned by:
Priority: minor Milestone:
Component: ui.autocomplete Version: 1.8.4
Keywords: Cc:
Blocked by: Blocking:

Description

It's not possible to use HTML in the suggestion.

File: jquery.ui.autocomplete.js Line: 324-329

Original: _renderItem: function( ul, item) {

return $( "<li></li>" )

.data( "item.autocomplete", item ) .append( $( "<a></a>" ).text( item.label ) ) .appendTo( ul );

}

Fixed:

_renderItem: function( ul, item) {

return $( "<li></li>" )

.data( "item.autocomplete", item ) .append( $( "<a></a>" ).html( item.label ) ) .appendTo( ul );

}

Change History (8)

comment:1 Changed 9 years ago by rdworth

Resolution: wontfix
Status: newclosed

This change is by design ( see #5275 ). As mentioned over there, "Defaulting to plaintext and defining your own render method for HTML and other complex displays makes sense."

An extension can provide a custom _renderItem, such as http://jqueryui.com/demos/autocomplete/custom-data.html so no change to the default is required.

comment:2 Changed 9 years ago by carpeliam

Is there perhaps a middle-of-the-road longterm solution? I understand that plaintext makes for a good default, but using _renderItem smells like monkey-patching to me. It's an undocumented method (outside of examples) as far as I can tell, it requires the plugin user to know something about the implementation of the plugin (I need to be aware that ULs and LIs are being used under the hood), and doesn't feel very forward-compatible.

Perhaps an option can be added to the plugin for rendering in html?

comment:3 Changed 9 years ago by carpeliam

Resolution: wontfix
Status: closedreopened

comment:4 Changed 9 years ago by Scott González

Resolution: wontfix
Status: reopenedclosed

comment:5 Changed 9 years ago by carpeliam

Thanks Scott, that's by far a much easier solution to work with. However, I'd love to see this rolled into the jqueryui codebase, just in case jqueryui implementation details change in the future, breaking this code.

comment:6 Changed 9 years ago by Scott González

#6753 is a duplicate of this ticket.

comment:7 Changed 7 years ago by Scott González

Milestone: TBD

Milestone TBD deleted

comment:18 Changed 7 years ago by Scott González

#9093 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.