Search and Top Navigation
#5918 closed enhancement (wontfix)
Opened August 10, 2010 04:03PM UTC
Closed August 17, 2010 09:06PM UTC
Last modified February 18, 2013 12:45PM UTC
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 );
}
Attachments (0)
Change History (8)
Changed August 10, 2010 04:15PM UTC by comment:1
resolution: | → wontfix |
---|---|
status: | new → closed |
Changed August 17, 2010 08:48PM UTC by comment:2
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?
Changed August 17, 2010 08:48PM UTC by comment:3
resolution: | wontfix |
---|---|
status: | closed → reopened |
Changed August 17, 2010 09:06PM UTC by comment:4
resolution: | → wontfix |
---|---|
status: | reopened → closed |
I've created an extension that adds a boolean html option: http://github.com/scottgonzalez/jquery-ui-extensions/blob/master/autocomplete/jquery.ui.autocomplete.html.js
Changed August 17, 2010 09:26PM UTC by comment:5
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.
Changed October 11, 2012 09:15PM UTC by comment:7
milestone: | TBD |
---|
Milestone TBD deleted
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.