Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery UI Autocomplete using both categories and accent folding at the same time
    primarykey
    data
    text
    <p>I'm using the jQuery UI Autocomplete widget. I want to be able to use two different functionalities at the same time - Categories and Accent folding.</p> <p>I can get both working independently using the source code from the jQuery UI website (http://jqueryui.com/autocomplete/).</p> <p>For the categories:</p> <pre><code>&lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;title&gt;jQuery UI Autocomplete - Categories&lt;/title&gt; &lt;link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" /&gt; &lt;script src="http://code.jquery.com/jquery-1.8.2.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" href="/resources/demos/style.css" /&gt; &lt;style&gt; .ui-autocomplete-category { font-weight: bold; padding: .2em .4em; margin: .8em 0 .2em; line-height: 1.5; } &lt;/style&gt; &lt;script&gt; $.widget( "custom.catcomplete", $.ui.autocomplete, { _renderMenu: function( ul, items ) { var that = this, currentCategory = ""; $.each( items, function( index, item ) { if ( item.category != currentCategory ) { ul.append( "&lt;li class='ui-autocomplete-category'&gt;" + item.category + "&lt;/li&gt;" ); currentCategory = item.category; } that._renderItemData( ul, item ); }); } }); &lt;/script&gt; &lt;script&gt; $(function() { var data = [ { label: "anders", category: "" }, { label: "andreas", category: "" }, { label: "antal", category: "" }, { label: "annhhx10", category: "Products" }, { label: "annk K12", category: "Products" }, { label: "annttop C13", category: "Products" }, { label: "anders andersson", category: "People" }, { label: "andreas andersson", category: "People" }, { label: "andreas johnson", category: "People" } ]; $( "#search" ).catcomplete({ delay: 0, source: data }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;label for="search"&gt;Search: &lt;/label&gt; &lt;input id="search" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and for the accent folding:</p> <pre><code>&lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;title&gt;jQuery UI Autocomplete - Accent folding&lt;/title&gt; &lt;link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" /&gt; &lt;script src="http://code.jquery.com/jquery-1.8.2.js"&gt;&lt;/script&gt; &lt;script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" href="/resources/demos/style.css" /&gt; &lt;script&gt; $(function() { var names = [ "Jörn Zaefferer", "Scott González", "John Resig" ]; var accentMap = { "á": "a", "ö": "o" }; var normalize = function( term ) { var ret = ""; for ( var i = 0; i &lt; term.length; i++ ) { ret += accentMap[ term.charAt(i) ] || term.charAt(i); } return ret; }; $( "#developer" ).autocomplete({ source: function( request, response ) { var matcher = new RegExp( $.ui.autocomplete.escapeRegex( request.term ), "i" ); response( $.grep( names, function( value ) { value = value.label || value.value || value; return matcher.test( value ) || matcher.test( normalize( value ) ); }) ); } }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="ui-widget"&gt; &lt;form&gt; &lt;label for="developer"&gt;Developer: &lt;/label&gt; &lt;input id="developer" /&gt; &lt;/form&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I thought I would be able to replace the 'source' in the categories example (which is source: data) with the 'source' in the accent folding example (which is source: function( request, response )......) but this doesn't seem to work.</p> <p>So, how can I combine the functionality of the categories and accent-folding into one autocomplete?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload