Permalink
Browse files

Remove grouped_options_for_select leading divider

This will omit the first divider in grouped_options_for_select (I would
expect a divider to go between things only).

Currently, the grouped options divider will make a select like so:

Please Select:
-----
USA
Canada
-----
Denmark
United Kingdom
-----
China
India

It is more symmetric and more typical to only seperate the groups:

Please Select:

USA
Canada
-----
Denmark
United Kingdom
-----
China
India
  • Loading branch information...
evanfarrar committed Aug 16, 2012
1 parent a38d4d4 commit e7dbdbccf5779f43e6712c8679fbe6c82364fac9
@@ -500,7 +500,7 @@ def option_groups_from_collection_for_select(collection, group_method, group_lab
# grouped_options_for_select(grouped_options, nil, divider: '---------')
#
# Possible output:
- # <optgroup label="---------">
+ # <optgroup>
# <option value="Denmark">Denmark</option>
# <option value="Germany">Germany</option>
# <option value="France">France</option>
@@ -530,6 +530,14 @@ def grouped_options_for_select(grouped_options, selected_key = nil, options = {}
grouped_options = grouped_options.sort if grouped_options.is_a?(Hash)
+ container = grouped_options.shift
+ if divider
+ label = nil
+ else
+ label, container = container
+ end
+ body.safe_concat content_tag(:optgroup, options_for_select(container, selected_key), :label => label)
+
grouped_options.each do |container|
if divider
label = divider
@@ -297,7 +297,7 @@ def test_grouped_options_for_select_with_array
def test_grouped_options_for_select_with_optional_divider
assert_dom_equal(
- "<optgroup label=\"----------\"><option value=\"US\">US</option>\n<option value=\"Canada\">Canada</option></optgroup><optgroup label=\"----------\"><option value=\"GB\">GB</option>\n<option value=\"Germany\">Germany</option></optgroup>",
+ "<optgroup><option value=\"US\">US</option>\n<option value=\"Canada\">Canada</option></optgroup><optgroup label=\"----------\"><option value=\"GB\">GB</option>\n<option value=\"Germany\">Germany</option></optgroup>",
grouped_options_for_select([['US',"Canada"] , ["GB", "Germany"]], nil, divider: "----------")
)

0 comments on commit e7dbdbc

Please sign in to comment.