1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix incorrectly appended square brackets to a multiple select box

If an explicit name has been given and it already ends with "[]"

Before:

    select(:category, [], {}, multiple: true, name: "post[category][]")
    # => <select name="post[category][][]" ...>

After:

    select(:category, [], {}, multiple: true, name: "post[category][]")
    # => <select name="post[category][]" ...>
This commit is contained in:
Olek Janiszewski 2013-03-08 18:07:09 +01:00
parent dd1d309fa9
commit 8e05a6f638
3 changed files with 24 additions and 1 deletions

View file

@ -1,5 +1,20 @@
## Rails 4.0.0 (unreleased) ##
* Fix incorrectly appended square brackets to a multiple select box
if an explicit name has been given and it already ends with "[]"
Before:
select(:category, [], {}, multiple: true, name: "post[category][]")
# => <select name="post[category][][]" ...>
After:
select(:category, [], {}, multiple: true, name: "post[category][]")
# => <select name="post[category][]" ...>
*Olek Janiszewski*
* Fixed regression when using `assert_template` to verify files sent using
`render file: 'README.md'`.
Fixes #9464.

View file

@ -84,7 +84,7 @@ module ActionView
options["id"] = options.fetch("id"){ tag_id }
end
options["name"] += "[]" if options["multiple"]
options["name"] += "[]" if options["multiple"] && !options["name"].ends_with?("[]")
options["id"] = [options.delete('namespace'), options["id"]].compact.join("_").presence
end

View file

@ -575,6 +575,14 @@ class FormOptionsHelperTest < ActionView::TestCase
)
end
def test_select_with_multiple_and_with_explicit_name_ending_with_brackets
output_buffer = select(:post, :category, [], {include_hidden: false}, multiple: true, name: 'post[category][]')
assert_dom_equal(
"<select multiple=\"multiple\" id=\"post_category\" name=\"post[category][]\"></select>",
output_buffer
)
end
def test_select_with_multiple_and_disabled_to_add_disabled_hidden_input
output_buffer = select(:post, :category, "", {}, :multiple => true, :disabled => true)
assert_dom_equal(