diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-05-21 08:45:12 -0300 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2016-05-21 08:45:12 -0300 |
commit | 7087ff99071cd29f1d07e5298dbc204bede6ca86 (patch) | |
tree | 67b396ef0b92385bd5996fb0617abab989f166e9 /actionview | |
parent | 694cbbf801e46d7ec533ece4637412838f02723e (diff) | |
parent | 9bfd968bed1a76888ec82e0f7b524a989d0e1108 (diff) | |
download | rails-7087ff99071cd29f1d07e5298dbc204bede6ca86.tar.gz rails-7087ff99071cd29f1d07e5298dbc204bede6ca86.tar.bz2 rails-7087ff99071cd29f1d07e5298dbc204bede6ca86.zip |
Merge pull request #24923 from vipulnsward/24816-add-label
Add empty label to empty options tag
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/CHANGELOG.md | 17 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/form_tag_helper.rb | 4 | ||||
-rw-r--r-- | actionview/test/template/form_tag_helper_test.rb | 10 |
3 files changed, 25 insertions, 6 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 1d7ec77e70..0b40699c77 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,2 +1,19 @@ +* `select_tag`'s `include_blank` option for generation for blank option tag, now adds an empty space label, + when the value as well as content for option tag are empty, so that we confirm with html specification. + Ref: https://www.w3.org/TR/html5/forms.html#the-option-element. + + Generation of option before: + + ```html + <option value=""></option> + ``` + + Generation of option after: + + ```html + <option value="" label=" "></option> + ``` + + *Vipul A M * Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/actionview/CHANGELOG.md) for previous changes. diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index cfff0bef5d..82f2fd30c7 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -134,13 +134,15 @@ module ActionView if options.include?(:include_blank) include_blank = options.delete(:include_blank) + options_for_blank_options_tag = { value: '' } if include_blank == true include_blank = '' + options_for_blank_options_tag[:label] = ' ' end if include_blank - option_tags = content_tag("option".freeze, include_blank, value: '').safe_concat(option_tags) + option_tags = content_tag("option".freeze, include_blank, options_for_blank_options_tag).safe_concat(option_tags) end end diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index 7b93c8dc29..5b0b708618 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -239,8 +239,8 @@ class FormTagHelperTest < ActionView::TestCase end def test_select_tag_with_include_blank - actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), :include_blank => true - expected = %(<select id="places" name="places"><option value=""></option><option>Home</option><option>Work</option><option>Pub</option></select>) + actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), include_blank: true + expected = %(<select id="places" name="places"><option value="" label=" "></option><option>Home</option><option>Work</option><option>Pub</option></select>) assert_dom_equal expected, actual end @@ -269,14 +269,14 @@ class FormTagHelperTest < ActionView::TestCase end def test_select_tag_with_prompt_and_include_blank - actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), :prompt => "string", :include_blank => true - expected = %(<select name="places" id="places"><option value="">string</option><option value=""></option><option>Home</option><option>Work</option><option>Pub</option></select>) + actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), prompt: "string", include_blank: true + expected = %(<select name="places" id="places"><option value="">string</option><option value="" label=" "></option><option>Home</option><option>Work</option><option>Pub</option></select>) assert_dom_equal expected, actual end def test_select_tag_with_nil_option_tags_and_include_blank actual = select_tag "places", nil, :include_blank => true - expected = %(<select id="places" name="places"><option value=""></option></select>) + expected = %(<select id="places" name="places"><option value="" label=" "></option></select>) assert_dom_equal expected, actual end |