Skip to content

Commit

Permalink
Merge [6078] from trunk. References #6977.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@6079 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Jan 28, 2007
1 parent 4dc206c commit 2bc5e6c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* select :multiple => true suffixes the attribute name with [] unless already suffixed. #6977 [nik.kakelin, ben, julik]

* Improve routes documentation. #7095 [zackchandler]

* Resource member routes require :id, eliminating the ambiguous overlap with collection routes. #7229 [dkubb]
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/form_helper.rb
Expand Up @@ -387,7 +387,7 @@ def add_default_name_and_id(options)
options["name"] ||= tag_name_with_index(@auto_index)
options["id"] ||= tag_id_with_index(@auto_index)
else
options["name"] ||= tag_name
options["name"] ||= tag_name + (options.has_key?('multiple') ? '[]' : '')
options["id"] ||= tag_id
end
end
Expand Down
19 changes: 19 additions & 0 deletions actionpack/test/template/form_options_helper_test.rb
Expand Up @@ -360,6 +360,25 @@ def test_collection_select_with_blank_and_style
)
end

def test_collection_select_with_multiple_option_appends_array_brackets
@posts = [
Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
Post.new("Babe went home", "Babe", "To a little house", "shh!"),
Post.new("Cabe went home", "Cabe", "To a little house", "shh!")
]

@post = Post.new
@post.author_name = "Babe"

expected = "<select id=\"post_author_name\" name=\"post[author_name][]\" multiple=\"multiple\"><option value=\"\"></option>\n<option value=\"&lt;Abe&gt;\">&lt;Abe&gt;</option>\n<option value=\"Babe\" selected=\"selected\">Babe</option>\n<option value=\"Cabe\">Cabe</option></select>"

# Should suffix default name with [].
assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true }, :multiple => true)

# Shouldn't suffix custom name with [].
assert_dom_equal expected, collection_select("post", "author_name", @posts, "author_name", "author_name", { :include_blank => true, :name => 'post[author_name][]' }, :multiple => true)
end

def test_country_select
@post = Post.new
@post.origin = "Denmark"
Expand Down

0 comments on commit 2bc5e6c

Please sign in to comment.