Friday, January 22, 2010

Recipe 4: Autocomplete a text field

(This post is one of a series that upadates Chad Fowler's Rails Recipes.)

What. This recipe describes how to implement auto-completion of text fields.

How. Essentially this is done by wiring the Ruby up to the auto completion.

Anachronisms. The auto_complete plugin is now required. This functionality, once part of Rails, has been removed.

Bug. The auto_complete plugin in turn appears to have a bug. The JavaScript methods are expecting to see something returned of the form

  <ul>
<li>Choice One</li>
<li>Choice Two</li>
</ul>

Instead, the plugin seems to return something of the form

  <ul>[<li>Choice One</li>,<li>Choice Two</li>]</ul>

This can be fixed. In the plugin file auto_complete_macros_helper.rb, the last line of the method auto_complete_result is

  content_tag("ul", items.uniq)

This should read

  content_tag("ul", items.uniq.join(""))

No comments:

Post a Comment