mirror of
https://github.com/github/rails.git
synced 2026-01-30 08:48:06 -05:00
Added block-usage to PrototypeHelper#form_remote_tag, document block-usage of FormTagHelper#form_tag [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5346 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
*SVN*
|
||||
|
||||
* Added block-usage to PrototypeHelper#form_remote_tag, document block-usage of FormTagHelper#form_tag [Rick]
|
||||
|
||||
* Add a 0 margin/padding div around the hidden _method input tag that form_tag outputs. [Rick]
|
||||
|
||||
* Added block-usage to TagHelper#content_tag [DHH]. Example:
|
||||
|
||||
<% content_tag :div, :class => "strong" %>
|
||||
|
||||
@@ -12,6 +12,19 @@ module ActionView
|
||||
# Starts a form tag that points the action to an url configured with <tt>url_for_options</tt> just like
|
||||
# ActionController::Base#url_for. The method for the form defaults to POST.
|
||||
#
|
||||
# Examples:
|
||||
# * <tt>form_tag('/posts') => <form action="/posts" method="post"></tt>
|
||||
# * <tt>form_tag('/posts/1', :method => :put) => <form action="/posts/1" method="put"></tt>
|
||||
# * <tt>form_tag('/upload', :multipart => true) => <form action="/upload" method="post" enctype="multipart/form-data"></tt>
|
||||
#
|
||||
# ERb example:
|
||||
# <% form_tag '/posts' do -%>
|
||||
# <div><%= submit_tag 'Save' %></div>
|
||||
# <% end -%>
|
||||
#
|
||||
# Will output:
|
||||
# <form action="/posts" method="post"><div><input type="submit" name="submit" value="Save" /></div></form>
|
||||
#
|
||||
# Options:
|
||||
# * <tt>:multipart</tt> - If set to true, the enctype is set to "multipart/form-data".
|
||||
# * <tt>:method</tt> - The method to use when submitting the form, usually either "get" or "post".
|
||||
@@ -31,7 +44,7 @@ module ActionView
|
||||
html_options["method"] = "post"
|
||||
else
|
||||
html_options["method"] = "post"
|
||||
method_tag = tag(:input, :type => "hidden", :name => "_method", :value => method)
|
||||
method_tag = content_tag(:div, tag(:input, :type => "hidden", :name => "_method", :value => method), :style => 'margin:0;padding:0')
|
||||
end
|
||||
|
||||
if block_given?
|
||||
|
||||
@@ -164,7 +164,12 @@ module ActionView
|
||||
#
|
||||
# By default the fall-through action is the same as the one specified in
|
||||
# the :url (and the default method is :post).
|
||||
def form_remote_tag(options = {})
|
||||
#
|
||||
# form_remote_tag also takes a block, like form_tag:
|
||||
# <% form_remote_tag :url => '/posts' do -%>
|
||||
# <div><%= submit_tag 'Save' %></div>
|
||||
# <% end -%>
|
||||
def form_remote_tag(options = {}, &block)
|
||||
options[:form] = true
|
||||
|
||||
options[:html] ||= {}
|
||||
@@ -172,7 +177,7 @@ module ActionView
|
||||
(options[:html][:onsubmit] ? options[:html][:onsubmit] + "; " : "") +
|
||||
"#{remote_function(options)}; return false;"
|
||||
|
||||
form_tag(options[:html].delete(:action) || url_for(options[:url]), options[:html])
|
||||
form_tag(options[:html].delete(:action) || url_for(options[:url]), options[:html], &block)
|
||||
end
|
||||
|
||||
# Works like form_remote_tag, but uses form_for semantics.
|
||||
|
||||
@@ -20,9 +20,9 @@ module ActionView
|
||||
# <tt><div class="strong"><p>Hello world!</p></div></tt>
|
||||
#
|
||||
# ERb example:
|
||||
# <% content_tag :div, :class => "strong" %>
|
||||
# <% content_tag :div, :class => "strong" do -%>
|
||||
# Hello world!
|
||||
# <% end %>
|
||||
# <% end -%>
|
||||
#
|
||||
# Will output:
|
||||
# <div class="strong"><p>Hello world!</p></div>
|
||||
|
||||
@@ -256,7 +256,7 @@ class FormHelperTest < Test::Unit::TestCase
|
||||
|
||||
expected =
|
||||
"<form action='http://www.example.com' id='create-post' method='post'>" +
|
||||
"<input name='_method' type='hidden' value='put' />" +
|
||||
"<div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div>" +
|
||||
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
|
||||
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
|
||||
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
|
||||
|
||||
@@ -36,7 +36,7 @@ class FormTagHelperTest < Test::Unit::TestCase
|
||||
|
||||
def test_form_tag_with_method
|
||||
actual = form_tag({}, { :method => :put })
|
||||
expected = %(<form action="http://www.example.com" method="post"><input type="hidden" name="_method" value="put" />)
|
||||
expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>)
|
||||
assert_dom_equal expected, actual
|
||||
end
|
||||
|
||||
@@ -52,7 +52,7 @@ class FormTagHelperTest < Test::Unit::TestCase
|
||||
_erbout = ''
|
||||
form_tag("http://example.com", :method => :put) { _erbout.concat "Hello world!" }
|
||||
|
||||
expected = %(<form action="http://www.example.com" method="post"><input type="hidden" name="_method" value="put" />Hello world!</form>)
|
||||
expected = %(<form action="http://www.example.com" method="post"><div style='margin:0;padding:0'><input type="hidden" name="_method" value="put" /></div>Hello world!</form>)
|
||||
assert_dom_equal expected, _erbout
|
||||
end
|
||||
|
||||
|
||||
@@ -69,9 +69,15 @@ class PrototypeHelperTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_form_remote_tag_with_method
|
||||
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\"><input name='_method' type='hidden' value='put' />),
|
||||
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\"><div style='margin:0;padding:0'><input name='_method' type='hidden' value='put' /></div>),
|
||||
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, :html => { :method => :put })
|
||||
end
|
||||
|
||||
def test_form_remote_tag_with_block
|
||||
_erbout = ''
|
||||
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }) { _erbout.concat "Hello world!" }
|
||||
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">Hello world!</form>), _erbout
|
||||
end
|
||||
|
||||
def test_on_callbacks
|
||||
callbacks = [:uninitialized, :loading, :loaded, :interactive, :complete, :success, :failure]
|
||||
|
||||
Reference in New Issue
Block a user