Skip to content

Commit

Permalink
Fixed labels that have a bracketed name and an index [#68 state:resol…
Browse files Browse the repository at this point in the history
…ved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
kjg authored and josh committed Apr 30, 2008
1 parent 96d9691 commit c83f758
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions actionpack/lib/action_view/helpers/form_helper.rb
Expand Up @@ -471,6 +471,7 @@ def to_label_tag(text = nil, options = {})
options = options.stringify_keys
name_and_id = options.dup
add_default_name_and_id(name_and_id)
options.delete("index")
options["for"] ||= name_and_id["id"]
content = (text.blank? ? nil : text.to_s) || method_name.humanize
label_tag(name_and_id["id"], content, options)
Expand Down
12 changes: 12 additions & 0 deletions actionpack/test/template/form_helper_test.rb
Expand Up @@ -540,6 +540,18 @@ def test_fields_for_object_with_bracketed_name
_erbout
end

def test_fields_for_object_with_bracketed_name_and_index
_erbout = ''
fields_for("author[post]", @post, :index => 1) do |f|
_erbout.concat f.label(:title)
_erbout.concat f.text_field(:title)
end

assert_dom_equal "<label for=\"author_post_1_title\">Title</label>" +
"<input name='author[post][1][title]' size='30' type='text' id='author_post_1_title' value='Hello World' />",
_erbout
end

def test_form_builder_does_not_have_form_for_method
assert ! ActionView::Helpers::FormBuilder.instance_methods.include?('form_for')
end
Expand Down

0 comments on commit c83f758

Please sign in to comment.