]> source.dussan.org Git - redmine.git/commitdiff
Replaces <option value=""></option> which is not HTML5 valid (#15191).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 26 Oct 2013 08:08:45 +0000 (08:08 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 26 Oct 2013 08:08:45 +0000 (08:08 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12237 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/projects_helper.rb
config/initializers/10-patches.rb
test/functional/boards_controller_test.rb

index 4ec54d8dda2f90f40ec5c5ff6f345c27af2a11a4..8f236bed6c050bac6b96dd81c401618c1e27b8f9 100644 (file)
@@ -46,7 +46,7 @@ module ProjectsHelper
     end
 
     options = ''
-    options << "<option value=''></option>" if project.allowed_parents.include?(nil)
+    options << "<option value=''>&nbsp;</option>" if project.allowed_parents.include?(nil)
     options << project_tree_options_for_select(project.allowed_parents.compact, :selected => selected)
     content_tag('select', options.html_safe, :name => 'project[parent_id]', :id => 'project_parent_id')
   end
index 79641513ec60c2d8a40219ca521af0ce7cde1576..d186bcdc4b24cb7d1807cf5c5bad97bc5323f99d 100644 (file)
@@ -91,6 +91,43 @@ end
 
 ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| html_tag || ''.html_safe }
 
+# HTML5: <option value=""></option> is invalid, use <option value="">&nbsp;</option> instead
+module ActionView
+  module Helpers
+    class InstanceTag
+      private
+      def add_options_with_non_empty_blank_option(option_tags, options, value = nil)
+        if options[:include_blank] == true
+          options = options.dup
+          options[:include_blank] = '&nbsp;'.html_safe
+        end
+        add_options_without_non_empty_blank_option(option_tags, options, value)
+      end
+      alias_method_chain :add_options, :non_empty_blank_option
+    end
+
+    module FormTagHelper
+      def select_tag_with_non_empty_blank_option(name, option_tags = nil, options = {})
+        if options.delete(:include_blank)
+          options[:prompt] = '&nbsp;'.html_safe
+        end
+        select_tag_without_non_empty_blank_option(name, option_tags, options)
+      end
+      alias_method_chain :select_tag, :non_empty_blank_option
+    end
+
+    module FormOptionsHelper
+      def options_for_select_with_non_empty_blank_option(container, selected = nil)
+        if container.is_a?(Array)
+          container = container.map {|element| element.blank? ? ["&nbsp;".html_safe, ""] : element}
+        end
+        options_for_select_without_non_empty_blank_option(container, selected)
+      end
+      alias_method_chain :options_for_select, :non_empty_blank_option
+    end
+  end
+end
+
 require 'mail'
 
 module DeliveryMethods
index 910f16e9a917c9aaf059742c475bbac62fc9246c..6b07b900ce6c2ac6ca0bd2cc424ca83d54c90755 100644 (file)
@@ -117,7 +117,7 @@ class BoardsControllerTest < ActionController::TestCase
 
     assert_select 'select[name=?]', 'board[parent_id]' do
       assert_select 'option', (Project.find(1).boards.size + 1)
-      assert_select 'option[value=]', :text => ''
+      assert_select 'option[value=]', :text => '&nbsp;'
       assert_select 'option[value=1]', :text => 'Help'
     end
   end