mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
1e08d11579
commit
e7afaf62bd
3 changed files with 27 additions and 2 deletions
|
@ -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]
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue