YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: AutoComplete Control: Basic Local Data

# AutoComplete Control: Basic Local Data

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.

View example in new window.

Enter a state:

## Sample Code

Data:

YAHOO.example.Data.arrayStates = [ "Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", ... ];

CSS:

#myAutoComplete { width:15em; /* set width here or else widget will expand to fit its container */ padding-bottom:2em; }

Markup:

<label for="myInput">Enter a state:</label> <div id="myAutoComplete"> <input id="myInput" type="text"> <div id="myContainer"></div> </div>

JavaScript:

YAHOO.example.BasicLocal = function() { // Use a LocalDataSource var oDS = new YAHOO.util.LocalDataSource(YAHOO.example.Data.arrayStates); // Optional to define fields for single-dimensional array oDS.responseSchema = {fields : ["state"]}; // Instantiate the AutoComplete var oAC = new YAHOO.widget.AutoComplete("myInput", "myContainer", oDS); oAC.prehighlightClassName = "yui-ac-prehighlight"; oAC.useShadow = true; return { oDS: oDS, oAC: oAC }; }();

## Configuration for This Example

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.

### YUI Logger Output:

Note: You are viewing this example in debug mode with logging enabled. This can significantly slow performance.

Reload with logging
and debugging disabled.

### AutoComplete Control Examples:

### More AutoComplete Control Resources:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2010 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings