diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-05-13 01:00:01 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-05-13 01:00:01 -0300 |
commit | a8cfaed3389de8c12ad8c8e363df13bd93354ab4 (patch) | |
tree | eeda43a98880df9f068f572c342dcef420b69cfc /actionpack/lib | |
parent | 871b1c2115182e7273b75b76518733374a9883b3 (diff) | |
parent | 2e9c7cd5f603dd27015cddb17c6ea328e9baa0d5 (diff) | |
download | rails-a8cfaed3389de8c12ad8c8e363df13bd93354ab4.tar.gz rails-a8cfaed3389de8c12ad8c8e363df13bd93354ab4.tar.bz2 rails-a8cfaed3389de8c12ad8c8e363df13bd93354ab4.zip |
Merge pull request #6225 from acapilleri/select_with_required_true_include_first_option_blank
HTML5 validation error with options_from_collection_for_select
Fixes #5908
Conflicts:
actionpack/CHANGELOG.md
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/tags/base.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/tags/base.rb b/actionpack/lib/action_view/helpers/tags/base.rb index e4f431a6d7..bf209d3a20 100644 --- a/actionpack/lib/action_view/helpers/tags/base.rb +++ b/actionpack/lib/action_view/helpers/tags/base.rb @@ -121,6 +121,7 @@ module ActionView 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) select = content_tag("select", add_options(option_tags, options, value(object)), html_options) if html_options["multiple"] && options.fetch(:include_hidden, true) @@ -129,6 +130,10 @@ module ActionView select end end + + def option_required?(html_options) + html_options["required"] && html_options["size"].to_i == 1 && !html_options["multiple"] + end def add_options(option_tags, options, value = nil) if options[:include_blank] |