YUI recommends YUI 3.
YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.
This AutoComplete implementation points to an online script that serves a data as delimited plain text. Enabling caching on the DataSource can reduce trips to the server and speed performance for repeated queries.
Implementers who are working with data from third-party sources, user input data, or otherwise untrustworthy sources should be sure to read the Security Considerations section of the AutoComplete user guide.
Data:
1 | ... |
2 | food and drink 1924 |
3 | food basic 1075 |
4 | food carts 1042 |
5 | ... |
view plain | print | ? |
CSS:
1 | #myAutoComplete { |
2 | width:25em; /* set width here or else widget will expand to fit its container */ |
3 | padding-bottom:2em; |
4 | } |
view plain | print | ? |
Markup:
1 | <label for="myInput">Search our database:</label> |
2 | <div id="myAutoComplete"> |
3 | <input id="myInput" type="text"> |
4 | <div id="myContainer"></div> |
5 | </div> |
view plain | print | ? |
JavaScript:
1 | YAHOO.example.BasicRemote = function() { |
2 | // Use an XHRDataSource |
3 | var oDS = new YAHOO.util.XHRDataSource("assets/php/ysearch_flat.php"); |
4 | // Set the responseType |
5 | oDS.responseType = YAHOO.util.XHRDataSource.TYPE_TEXT; |
6 | // Define the schema of the delimited results |
7 | oDS.responseSchema = { |
8 | recordDelim: "\n", |
9 | fieldDelim: "\t" |
10 | }; |
11 | // Enable caching |
12 | oDS.maxCacheEntries = 5; |
13 | |
14 | // Instantiate the AutoComplete |
15 | var oAC = new YAHOO.widget.AutoComplete("myInput", "myContainer", oDS); |
16 | |
17 | return { |
18 | oDS: oDS, |
19 | oAC: oAC |
20 | }; |
21 | }(); |
view plain | print | ? |
You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.
INFO 56ms (+0) 1:12:56 AM:
LogReader instance0
LogReader initialized
INFO 56ms (+1) 1:12:56 AM:
Get
Appending node: ../../../2.x/build/event-mouseenter/event-mouseenter-min.js
INFO 55ms (+0) 1:12:56 AM:
Get
attempting to load ../../../2.x/build/event-mouseenter/event-mouseenter-min.js
INFO 55ms (+49) 1:12:56 AM:
Get
_next: q0, loaded: undefined
INFO 6ms (+2) 1:12:56 AM:
AutoComplete instance0 myInput
AutoComplete initialized
INFO 4ms (+4) 1:12:56 AM:
DataSource instance0
DataSource initialized
INFO 0ms (+0) 1:12:56 AM:
global
Logger initialized
Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.
Copyright © 2011 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings