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:
parent
2f689d462d
commit
ac2e801cd2
2 changed files with 24 additions and 1 deletions
|
@ -14,8 +14,13 @@ module ActionView
|
||||||
end
|
end
|
||||||
|
|
||||||
def render
|
def render
|
||||||
|
option_tags_options = {
|
||||||
|
:selected => @options.fetch(:selected) { value(@object) },
|
||||||
|
:disabled => @options[:disabled]
|
||||||
|
}
|
||||||
|
|
||||||
select_content_tag(
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -1100,6 +1100,24 @@ class FormOptionsHelperTest < ActionView::TestCase
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_grouped_collection_select_with_selected
|
||||||
|
@post = Post.new
|
||||||
|
|
||||||
|
assert_dom_equal(
|
||||||
|
%Q{<select id="post_origin" name="post[origin]"><optgroup label="<Africa>"><option value="<sa>"><South Africa></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="<Africa>"><option value="<sa>"><South Africa></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
|
def test_grouped_collection_select_under_fields_for
|
||||||
@post = Post.new
|
@post = Post.new
|
||||||
@post.origin = 'dk'
|
@post.origin = 'dk'
|
||||||
|
|
Loading…
Reference in a new issue