From a20914822ed2f68525c3531c24d19eb188cce529 Mon Sep 17 00:00:00 2001 From: Ken Collins Date: Tue, 24 Feb 2009 13:00:31 -0500 Subject: [PATCH] Allow remote forms to use the standard link_to_remote options :with/:submit. --- .../lib/action_view/helpers/prototype_helper.rb | 6 +++--- actionpack/test/template/prototype_helper_test.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index 18a209d..f1803fd 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -1048,12 +1048,12 @@ module ActionView js_options['insertion'] = "'#{options[:position].to_s.downcase}'" if options[:position] js_options['evalScripts'] = options[:script].nil? || options[:script] - if options[:form] - js_options['parameters'] = 'Form.serialize(this)' - elsif options[:submit] + if options[:submit] js_options['parameters'] = "Form.serialize('#{options[:submit]}')" elsif options[:with] js_options['parameters'] = options[:with] + elsif options[:form] + js_options['parameters'] = 'Form.serialize(this)' end if protect_against_forgery? && !options[:form] diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb index d6b86a3..f12cfea 100644 --- a/actionpack/test/template/prototype_helper_test.rb +++ b/actionpack/test/template/prototype_helper_test.rb @@ -92,6 +92,13 @@ class PrototypeHelperTest < PrototypeHelperBaseTest assert_dom_equal %(Remote), link_to_remote("Remote", { :url => { :action => "whatnot's" } }) end + + def test_link_to_remote_submit_and_with_options + assert_dom_equal %(Submit Form), + link_to_remote("Submit Form", :url => {:action => "whatnot"}, :submit => 'table_row_1') + assert_dom_equal %(Submit Form), + link_to_remote("Submit Form", :url => {:action => "whatnot"}, :with => 'serializeTableRow(1)') + end def test_button_to_remote assert_dom_equal %(), @@ -128,6 +135,13 @@ class PrototypeHelperTest < PrototypeHelperBaseTest assert_dom_equal %(
), form_remote_tag(:update => { :success => 'glass_of_beer', :failure => "glass_of_water" }, :url => { :action => :fast }) end + + def test_form_remote_tag_using_submit_and_with_options + assert_dom_equal %(), + form_remote_tag(:url => {:action => "fast"}, :submit => 'table_row_1') + assert_dom_equal %(), + form_remote_tag(:url => {:action => "fast"}, :with => 'serializeTableRow(1)') + end def test_form_remote_tag_with_method assert_dom_equal %(
), -- 1.6.1