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 | <label for="myInput">Enter a state:</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.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.
Note: Logging and debugging is currently turned off for this example.
Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Copyright Policy - Job Openings