Skip to content
This repository
Browse code

Fixed to_label_tag to accept id attribute without changing for attrib…

…ute [#2660 status:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
commit 920ef4e6f3832ea1d3297e2e7e5f0f775dab69a8 1 parent e391c7a
Matt Duncan authored August 08, 2009 lifo committed August 09, 2009
1  actionpack/lib/action_view/helpers/form_helper.rb
@@ -738,6 +738,7 @@ def to_label_tag(text = nil, options = {})
738 738
         options = options.stringify_keys
739 739
         tag_value = options.delete("value")
740 740
         name_and_id = options.dup
  741
+        name_and_id["id"] = name_and_id["for"]
741 742
         add_default_name_and_id_for_value(tag_value, name_and_id)
742 743
         options.delete("index")
743 744
         options["for"] ||= name_and_id["id"]
16  actionpack/test/template/form_helper_test.rb
@@ -157,6 +157,22 @@ def test_label_with_for_attribute_as_string
157 157
     assert_dom_equal('<label for="my_for">Title</label>', label(:post, :title, nil, "for" => "my_for"))
158 158
   end
159 159
 
  160
+  def test_label_with_id_attribute_as_symbol
  161
+    assert_dom_equal('<label for="post_title" id="my_id">Title</label>', label(:post, :title, nil, :id => "my_id"))
  162
+  end
  163
+
  164
+  def test_label_with_id_attribute_as_string
  165
+    assert_dom_equal('<label for="post_title" id="my_id">Title</label>', label(:post, :title, nil, "id" => "my_id"))
  166
+  end
  167
+
  168
+  def test_label_with_for_and_id_attributes_as_symbol
  169
+    assert_dom_equal('<label for="my_for" id="my_id">Title</label>', label(:post, :title, nil, :for => "my_for", :id => "my_id"))
  170
+  end
  171
+
  172
+  def test_label_with_for_and_id_attributes_as_string
  173
+    assert_dom_equal('<label for="my_for" id="my_id">Title</label>', label(:post, :title, nil, "for" => "my_for", "id" => "my_id"))
  174
+  end
  175
+
160 176
   def test_label_for_radio_buttons_with_value
161 177
     assert_dom_equal('<label for="post_title_great_title">The title goes here</label>', label("post", "title", "The title goes here", :value => "great_title"))
162 178
     assert_dom_equal('<label for="post_title_great_title">The title goes here</label>', label("post", "title", "The title goes here", :value => "great title"))

0 notes on commit 920ef4e

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