views:

1148

answers:

3

How do I make an autocomplete text field like the one here at Stack Overflow for the Tags fields? I want to use it for my Rails app.

A: 

The basic idea is, you trigger AJAX requests to the server, using onkeydown or onkeypress events (preferably with a bit in the way of delays), that do your search using the text entered so far and send back possible completions to the client. The client then does DOM manipulation to display these.

chaos
+2  A: 

Auto-Complete Text Fields in Rails 2

Scott Evernden
+2  A: 

StackOverflow uses the jQuery Autocomplete Plugin, it has multiple item support.

Check the demos.

Snippet from the edit page:

$("#tagnames").autocomplete("/tags/filter", {
 max: 6,
 highlightItem: true,
 multiple: true,
 multipleSeparator: " ",
 matchContains: true,
 scroll: true,
 scrollHeight: 300
});
CMS