diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-24 00:52:14 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-24 00:52:14 +0000 |
commit | 96536bebaefccabcbfb5ce9e689dd40c4fb4e294 (patch) | |
tree | 9000f9de158a5bce0ca7f6571637c1fa20361947 /actionpack/lib/action_view/helpers/java_script_macros_helper.rb | |
parent | af60120d30157837d92b02953e04131facd1f7de (diff) | |
download | rails-96536bebaefccabcbfb5ce9e689dd40c4fb4e294.tar.gz rails-96536bebaefccabcbfb5ce9e689dd40c4fb4e294.tar.bz2 rails-96536bebaefccabcbfb5ce9e689dd40c4fb4e294.zip |
Added :select option for JavaScriptMacroHelper#auto_complete_field that makes it easier to only use part of the auto-complete suggestion as the value for insertion [Thomas Fuchs]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3344 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/java_script_macros_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/java_script_macros_helper.rb | 7 |
1 files changed, 6 insertions, 1 deletions
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 f0fc092572..a01f91d8f1 100644 --- a/actionpack/lib/action_view/helpers/java_script_macros_helper.rb +++ b/actionpack/lib/action_view/helpers/java_script_macros_helper.rb @@ -105,6 +105,9 @@ module ActionView # innerHTML is replaced. # <tt>:on_show</tt>:: Like on_hide, only now the expression is called # then the div is shown. + # <tt>:select</tt>:: Pick the class of the element from which the value for + # insertion should be extracted. If this is not specified, + # the entire element is used. def auto_complete_field(field_id, options = {}) function = "new Ajax.Autocompleter(" function << "'#{field_id}', " @@ -115,9 +118,11 @@ 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| + + { :on_show => :onShow, :on_hide => :onHide, :min_chars => :min_chars, :select => :select }.each do |k,v| js_options[v] = options[k] if options[k] end + function << (', ' + options_for_javascript(js_options) + ')') javascript_tag(function) |