github github
  • Home
  • Pricing and Signup
  • Training
  • Gist
  • Blog
  • Login

jquery / jquery-ui

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 921
    • 212
  • Source
  • Commits
  • Network (212)
  • Graphs
  • Tree: 1f2cfb9

click here to add a description

click here to add a homepage

  • Switch Branches (8)
    • bind
    • devpreview
    • formcontrols
    • master
    • menu
    • panel
    • tooltip
    • widget-super
  • Switch Tags (21)
    • 1.9m2
    • 1.9m1
    • 1.8rc3
    • 1.8rc2
    • 1.8rc1
    • 1.8b1
    • 1.8a2
    • 1.8a1
    • 1.8.4
    • 1.8.3
    • 1.8.2
    • 1.8.1
    • 1.8
    • 1.7
    • 1.6rc6
    • 1.6rc5
    • 1.6rc3
    • 1.6rc2
    • 1.6
    • 1.5.2
    • 1.5.1
  • Comments
  • Contributors
Sending Request…

The official jQuery user interface library. — Read more

  Cancel

http://jqueryui.com/

  Cancel
  • HTTP
  • Git Read-Only

This URL has Read+Write access

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.
scottgonzalez (author)
Mon Jul 19 12:45:30 -0700 2010
commit  1f2cfb942f8ac5549b1f
tree    e675788946bbe39bf323
parent  7deb873c51ede9fb5e8b
M demos/autocomplete/combobox.html 6 •••••
M demos/autocomplete/search.php 4 ••••
M ui/jquery.ui.autocomplete.js 2 ••
Txt demos/autocomplete/combobox.html
  • View file @ 1f2cfb9
... ...
@@ -54,6 +54,12 @@
54 54
             minLength: 0
55 55
           })
56 56
           .addClass("ui-widget ui-widget-content ui-corner-left");
  57
+        input.data("autocomplete")._renderItem = function( ul, item) {
  58
+          return $( "<li></li>" )
  59
+            .data( "item.autocomplete", item )
  60
+            .append( "<a>" + item.label + "</a>" )
3
  61
+            .appendTo( ul );
  62
+        };
57 63
         $("<button>&nbsp;</button>")
58 64
         .attr("tabIndex", -1)
59 65
         .attr("title", "Show All Items")
Txt demos/autocomplete/search.php
  • View file @ 1f2cfb9
... ...
@@ -3,8 +3,8 @@
3 3
 $q = strtolower($_GET["term"]);
4 4
 if (!$q) return;
5 5
 $items = array(
6  
-"Great <em>Bittern</em>"=>"Botaurus stellaris",
7  
-"Little <em>Grebe</em>"=>"Tachybaptus ruficollis",
  6
+"Great Bittern"=>"Botaurus stellaris",
  7
+"Little Grebe"=>"Tachybaptus ruficollis",
8 8
 "Black-necked Grebe"=>"Podiceps nigricollis",
9 9
 "Little Bittern"=>"Ixobrychus minutus",
10 10
 "Black-crowned Night Heron"=>"Nycticorax nycticorax",
Txt ui/jquery.ui.autocomplete.js
  • View file @ 1f2cfb9
... ...
@@ -304,7 +304,7 @@ $.widget( "ui.autocomplete", {
304 304
   _renderItem: function( ul, item) {
305 305
     return $( "<li></li>" )
306 306
       .data( "item.autocomplete", item )
307  
-      .append( "<a>" + item.label + "</a>" )
  307
+      .append( $( "<a></a>" ).text( item.label ) )
308 308
       .appendTo( ul );
309 309
   },
310 310
 

0 notes on commit 1f2cfb9 (3 line notes)

erikrose added a note to 1f2cfb9 demos/autocomplete/combobox.html:L60

Mon Jul 19 14:19:12 -0700 2010

Perhaps we should use text() as below so people don't copy this and end up in trouble when the label is "<script>doMaliciousStuff()</script>"?

scottgonzalez added a note to 1f2cfb9 demos/autocomplete/combobox.html:L60 repo collab

Mon Jul 19 14:48:02 -0700 2010

The combobox demo uses HTML to show highlighting, so we can't use .text().

erikrose added a note to 1f2cfb9 demos/autocomplete/combobox.html:L60

Mon Jul 19 14:49:50 -0700 2010

That's what I get for not reading the rest of the file. Never mind, and thanks for the awesome quick fix! :-D

Please log in to comment.
Dedicated Server Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
  • Blog
  • Support
  • Training
  • Job Board
  • Shop
  • Contact
  • API
  • Status
  • © 2010 GitHub Inc. All rights reserved.
  • Terms of Service
  • Privacy
  • Security
  • English
  • Deutsch
  • Français
  • 日本語
  • Português (BR)
  • 中文
  • See all available languages

Your current locale selection: English. Choose another?

  • English
  • Afrikaans
  • Català
  • Čeština
  • Deutsch
  • Español
  • Français
  • Hrvatski
  • Indonesia
  • Italiano
  • 日本語
  • Nederlands
  • Norsk
  • Polski
  • Português (BR)
  • Српски
  • Svenska
  • 中文