From e7afaf62bd9f6d3e7e7bf8b37d54d157ac6a3d6d Mon Sep 17 00:00:00 2001 From: Thomas Fuchs Date: Sat, 1 Oct 2005 05:43:53 +0000 Subject: Added new scriptaculous options for auto_complete_field #2343 [m.stienstra@fngtps.com] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2431 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../helpers/java_script_macros_helper.rb | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_view/helpers/java_script_macros_helper.rb') diff --git a/actionpack/lib/action_view/helpers/java_script_macros_helper.rb b/actionpack/lib/action_view/helpers/java_script_macros_helper.rb index 1cc814feaf..f4c99d422a 100644 --- a/actionpack/lib/action_view/helpers/java_script_macros_helper.rb +++ b/actionpack/lib/action_view/helpers/java_script_macros_helper.rb @@ -85,8 +85,24 @@ module ActionView # :with:: A JavaScript expression specifying the # parameters for the XMLHttpRequest. This defaults # to 'fieldname=value'. - # :indicator:: Specifies the DOM ID of an elment which will be - # displayed while autocomplete is running. + # :indicator:: Specifies the DOM ID of an element which will be + # displayed while autocomplete is running. + # :tokens:: A string or an array of strings containing + # seperator tokens for tokenized incremental + # autocompletion. Example: :tokens => ',' would + # allow multiple autocompletion entries, seperated + # by commas. + # :min_chars:: The minimum number of characters that should be + # in the input field before an Ajax call is made + # to the server. + # :on_hide:: A Javascript expression that is called when the + # autocompletion div is hidden. The expression + # should take two variables: element and update. + # Element is a DOM element for the field, update + # is a DOM element for the div from which the + # innerHTML is replaced. + # :on_show:: Like on_hide, only now the expression is called + # then the div is shown. def auto_complete_field(field_id, options = {}) function = "new Ajax.Autocompleter(" function << "'#{field_id}', " @@ -97,6 +113,9 @@ module ActionView js_options[:tokens] = array_or_string_for_javascript(options[:tokens]) if options[:tokens] js_options[:callback] = "function(element, value) { return #{options[:with]} }" if options[:with] js_options[:indicator] = "'#{options[:indicator]}'" if options[:indicator] + {:on_show => :onShow, :on_hide => :onHide, :min_chars => :min_chars}.each do |k,v| + js_options[v] = options[k] if options[k] + end function << (', ' + options_for_javascript(js_options) + ')') javascript_tag(function) -- cgit v1.2.3