Autocomplete: Render items as text, not HTML. Fixes #5275 - suggestions are not html-encoded.

As noted in the ticket, it's probably better to default to unstyled items to prevent problems. Users can still implement their own rendering method as shown in the custom data and display demo.
This commit is contained in:
Scott González 2010-07-19 15:45:30 -04:00
parent 7deb873c51
commit 1f2cfb942f
3 changed files with 9 additions and 3 deletions

View File

@ -54,6 +54,12 @@
minLength: 0 minLength: 0
}) })
.addClass("ui-widget ui-widget-content ui-corner-left"); .addClass("ui-widget ui-widget-content ui-corner-left");
input.data("autocomplete")._renderItem = function( ul, item) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.label + "</a>" )
.appendTo( ul );
};
$("<button>&nbsp;</button>") $("<button>&nbsp;</button>")
.attr("tabIndex", -1) .attr("tabIndex", -1)
.attr("title", "Show All Items") .attr("title", "Show All Items")

View File

@ -3,8 +3,8 @@
$q = strtolower($_GET["term"]); $q = strtolower($_GET["term"]);
if (!$q) return; if (!$q) return;
$items = array( $items = array(
"Great <em>Bittern</em>"=>"Botaurus stellaris", "Great Bittern"=>"Botaurus stellaris",
"Little <em>Grebe</em>"=>"Tachybaptus ruficollis", "Little Grebe"=>"Tachybaptus ruficollis",
"Black-necked Grebe"=>"Podiceps nigricollis", "Black-necked Grebe"=>"Podiceps nigricollis",
"Little Bittern"=>"Ixobrychus minutus", "Little Bittern"=>"Ixobrychus minutus",
"Black-crowned Night Heron"=>"Nycticorax nycticorax", "Black-crowned Night Heron"=>"Nycticorax nycticorax",

View File

@ -304,7 +304,7 @@ $.widget( "ui.autocomplete", {
_renderItem: function( ul, item) { _renderItem: function( ul, item) {
return $( "<li></li>" ) return $( "<li></li>" )
.data( "item.autocomplete", item ) .data( "item.autocomplete", item )
.append( "<a>" + item.label + "</a>" ) .append( $( "<a></a>" ).text( item.label ) )
.appendTo( ul ); .appendTo( ul );
}, },