This AutoComplete implementation points to a JavaScript array that is available in-memory, allowing for a zippy user interaction without the need for a server-side component. Enabling the prehighlightClassName
and useShadow
features, as well as pulling in the Animation utility, provides an ehanced visual user experience.
Data:
1 | YAHOO.example.Data.arrayStates = [ |
2 | "Alabama", |
3 | "Alaska", |
4 | "Arizona", |
5 | "Arkansas", |
6 | "California", |
7 | "Colorado", |
8 | "Connecticut", |
9 | "Delaware", |
10 | "Florida", |
11 | ... |
12 | ]; |
view plain | print | ? |
CSS:
1 | #myAutoComplete { |
2 | width:15em; /* set width here or else widget will expand to fit its container */ |
3 | padding-bottom:2em; |
4 | } |
view plain | print | ? |
Markup:
1 | <div id="myAutoComplete"> |
2 | <input id="myInput" type="text"> |
3 | <div id="myContainer"></div> |
4 | </div> |
view plain | print | ? |
JavaScript:
1 | YAHOO.example.BasicLocal = function() { |
2 | // Use a LocalDataSource |
3 | var oDS = new YAHOO.util.LocalDataSource(YAHOO.example.Data.arrayStates); |
4 | // Optional to define fields for single-dimensional array |
5 | oDS.responseSchema = {fields : ["state"]}; |
6 | |
7 | // Instantiate the AutoComplete |
8 | var oAC = new YAHOO.widget.AutoComplete("myInput", "myContainer", oDS); |
9 | oAC.prehighlightClassName = "yui-ac-prehighlight"; |
10 | oAC.useShadow = true; |
11 | |
12 | return { |
13 | oDS: oDS, |
14 | oAC: oAC |
15 | }; |
16 | }(); |
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 1344ms (+2) 10:24:46 PM:
AutoComplete instance0 myInput
AutoComplete initialized
INFO 1342ms (+1342) 10:24:46 PM:
DataSource instance0
DataSource initialized
INFO 0ms (+0) 10:24:45 PM:
global
Logger initialized
Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.
Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings