<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example: Remote Data via YQL</title>
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/css/main.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="../../build/yui/yui-min.js"></script>
</head>
<body>
<!--
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
-->
<div id="doc">
<div id="hd">
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
</div>
<h1>Example: Remote Data via YQL</h1>
<div class="yui3-g">
<div class="yui3-u-3-4">
<div id="main">
<div class="content"><style scoped>
#ac-input { width: 250px; }
</style>
<div class="intro">
<p>
This example demonstrates how to provide autocomplete suggestions using a YQL query as the source. In this case, we're using a custom <a href="http://developer.yahoo.com/yql/console/?q=select%20*%20from%20search.suggest%20where%20query%3D%22yui%20autocomplete%22&env=http%3A%2F%2Fpieisgood.org%2Fyql%2Ftables.env"><code>search.suggest</code> YQL table</a> to provide suggestions based on popular Yahoo! Search queries.
</p>
</div>
<div class="example">
<div id="demo" class="yui3-skin-sam"> <!-- You need this skin class -->
<label for="ac-input">Search:</label><br>
<input id="ac-input" type="text">
</div>
<script>
YUI().use('autocomplete', 'autocomplete-highlighters', function (Y) {
Y.one('#ac-input').plug(Y.Plugin.AutoComplete, {
resultHighlighter: 'phraseMatch',
source: 'select * from search.suggest where query="{query}"',
yqlEnv: 'http://pieisgood.org/yql/tables.env'
});
});
</script>
</div>
<h2>HTML</h2>
<p>
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the
page's <code><body></code> element or to a parent element of the widget in order to apply
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>.
</p>
<pre class="code prettyprint"><div id="demo" class="yui3-skin-sam"> <!-- You need this skin class -->
<label for="ac-input">Search:</label><br>
<input id="ac-input" type="text">
</div></pre>
<h2>JavaScript</h2>
<pre class="code prettyprint">YUI().use('autocomplete', 'autocomplete-highlighters', function (Y) {
Y.one('#ac-input').plug(Y.Plugin.AutoComplete, {
resultHighlighter: 'phraseMatch',
source: 'select * from search.suggest where query="{query}"',
yqlEnv: 'http://pieisgood.org/yql/tables.env'
});
});</pre>
<h2>Complete Example Source</h2>
<pre class="code prettyprint"><div id="demo" class="yui3-skin-sam"> <!-- You need this skin class -->
<label for="ac-input">Search:</label><br>
<input id="ac-input" type="text">
</div>
<script>
YUI().use('autocomplete', 'autocomplete-highlighters', function (Y) {
Y.one('#ac-input').plug(Y.Plugin.AutoComplete, {
resultHighlighter: 'phraseMatch',
source: 'select * from search.suggest where query="{query}"',
yqlEnv: 'http://pieisgood.org/yql/tables.env'
});
});
</script></pre>
</div>
</div>
</div>
<div class="yui3-u-1-4">
<div class="sidebar">
<div class="sidebox">
<div class="hd">
<h2 class="no-toc">Examples</h2>
</div>
<div class="bd">
<ul class="examples">
<li data-description="How to provide autocomplete suggestions from a local array.">
<a href="ac-local.html">Basic Local Data</a>
</li>
<li data-description="How to provide autocomplete suggestions using a remote JSONP source.">
<a href="ac-jsonp.html">Remote Data via JSONP</a>
</li>
<li data-description="How to provide autocomplete suggestions using a YQL query source.">
<a href="ac-yql.html">Remote Data via YQL</a>
</li>
<li data-description="How to provide autocomplete suggestions using a DataSource instance.">
<a href="ac-datasource.html">Remote Data via DataSource</a>
</li>
<li data-description="How to implement delimited tag completion.">
<a href="ac-tagging.html">Tag Completion Using Query Delimiters</a>
</li>
<li data-description="How to find and select Flickr photos using a YQL source and a custom autocomplete result formatter.">
<a href="ac-flickr.html">Find Photos on Flickr (Custom Formatting, YQL Source)</a>
</li>
<li data-description="How to use autocomplete-base to filter a set of existing items on a page.">
<a href="ac-filter.html">Filter a Set of Existing Items on a Page</a>
</li>
<li data-description="How to find an address using a YQL source calling Google's Geocoding Service">
<a href="ac-geocode.html">Address Completion on Google's Geocoding Service</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script>
YUI.Env.Tests = {
examples: [],
project: '../assets',
assets: '../assets/autocomplete',
name: 'ac-yql',
title: 'Remote Data via YQL',
newWindow: '',
auto: false
};
YUI.Env.Tests.examples.push('ac-local');
YUI.Env.Tests.examples.push('ac-jsonp');
YUI.Env.Tests.examples.push('ac-yql');
YUI.Env.Tests.examples.push('ac-datasource');
YUI.Env.Tests.examples.push('ac-tagging');
YUI.Env.Tests.examples.push('ac-flickr');
YUI.Env.Tests.examples.push('ac-filter');
YUI.Env.Tests.examples.push('ac-geocode');
</script>
<script src="../assets/yui/test-runner.js"></script>
</body>
</html>