Skip to content

Commit

Permalink
Fixed to_label_tag to accept id attribute without changing for attrib…
Browse files Browse the repository at this point in the history
…ute [#2660 status:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
mrduncan authored and lifo committed Aug 9, 2009
1 parent 59c3b0d commit ba96125
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions actionpack/lib/action_view/helpers/form_helper.rb
Expand Up @@ -726,6 +726,7 @@ def to_label_tag(text = nil, options = {})
options = options.stringify_keys
tag_value = options.delete("value")
name_and_id = options.dup
name_and_id["id"] = name_and_id["for"]
add_default_name_and_id_for_value(tag_value, name_and_id)
options.delete("index")
options["for"] ||= name_and_id["id"]
Expand Down
16 changes: 16 additions & 0 deletions actionpack/test/template/form_helper_test.rb
Expand Up @@ -145,6 +145,22 @@ 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_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

def test_label_with_id_attribute_as_string
assert_dom_equal('<label for="post_title" id="my_id">Title</label>', label(:post, :title, nil, "id" => "my_id"))
end

def test_label_with_for_and_id_attributes_as_symbol
assert_dom_equal('<label for="my_for" id="my_id">Title</label>', label(:post, :title, nil, :for => "my_for", :id => "my_id"))
end

def test_label_with_for_and_id_attributes_as_string
assert_dom_equal('<label for="my_for" id="my_id">Title</label>', label(:post, :title, nil, "for" => "my_for", "id" => "my_id"))
end

def test_label_for_radio_buttons_with_value
assert_dom_equal('<label for="post_title_great_title">The title goes here</label>', label("post", "title", "The title goes here", :value => "great_title"))
assert_dom_equal('<label for="post_title_great_title">The title goes here</label>', label("post", "title", "The title goes here", :value => "great title"))
Expand Down

0 comments on commit ba96125

Please sign in to comment.