Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Block version of label should wrapped in field_with_errors in case of…

… error
  • Loading branch information...
commit 889bb4b786941fa2e73163e0b0de10175a999526 1 parent 0244c0d
@avakhov avakhov authored
View
3  actionpack/lib/action_view/helpers/tags/label.rb
@@ -33,7 +33,8 @@ def render(&block)
options["for"] = name_and_id["id"] unless options.key?("for")
if block_given?
- @template_object.label_tag(name_and_id["id"], options, &block)
+ content = @template_object.capture(&block)
+ label_tag(name_and_id["id"], content, options)
else
content = if @content.blank?
@object_name.gsub!(/\[(.*)_attributes\]\[\d\]/, '.\1')
View
14 actionpack/test/template/form_helper_test.rb
@@ -1080,6 +1080,20 @@ def test_form_for_label_error_wrapping_without_conventional_instance_variable
assert_dom_equal expected, output_buffer
end
+ def test_form_for_label_error_wrapping_block_and_non_block_versions
+ form_for(@post) do |f|
+ concat f.label(:author_name, 'Name', :class => 'label')
+ concat f.label(:author_name, :class => 'label') { 'Name' }
+ end
+
+ expected = whole_form('/posts/123', 'edit_post_123' , 'edit_post', 'patch') do
+ "<div class='field_with_errors'><label for='post_author_name' class='label'>Name</label></div>" +
+ "<div class='field_with_errors'><label for='post_author_name' class='label'>Name</label></div>"
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
def test_form_for_with_namespace
form_for(@post, :namespace => 'namespace') do |f|
concat f.text_field(:title)

0 comments on commit 889bb4b

Please sign in to comment.
Something went wrong with that request. Please try again.