From 10cf9ecafc4b1953cf8289e530cab7a0a751b9c4 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 3 Jan 2006 04:11:51 +0000 Subject: Added assignment of the Autocompleter object created by JavaScriptMacroHelper#auto_complete_field to a local javascript variables [DHH] Added :on option for PrototypeHelper#observe_field that allows you to specify a different callback hook to have the observer trigger on [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3378 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/prototype_helper.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_view/helpers/prototype_helper.rb') diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index a9a68f474b..d35334a98c 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -337,11 +337,16 @@ module ActionView # parameters for the XMLHttpRequest. This defaults # to 'value', which in the evaluated context # refers to the new field value. + # :on:: Specifies which event handler to observe. By default, + # it's set to "changed" for text fields and areas and + # "click" for radio buttons and checkboxes. With this, + # you can specify it instead to be "blur" or "focus" or + # any other event. # # Additionally, you may specify any of the options documented in # link_to_remote. def observe_field(field_id, options = {}) - if options[:frequency] and options[:frequency] > 0 + if options[:frequency] && options[:frequency] > 0 build_observer('Form.Element.Observer', field_id, options) else build_observer('Form.Element.EventObserver', field_id, options) @@ -567,7 +572,9 @@ module ActionView javascript = "new #{klass}('#{name}', " javascript << "#{options[:frequency]}, " if options[:frequency] javascript << "function(element, value) {" - javascript << "#{callback}})" + javascript << "#{callback}}" + javascript << ", '#{options[:on]}'" if options[:on] + javascript << ")" javascript_tag(javascript) end -- cgit v1.2.3