This enhancements adds complete support for remote autocompletion for text fields.
Tested in Firefox 1.0 (Mac/Win), IE 5.5., IE 6.0, Safari. Opera 7.23 is reportedly broken.
What's in:
- new Ajax.Autocomplete Jacascript Object, some Helper Javascript Objects
- JavascriptHelper.autocomplete_for Helper (see RDoc)
- JavascriptHelper.autocomplete_responder (see RDoc)
- FormHelper.text_field now supports :remote_autocomplete and :indicator (no Doc yet)
- Special handling for IE, so select elements won't overlap the autocomplete popup
- HTML-Elements in autocomplete return are stripped before they are put in the text
field, so you can have images and other markup in the autocomplete popup
Example usage:
Action:
def autocomplete
@items = Item.find_all [ 'LOWER(description) LIKE ?', '%' + @params["for"].downcase + '%' ], 'description ASC', 10
@mark = @params["for"]
render_without_layout
end
View:
<%= autocomplete_responder @items, 'description', @mark %>
Form:
<%= text_field 'items', 'description',
{ :remote_autocomplete => { :controller => 'upload', :action => 'autocomplete' },
:indicator => '/images/indicator.gif'
} %>
Notes:
The addition of @controller = @template_object.controller # url_for in :remote_autocomplete breaks many tests (but not the real functionality), hopefully someone can look after that and find a solution.