diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-18 21:27:05 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-05-18 21:27:05 +0000 |
commit | 4221494348f06b0c44446a44571c8ad8b74e1da6 (patch) | |
tree | 647820e2c4ddf97ee6eea359dec26dab56c97a2c /actionpack/lib/action_view | |
parent | c597e7d9ac82a1c393c645fce06f615ed5abba87 (diff) | |
download | rails-4221494348f06b0c44446a44571c8ad8b74e1da6.tar.gz rails-4221494348f06b0c44446a44571c8ad8b74e1da6.tar.bz2 rails-4221494348f06b0c44446a44571c8ad8b74e1da6.zip |
observe_form always sends the serialized form. Closes #5271.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6775 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/prototype_helper.rb | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 1586a99e4c..8c3cd907ff 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -261,8 +261,10 @@ module ActionView return function end - # Observes the field with the DOM ID specified by +field_id+ and makes - # an Ajax call when its contents have changed. + # Observes the field with the DOM ID specified by +field_id+ and calls a + # callback when its contents have changed. The default callback is an + # Ajax call. By default the value of the observed field is sent as a + # parameter with the Ajax call. # # Required +options+ are either of: # <tt>:url</tt>:: +url_for+-style options for the action to call @@ -279,14 +281,24 @@ module ActionView # <tt>:update</tt>:: Specifies the DOM ID of the element whose # innerHTML should be updated with the # XMLHttpRequest response text. - # <tt>:with</tt>:: A JavaScript expression specifying the - # parameters for the XMLHttpRequest. This defaults - # to 'value', which in the evaluated context - # refers to the new field value. If you specify a - # string without a "=", it'll be extended to mean - # the form key that the value should be assigned to. - # So :with => "term" gives "'term'=value". If a "=" is - # present, no extension will happen. + # <tt>:with</tt>:: A JavaScript expression specifying the parameters + # for the XMLHttpRequest. The default is to send the + # key and value of the observed field. Any custom + # expressions should return a valid URL query string. + # The value of the field is stored in the JavaScript + # variable +value+. + # + # Examples + # + # :with => "'my_custom_key=' + value" + # :with => "'person[name]=' + prompt('New name')" + # :with => "Form.Element.serialize('other-field')" + # + # Finally + # :with => 'name' + # is shorthand for + # :with => "'name=' + value" + # This essentially just changes the key of the parameter. # <tt>:on</tt>:: 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, @@ -302,11 +314,15 @@ module ActionView build_observer('Form.Element.EventObserver', field_id, options) end end - - # Like +observe_field+, but operates on an entire form identified by the - # DOM ID +form_id+. +options+ are the same as +observe_field+, except - # the default value of the <tt>:with</tt> option evaluates to the - # serialized (request string) value of the form. + + # Observes the form with the DOM ID specified by +form_id+ and calls a + # callback when its contents have changed. The default callback is an + # Ajax call. By default all fields of the observed field are sent as + # parameters with the Ajax call. + # + # The +options+ for +observe_form+ are the same as the options for + # +observe_field+. The JavaScript variable +value+ available to the + # <tt>:with</tt> option is set to the serialized form by default. def observe_form(form_id, options = {}) if options[:frequency] build_observer('Form.Observer', form_id, options) @@ -682,10 +698,10 @@ module ActionView end def build_observer(klass, name, options = {}) - if options[:with] && !options[:with].include?("=") + if options[:with] && (options[:with] !~ /[=(.]/) options[:with] = "'#{options[:with]}=' + value" else - options[:with] ||= 'value' if options[:update] + options[:with] ||= 'value' unless options[:function] end callback = options[:function] || remote_function(options) |