mirror of
https://github.com/github/rails.git
synced 2026-01-29 08:18:03 -05:00
Add additional autocompleter options [aballai, Thomas Fuchs]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4131 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -101,6 +101,8 @@ module ActionView
|
||||
# <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 @@ module ActionView
|
||||
# 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 @@ module ActionView
|
||||
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
|
||||
|
||||
|
||||
@@ -31,8 +31,13 @@ class JavaScriptMacrosHelperTest < Test::Unit::TestCase
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user