Permalink
Browse files

Do not add `:include_blank` option if prompt is present

  • Loading branch information...
1 parent 3081856 commit 521e964411114a9ff8c95f4129ca7ade8f972d53 Rafael Mendon��a Fran��a committed with rafaelfranca May 13, 2012
@@ -121,7 +121,7 @@ def sanitized_value(value)
def select_content_tag(option_tags, options, html_options)
html_options = html_options.stringify_keys
add_default_name_and_id(html_options)
- options[:include_blank] ||= true if option_required?(html_options)
+ options[:include_blank] ||= true unless options[:prompt] || select_not_required?(html_options)
select = content_tag("select", add_options(option_tags, options, value(object)), html_options)
if html_options["multiple"] && options.fetch(:include_hidden, true)
@@ -131,8 +131,8 @@ def select_content_tag(option_tags, options, html_options)
end
end
- def option_required?(html_options)
- html_options["required"] && !html_options["multiple"] && !(html_options["size"].to_i > 1)
+ def select_not_required?(html_options)
+ !html_options["required"] || html_options["multiple"] || html_options["size"].to_i > 1
end
def add_options(option_tags, options, value = nil)
@@ -648,6 +648,13 @@ def test_required_select_with_include_blank_prompt
)
end
+ def test_required_select_with_prompt
+ assert_dom_equal(
+ %(<select id="post_category" name="post[category]" required="required"><option value="">Select one</option>\n<option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select>),
+ select("post", "category", %w(abe mus hest), { prompt: "Select one" }, required: true)
+ )
+ end
+
def test_required_select_display_size_equals_to_one
assert_dom_equal(
%(<select id="post_category" name="post[category]" required="required" size="1"><option value=""></option>\n<option value="abe">abe</option>\n<option value="mus">mus</option>\n<option value="hest">hest</option></select>),

0 comments on commit 521e964

Please sign in to comment.