Skip to content

Commit

Permalink
Merge pull request #9616 from exviva/multiple_select_name_double_squa…
Browse files Browse the repository at this point in the history
…re_brackets

Fix incorrectly appended square brackets to a multiple select box

Before:

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

After:

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

Conflicts:
	actionpack/CHANGELOG.md
	actionpack/lib/action_view/helpers/tags/base.rb
	actionpack/test/template/form_options_helper_test.rb
  • Loading branch information
carlosantoniodasilva committed Mar 12, 2013
1 parent ccf256d commit 4886991
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions actionpack/CHANGELOG.md
Expand Up @@ -5,6 +5,23 @@

## Rails 3.2.13 (Feb 17, 2013) ##

* 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][]" ...>

Backport #9616.

*Olek Janiszewski*

* Determine the controller#action from only the matched path when using the
shorthand syntax. Previously the complete path was used, which led
to problems with nesting (scopes and namespaces).
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/form_helper.rb
Expand Up @@ -1207,7 +1207,7 @@ def add_default_name_and_id(options)
options["id"] = options.fetch("id"){ tag_id }
end

options["name"] += "[]" if options["multiple"]
options["name"] += "[]" if options["multiple"] && !options["name"].ends_with?("[]")

This comment has been minimized.

Copy link
@cthiel

cthiel Mar 21, 2013

This is probably causing tors/jquery-fileupload-rails#36

This comment has been minimized.

Copy link
@exviva

exviva Mar 21, 2013

Contributor

@cthiel this commit actually makes the conditional more restrictive. I think 175ba04 introduced the bug (see #9616).

This comment has been minimized.

Copy link
@cthiel

cthiel Mar 21, 2013

@exviva you could be right! Thanks for the pointer.

options["id"] = [options.delete('namespace'), options["id"]].compact.join("_").presence
end

Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/template/form_options_helper_test.rb
Expand Up @@ -515,6 +515,14 @@ def test_select_with_multiple_to_add_hidden_input
)
end

def test_select_with_multiple_and_with_explicit_name_ending_with_brackets
output_buffer = select(:post, :category, "", {}, :multiple => true, :name => 'post[category][]')
assert_dom_equal(
"<input type=\"hidden\" name=\"post[category][]\" value=\"\"/><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(
Expand Down

0 comments on commit 4886991

Please sign in to comment.