diff options
author | Thomas Fuchs <thomas@fesch.at> | 2005-10-01 05:43:53 +0000 |
---|---|---|
committer | Thomas Fuchs <thomas@fesch.at> | 2005-10-01 05:43:53 +0000 |
commit | e7afaf62bd9f6d3e7e7bf8b37d54d157ac6a3d6d (patch) | |
tree | 7e5d1717e1126dce29357cf8b351bbb24d1bca06 /actionpack | |
parent | 1e08d11579f0080f086a6bfea1693826a0c09c95 (diff) | |
download | rails-e7afaf62bd9f6d3e7e7bf8b37d54d157ac6a3d6d.tar.gz rails-e7afaf62bd9f6d3e7e7bf8b37d54d157ac6a3d6d.tar.bz2 rails-e7afaf62bd9f6d3e7e7bf8b37d54d157ac6a3d6d.zip |
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
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/java_script_macros_helper.rb | 23 | ||||
-rw-r--r-- | actionpack/test/template/java_script_macros_helper_test.rb | 4 |
3 files changed, 27 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index b252286202..0c7db0ee2a 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Added new scriptaculous options for auto_complete_field #2343 [m.stienstra@fngtps.com] + * Don't prepend the asset host if the string is already a fully-qualified URL * Updated to script.aculo.us V1.5.0_rc2 and Prototype to V1.4.0_pre7 [Thomas Fuchs] 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 # <tt>:with</tt>:: A JavaScript expression specifying the # parameters for the XMLHttpRequest. This defaults # to 'fieldname=value'. - # <tt>:indicator</tt>:: Specifies the DOM ID of an elment which will be - # displayed while autocomplete is running. + # <tt>:indicator</tt>:: Specifies the DOM ID of an element which will be + # displayed while autocomplete is running. + # <tt>:tokens</tt>:: A string or an array of strings containing + # seperator tokens for tokenized incremental + # autocompletion. Example: <tt>:tokens => ','</tt> would + # allow multiple autocompletion entries, seperated + # by commas. + # <tt>:min_chars</tt>:: The minimum number of characters that should be + # in the input field before an Ajax call is made + # to the server. + # <tt>:on_hide</tt>:: 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. + # <tt>:on_show</tt>:: 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) diff --git a/actionpack/test/template/java_script_macros_helper_test.rb b/actionpack/test/template/java_script_macros_helper_test.rb index 9f1b6181c5..5f96d06861 100644 --- a/actionpack/test/template/java_script_macros_helper_test.rb +++ b/actionpack/test/template/java_script_macros_helper_test.rb @@ -29,6 +29,10 @@ class JavaScriptMacrosHelperTest < Test::Unit::TestCase auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => ','); assert_dom_equal %(<script type=\"text/javascript\">new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:[',']})</script>), auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => [',']); + assert_dom_equal %(<script type=\"text/javascript\">new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {min_chars:3})</script>), + auto_complete_field("some_input", :url => { :action => "autocomplete" }, :min_chars => 3); + assert_dom_equal %(<script type=\"text/javascript\">new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {onHide:function(element, update){Alert('me');}})</script>), + auto_complete_field("some_input", :url => { :action => "autocomplete" }, :on_hide => "function(element, update){Alert('me');}"); end def test_auto_complete_result |