Skip to content

Instantly share code, notes, and snippets.

@lifo
Created October 6, 2008 22:58
Show Gist options
  • Save lifo/15170 to your computer and use it in GitHub Desktop.
Save lifo/15170 to your computer and use it in GitHub Desktop.
From ccc9b762dc95b3c465fbc5b5466db4152654edb3 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Tarmo=20T=C3=A4nav?= <[email protected]>
Date: Mon, 6 Oct 2008 17:35:21 +0300
Subject: [PATCH] Implement submit_to_remote as a wrapper around a more generic button_to_remote
Removed the "return false" from submit_to_remote onclick end as
button input elements have no default behavior to cancel.
---
.../lib/action_view/helpers/prototype_helper.rb | 18 +++++++-----------
actionpack/test/template/prototype_helper_test.rb | 6 +++---
2 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb
index ff41a6d..dd32dad 100644
--- a/actionpack/lib/action_view/helpers/prototype_helper.rb
+++ b/actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -405,7 +405,7 @@ module ActionView
# # Generates: <input name="create_btn" onclick="new Ajax.Request('/testing/create',
# # {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)});
# # return false;" type="button" value="Create" />
- # <%= button_to_remote 'create_btn', 'Create', :url => { :action => 'create' } %>
+ # <%= submit_to_remote 'create_btn', 'Create', :url => { :action => 'create' } %>
#
# # Submit to the remote action update and update the DIV succeed or fail based
# # on the success or failure of the request
@@ -413,24 +413,20 @@ module ActionView
# # Generates: <input name="update_btn" onclick="new Ajax.Updater({success:'succeed',failure:'fail'},
# # '/testing/update', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)});
# # return false;" type="button" value="Update" />
- # <%= button_to_remote 'update_btn', 'Update', :url => { :action => 'update' },
+ # <%= submit_to_remote 'update_btn', 'Update', :url => { :action => 'update' },
# :update => { :success => "succeed", :failure => "fail" }
#
# <tt>options</tt> argument is the same as in form_remote_tag.
#
- # Note: This method used to be called submit_to_remote, but that's now just an alias for button_to_remote
- def button_to_remote(name, value, options = {})
+ # Note: This method used to be called submit_to_remote, but that's now just an alias for submit_to_remote
+ 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
+ html_options = options.delete(:html) || {}
+ html_options[:name] = name
- tag("input", options[:html], false)
+ button_to_remote(value, options, html_options)
end
- alias_method :submit_to_remote, :button_to_remote
# Returns '<tt>eval(request.responseText)</tt>' which is the JavaScript function
# that +form_remote_tag+ can call in <tt>:complete</tt> to evaluate a multiple
diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb
index a1f541f..d6b86a3 100644
--- a/actionpack/test/template/prototype_helper_test.rb
+++ b/actionpack/test/template/prototype_helper_test.rb
@@ -218,9 +218,9 @@ class PrototypeHelperTest < PrototypeHelperBaseTest
end
- def test_button_to_remote
- assert_dom_equal %(<input name=\"More beer!\" onclick=\"new Ajax.Updater('empty_bottle', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)}); return false;\" type=\"button\" value=\"1000000\" />),
- button_to_remote("More beer!", 1_000_000, :update => "empty_bottle")
+ def test_submit_to_remote
+ assert_dom_equal %(<input name=\"More beer!\" onclick=\"new Ajax.Updater('empty_bottle', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)});\" type=\"button\" value=\"1000000\" />),
+ submit_to_remote("More beer!", 1_000_000, :update => "empty_bottle")
end
def test_observe_field
--
1.6.0.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment