Skip to content
Browse files

Add additional autocompleter options [aballai, Thomas Fuchs]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4131 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent a3f2013 commit 1fcc60895b9fa9d969649dca46b861fa38263b90 @madrobby madrobby committed
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Add additional autocompleter options [aballai, Thomas Fuchs]
+
* Fixed fragment caching of binary data on Windows #4493 [bellis@deepthought.org]
* Applied Prototype $() performance patches (#4465, #4477) and updated script.aculo.us [Sam Stephenson, Thomas Fuchs]
View
11 actionpack/lib/action_view/helpers/java_script_macros_helper.rb
@@ -101,6 +101,8 @@ def in_place_editor_field(object, method, tag_options = {}, in_place_editor_opti
# <tt>:with</tt>:: A JavaScript expression specifying the
# parameters for the XMLHttpRequest. This defaults
# to 'fieldname=value'.
+ # <tt>:frequency</tt>:: Determines the time to wait after the last keystroke
+ # for the AJAX request to be initiated.
# <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
@@ -119,6 +121,11 @@ def in_place_editor_field(object, method, tag_options = {}, in_place_editor_opti
# innerHTML is replaced.
# <tt>:on_show</tt>:: Like on_hide, only now the expression is called
# then the div is shown.
+ # <tt>:after_update_element</tt>:: A Javascript expression that is called when the
+ # user has selected one of the proposed values.
+ # The expression should take two variables: element and value.
+ # Element is a DOM element for the field, value
+ # is the value selected by the user.
# <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.
@@ -133,8 +140,10 @@ def auto_complete_field(field_id, options = {})
js_options[:callback] = "function(element, value) { return #{options[:with]} }" if options[:with]
js_options[:indicator] = "'#{options[:indicator]}'" if options[:indicator]
js_options[:select] = "'#{options[:select]}'" if options[:select]
+ js_options[:frequency] = "#{options[:frequency]}" if options[:frequency]
- { :on_show => :onShow, :on_hide => :onHide, :min_chars => :minChars }.each do |k,v|
+ { :after_update_element => :afterUpdateElement,
+ :on_show => :onShow, :on_hide => :onHide, :min_chars => :minChars }.each do |k,v|
js_options[v] = options[k] if options[k]
end
View
9 actionpack/test/template/java_script_macros_helper_test.rb
@@ -31,8 +31,13 @@ def test_auto_complete_field
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => [',']);
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {minChars:3})\n//]]>\n</script>),
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :min_chars => 3);
- assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {onHide:function(element, update){Alert('me');}})\n//]]>\n</script>),
- auto_complete_field("some_input", :url => { :action => "autocomplete" }, :on_hide => "function(element, update){Alert('me');}");
+ assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {onHide:function(element, update){alert('me');}})\n//]]>\n</script>),
+ auto_complete_field("some_input", :url => { :action => "autocomplete" }, :on_hide => "function(element, update){alert('me');}");
+ assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {frequency:2})\n//]]>\n</script>),
+ auto_complete_field("some_input", :url => { :action => "autocomplete" }, :frequency => 2);
+ assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nvar some_input_auto_completer = new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {afterUpdateElement:function(element,value){alert('You have chosen: '+value)}})\n//]]>\n</script>),
+ auto_complete_field("some_input", :url => { :action => "autocomplete" },
+ :after_update_element => "function(element,value){alert('You have chosen: '+value)}");
end
def test_auto_complete_result

0 comments on commit 1fcc608

Please sign in to comment.
Something went wrong with that request. Please try again.