Skip to content


Subversion checkout URL

You can clone with
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

82 lines (67 sloc) 2.589 kb
<!-- this is important to tell javascript to treat the strings as UTF-8 -->
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<!-- YUI stylesheets -->
<link rel="stylesheet" type="text/css"
href="" />
<link rel="stylesheet" type="text/css"
href="" />
<!-- YUI libraries -->
<script type="text/javascript"
<script type="text/javascript"
<script type="text/javascript"
<!-- contains accent_fold() and accent_folded_hilite() -->
<script type="text/javascript" src="accent-fold.js"></script>
<body class=" yui-skin-sam">
<div style="width:25em">
<input id="to" type="text" />
<div id="ac"></div>
// our static address book
var addressBook = [
{name:'Fulanito López', email:''},
{name:'Erik Lørgensen', email:''},
{name:'Lorena Smith', email:''},
{name:'James Lö', email:''}
// add an accent-folded "search" field to each entry
for (var i=0; i<addressBook.length; i++) {
addressBook[i]['search'] = accent_fold(addressBook[i]['name']);
var datasource = new YAHOO.util.LocalDataSource(addressBook);
datasource.responseSchema = {fields : ["email", "name", "search"]};
var autocomp = new YAHOO.widget.AutoComplete("to", "ac", datasource);
autocomp.delimChar = [","," "]; // allow multiple entries
// iterate the entire datasource and search for q at the beginning
// of any words in the accent-folded "search" field
autocomp.filterResults = function(q, entries, resultObj, cb) {
var matches = [];
var re = new RegExp('\\b'+accent_fold(q), 'i');
for (var i=0; i<entries.length; i++) {
if (re.test(entries[i]['search'])) {
resultObj.results = matches;
return resultObj;
// create a pretty HTML representation of the match:
autocomp.formatResult = function (entry, q, match) {
var name = accent_folded_hilite(entry[1], q);
var email = accent_folded_hilite(entry[0], q);
return name + ' &lt;' + email + '&gt;';
// address book entries:
Fulanito López
Erik Lørgensen
Lorena Smith
James Lö
try searching for " lo"
Jump to Line
Something went wrong with that request. Please try again.