Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render select tag before hidden input #13524

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion actionview/lib/action_view/helpers/tags/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def select_content_tag(option_tags, options, html_options)
select = content_tag("select", add_options(option_tags, options, value), html_options)

if html_options["multiple"] && options.fetch(:include_hidden, true)
tag("input", :disabled => html_options["disabled"], :name => html_options["name"], :type => "hidden", :value => "") + select
select + tag("input", :disabled => html_options["disabled"], :name => html_options["name"], :type => "hidden", :value => "")
else
select
end
Expand Down
10 changes: 5 additions & 5 deletions actionview/test/template/form_options_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def test_select_under_fields_for_with_block
def test_select_with_multiple_to_add_hidden_input
output_buffer = select(:post, :category, "", {}, :multiple => true)
assert_dom_equal(
"<input type=\"hidden\" name=\"post[category][]\" value=\"\"/><select multiple=\"multiple\" id=\"post_category\" name=\"post[category][]\"></select>",
"<select multiple=\"multiple\" id=\"post_category\" name=\"post[category][]\"></select><input type=\"hidden\" name=\"post[category][]\" value=\"\"/>",
output_buffer
)
end
Expand All @@ -598,7 +598,7 @@ def test_select_with_multiple_and_with_explicit_name_ending_with_brackets
def test_select_with_multiple_and_disabled_to_add_disabled_hidden_input
output_buffer = select(:post, :category, "", {}, :multiple => true, :disabled => true)
assert_dom_equal(
"<input disabled=\"disabled\"type=\"hidden\" name=\"post[category][]\" value=\"\"/><select multiple=\"multiple\" disabled=\"disabled\" id=\"post_category\" name=\"post[category][]\"></select>",
"<select multiple=\"multiple\" disabled=\"disabled\" id=\"post_category\" name=\"post[category][]\"></select><input disabled=\"disabled\"type=\"hidden\" name=\"post[category][]\" value=\"\"/>",
output_buffer
)
end
Expand Down Expand Up @@ -729,7 +729,7 @@ def test_required_select_with_display_size_bigger_than_one

def test_required_select_with_multiple_option
assert_dom_equal(
%(<input name="post[category][]" type="hidden" value=""/><select id="post_category" multiple="multiple" name="post[category][]" required="required"><option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select>),
%(<select id="post_category" multiple="multiple" name="post[category][]" required="required"><option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select><input name="post[category][]" type="hidden" value=""/>),
select("post", "category", %w(abe mus hest), {}, required: true, multiple: true)
)
end
Expand Down Expand Up @@ -813,7 +813,7 @@ def test_select_with_prompt_and_selected_value
select("post", "category", %w( one two ), :selected => 'two', :prompt => true)
)
end

def test_select_with_disabled_array
@post = Post.new
@post.category = "<mus>"
Expand Down Expand Up @@ -909,7 +909,7 @@ def test_collection_select_with_multiple_option_appends_array_brackets_and_hidde
@post = Post.new
@post.author_name = "Babe"

expected = "<input type=\"hidden\" name=\"post[author_name][]\" value=\"\"/><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>"
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><input type=\"hidden\" name=\"post[author_name][]\" value=\"\"/>"

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