aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-04-13 05:44:43 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-04-13 05:44:43 +0000
commitf3e5e07982946f05b9826d5701aa95359bb5a10f (patch)
tree27264254b40f71763756e6e0ebb4fa7c4de6643a /actionpack/lib/action_view
parentad24c6d756f1fb0f78028f19b7922cc5490d5d74 (diff)
downloadrails-f3e5e07982946f05b9826d5701aa95359bb5a10f.tar.gz
rails-f3e5e07982946f05b9826d5701aa95359bb5a10f.tar.bz2
rails-f3e5e07982946f05b9826d5701aa95359bb5a10f.zip
Added submit_to_remote that allows you to trigger an Ajax form submition at the click of the submission button, which allows for multiple targets in a single form through the use of multiple submit buttons #930 [yrashk@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1160 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r--actionpack/lib/action_view/helpers/javascript_helper.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb
index 584f33f81d..9e91cd189e 100644
--- a/actionpack/lib/action_view/helpers/javascript_helper.rb
+++ b/actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -92,6 +92,20 @@ module ActionView
tag("form", options[:html], true)
end
+
+ # Returns a button input tag that will submit form using XMLHttpRequest in tghe background instead of regular
+ # reloading POST arrangement. <tt>options</tt> argument is the same as in <tt>form_remote_tag</tt>
+ def submit_to_remote(name,value,options = {})
+ options[:with] = 'Form.serialize(this.form)'
+
+ options[:html] ||= {}
+ options[:html][:type] = 'button'
+ options[:html][:onclick] = "#{remote_function(options)}; return false;"
+ options[:html][:name] = name
+ options[:html][:value] = value
+
+ tag("input", options[:html], false)
+ end
def remote_function(options) #:nodoc: for now
javascript_options = options_for_ajax(options)