aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/auto_complete.rb11
-rw-r--r--actionpack/lib/action_view/helpers/javascript_helper.rb6
2 files changed, 11 insertions, 6 deletions
diff --git a/actionpack/lib/action_controller/auto_complete.rb b/actionpack/lib/action_controller/auto_complete.rb
index 606f43b350..c2590c66b4 100644
--- a/actionpack/lib/action_controller/auto_complete.rb
+++ b/actionpack/lib/action_controller/auto_complete.rb
@@ -15,13 +15,14 @@ module ActionController
end
module ClassMethods
- def auto_complete_for(object, method)
+ def auto_complete_for(object, method, options = {})
define_method("auto_complete_for_#{object}_#{method}") do
- @items = object.to_s.camelize.constantize.find(
- :all,
+ find_options = {
:conditions => [ "LOWER(#{method}) LIKE ?", '%' + request.raw_post.downcase + '%' ],
- :order => "#{method} ASC"
- )
+ :order => "#{method} ASC",
+ :limit => 10 }.merge!(options)
+
+ @items = object.to_s.camelize.constantize.find(:all, find_options)
render :inline => "<%= auto_complete_result @items, '#{method}' %>"
end
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb
index c73c1e08b0..607b8fe0f9 100644
--- a/actionpack/lib/action_view/helpers/javascript_helper.rb
+++ b/actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -259,6 +259,10 @@ module ActionView
#
# This function expects that the called action returns a HTML <ul> list,
# or nothing if no entries should be displayed for autocompletion.
+ #
+ # You'll probably want to turn the browser's built-in autocompletion off,
+ # su be sure to include a autocomplete="off" attribute with your text
+ # input field.
#
# Required +options+ are:
# <tt>:url</tt>:: Specifies the DOM ID of the element whose
@@ -310,7 +314,7 @@ module ActionView
def text_field_with_auto_complete(object, method, tag_options = {}, completion_options = {})
(completion_options[:skip_style] ? "" : auto_complete_stylesheet) +
- text_field(object, method, tag_options) +
+ text_field(object, method, { :autocomplete => "off" }.merge!(tag_options)) +
content_tag("div", "", :id => "#{object}_#{method}_auto_complete", :class => "auto_complete") +
auto_complete_field("#{object}_#{method}", { :url => { :action => "auto_complete_for_#{object}_#{method}" } }.update(completion_options))
end