Permalink
Browse files

Fix label form helper to use I18n and html options, without the need …

…of 'nil' text param:

  Before: f.label :title, nil, :class => 'title'
  After : f.label :title, :class => 'title'

[#5267 state:committed]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
1 parent fb0bd8c commit 11614bddc015deff7095bdf8bbe9f11e5d81ae1c @carlosantoniodasilva carlosantoniodasilva committed with spastorino Aug 1, 2010
Showing with 13 additions and 5 deletions.
  1. +4 −3 actionpack/lib/action_view/helpers/form_helper.rb
  2. +9 −2 actionpack/test/template/form_helper_test.rb
View
7 actionpack/lib/action_view/helpers/form_helper.rb
@@ -215,7 +215,7 @@ module FormHelper
# ...
# <% end %>
#
- # If your resource has associations defined, for example, you want to add comments
+ # If your resource has associations defined, for example, you want to add comments
# to the post given that the routes are set correctly:
#
# <%= form_for([@document, @comment]) do |f| %>
@@ -583,8 +583,9 @@ def fields_for(record_or_name_or_array, *args, &block)
# 'Accept <a href="/terms">Terms</a>.'
# end
def label(object_name, method, content_or_options = nil, options = nil, &block)
- if block_given?
- options = content_or_options if content_or_options.is_a?(Hash)
+ content_is_options = content_or_options.is_a?(Hash)
+ if content_is_options || block_given?
+ options = content_or_options if content_is_options
text = nil
else
text = content_or_options
View
11 actionpack/test/template/form_helper_test.rb
@@ -120,6 +120,13 @@ def test_label_with_locales_symbols
I18n.locale = old_locale
end
+ def test_label_with_locales_and_options
+ old_locale, I18n.locale = I18n.locale, :label
+ assert_dom_equal('<label for="post_body" class="post_body">Write entire text here</label>', label(:post, :body, :class => 'post_body'))
+ ensure
+ I18n.locale = old_locale
+ end
+
def test_label_with_for_attribute_as_symbol
assert_dom_equal('<label for="my_for">Title</label>', label(:post, :title, nil, :for => "my_for"))
end
@@ -620,15 +627,15 @@ def test_form_for
def test_form_for_with_symbol_object_name
form_for(@post, :as => "other_name", :html => { :id => 'create-post' }) do |f|
- concat f.label(:title)
+ concat f.label(:title, :class => 'post_title')
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
concat f.submit('Create post')
end
expected = whole_form("/posts/123", "create-post", "other_name_edit", :method => "put") do
- "<label for='other_name_title'>Title</label>" +
+ "<label for='other_name_title' class='post_title'>Title</label>" +
"<input name='other_name[title]' size='30' id='other_name_title' value='Hello World' type='text' />" +
"<textarea name='other_name[body]' id='other_name_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='other_name[secret]' value='0' type='hidden' />" +

0 comments on commit 11614bd

Please sign in to comment.