Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #4713 from carlosantoniodasilva/form-label-for

Do not generate label for attribute when giving nil
  • Loading branch information...
commit f1baf8f5a4fe0dc98b36380498db747d3be5d316 2 parents e634efc + b03e55d
@drogus drogus authored
View
2  actionpack/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* `label` form helper accepts :for => nil to not generate the attribute. *Carlos Antonio da Silva*
+
* Add `:format` option to number_to_percentage *Rodrigo Flores*
* Add `config.action_view.logger` to configure logger for ActionView. *Rafael França*
View
2  actionpack/lib/action_view/helpers/tags/label.rb
@@ -30,7 +30,7 @@ def render(&block)
add_default_name_and_id_for_value(tag_value, name_and_id)
options.delete("index")
options.delete("namespace")
- options["for"] ||= name_and_id["id"]
+ options["for"] = name_and_id["id"] unless options.key?("for")
if block_given?
@template_object.label_tag(name_and_id["id"], options, &block)
View
4 actionpack/test/template/form_helper_test.rb
@@ -215,6 +215,10 @@ def test_label_with_for_attribute_as_string
assert_dom_equal('<label for="my_for">Title</label>', label(:post, :title, nil, "for" => "my_for"))
end
+ def test_label_does_not_generate_for_attribute_when_given_nil
+ assert_dom_equal('<label>Title</label>', label(:post, :title, :for => nil))
+ end
+
def test_label_with_id_attribute_as_symbol
assert_dom_equal('<label for="post_title" id="my_id">Title</label>', label(:post, :title, nil, :id => "my_id"))
end
Please sign in to comment.
Something went wrong with that request. Please try again.