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

add selected and disabled option to grouped select

This commit is contained in:
Vasiliy Ermolovich 2012-02-18 14:35:28 +03:00
parent 2f689d462d
commit ac2e801cd2
2 changed files with 24 additions and 1 deletions

View file

@ -14,8 +14,13 @@ module ActionView
end
def render
option_tags_options = {
:selected => @options.fetch(:selected) { value(@object) },
:disabled => @options[:disabled]
}
select_content_tag(
option_groups_from_collection_for_select(@collection, @group_method, @group_label_method, @option_key_method, @option_value_method, value(@object)), @options, @html_options
option_groups_from_collection_for_select(@collection, @group_method, @group_label_method, @option_key_method, @option_value_method, option_tags_options), @options, @html_options
)
end
end

View file

@ -1100,6 +1100,24 @@ class FormOptionsHelperTest < ActionView::TestCase
)
end
def test_grouped_collection_select_with_selected
@post = Post.new
assert_dom_equal(
%Q{<select id="post_origin" name="post[origin]"><optgroup label="&lt;Africa&gt;"><option value="&lt;sa&gt;">&lt;South Africa&gt;</option>\n<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option value="dk" selected="selected">Denmark</option>\n<option value="ie">Ireland</option></optgroup></select>},
grouped_collection_select("post", "origin", dummy_continents, :countries, :continent_name, :country_id, :country_name, :selected => 'dk')
)
end
def test_grouped_collection_select_with_disabled_value
@post = Post.new
assert_dom_equal(
%Q{<select id="post_origin" name="post[origin]"><optgroup label="&lt;Africa&gt;"><option value="&lt;sa&gt;">&lt;South Africa&gt;</option>\n<option value="so">Somalia</option></optgroup><optgroup label="Europe"><option disabled="disabled" value="dk">Denmark</option>\n<option value="ie">Ireland</option></optgroup></select>},
grouped_collection_select("post", "origin", dummy_continents, :countries, :continent_name, :country_id, :country_name, :disabled => 'dk')
)
end
def test_grouped_collection_select_under_fields_for
@post = Post.new
@post.origin = 'dk'