diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-01-26 20:46:43 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-01-26 21:23:33 -0200 |
commit | b03e55d17780b4ca9d4b962a426274af1f2e68a6 (patch) | |
tree | de763a8d04242148471eb0964b6bff9cece6ef62 /actionpack | |
parent | e634efca99962fdbb83791a8daf9b0ceb9ff2f63 (diff) | |
download | rails-b03e55d17780b4ca9d4b962a426274af1f2e68a6.tar.gz rails-b03e55d17780b4ca9d4b962a426274af1f2e68a6.tar.bz2 rails-b03e55d17780b4ca9d4b962a426274af1f2e68a6.zip |
Do not generate label for attribute when giving nil
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/label.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 4 |
3 files changed, 7 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 3b0945d63b..1ffb7f32a0 100644 --- a/actionpack/CHANGELOG.md +++ b/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* diff --git a/actionpack/lib/action_view/helpers/tags/label.rb b/actionpack/lib/action_view/helpers/tags/label.rb index 74ac92ee18..1bd71c2778 100644 --- a/actionpack/lib/action_view/helpers/tags/label.rb +++ b/actionpack/lib/action_view/helpers/tags/label.rb @@ -30,7 +30,7 @@ module ActionView 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) diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 39d4768861..8680631a48 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -215,6 +215,10 @@ class FormHelperTest < ActionView::TestCase 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 |