YUI Library Home

Site Search (YDN & YUIBlog):

# YUI Library Examples: AutoComplete Control: Tagging Example with alwaysShowContainer

# AutoComplete Control: Tagging Example with alwaysShowContainer

This AutoComplete interaction uses the `alwaysShowContainer` feature to allow users to find and select tags. Showing the set of previously used tags as a visual enhancement discourages unneccessary duplication of similar tags. As is common for tagging, comma- and semi-colon delimiters have also been enabled. Note that an initial query is needed on page load to get the container to display the first time with the full set of data. Since the container is meant to stay open, CSS is used to give it proper real estate on the page, including scrolling to show a potentially long list of tags.

View example in new window.

Assign tags:

## Sample Code

Data:

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

CSS:

#myAutoComplete { width:20em; /* set width here or else widget will expand to fit its container */ padding-bottom:20em; /* allow enough real estate for the container */ } .yui-skin-sam .yui-ac-content { /* set scrolling */ max-height:18em;overflow:auto;overflow-x:hidden; /* set scrolling */ _height:18em; /* ie6 */ }

Markup:

<label for="myInput">Assign tags:</label> <div id="myAutoComplete"> <input id="myInput" type="text"> <div id="myContainer"></div> </div>

JavaScript:

YAHOO.example.TagsAlwaysShow = function() { // Use a LocalDataSource var oDS = new YAHOO.util.LocalDataSource(YAHOO.example.Data.tags); // Optional to define fields for single-dimensional array oDS.responseSchema = {fields : ["tag"]}; // Instantiate the AutoComplete var oAC = new YAHOO.widget.AutoComplete("myInput", "myContainer", oDS); oAC.alwaysShowContainer = true; oAC.minQueryLength = 0; // Can be 0, which will return all results oAC.maxResultsDisplayed = 100; // Show more results, scrolling is enabled via CSS oAC.delimChar = [",",";"]; // Enable comma and semi-colon delimiters oAC.autoHighlight = false; // Auto-highlighting interferes with adding new tags oAC.sendQuery(""); // Populate list to start a new interaction oAC.itemSelectEvent.subscribe(function(sType, aArgs) { oAC.sendQuery(""); }); 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: Logging and debugging is currently turned off for this example.

Reload with logging
and debugging enabled.

### AutoComplete Control Examples:

- Basic Local Data
- Basic Remote Data
- Screenreader Accessibility
- Customizing Remote Requests
- Custom Formatting, with a Proxyless Remote DataSource
- Searching Field A, Submitting Field B with itemSelectEvent
- Combobox, with CSS for Multiple Stacked Instances
- Tagging Example with alwaysShowContainer
- FunctionDataSource to Search Multiple Fields of an Address Book at Runtime
- Centering AutoComplete On a Page
- Subset Matching
- Find Photos on Flickr
- Configurations Dashboard
- Skinning Model
- Flickr Image Search (included with examples for Rich Text Editor)
- Logger Integration with YUI Components (included with examples for Logger Control)
- Datatable with Autocomplete (included with examples for DataTable Control)
- Complex Application (included with examples for Layout Manager)

### 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