34 |
34 |
|
35 |
35 |
ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| html_tag || ''.html_safe }
|
36 |
36 |
|
37 |
|
# HTML5: <option value=""></option> is invalid, use <option value=""> </option> instead
|
38 |
37 |
module ActionView
|
39 |
38 |
module Helpers
|
40 |
|
module Tags
|
41 |
|
SelectRenderer.prepend(Module.new do
|
42 |
|
def add_options(option_tags, options, value = nil)
|
43 |
|
if options.delete(:include_blank)
|
44 |
|
options[:prompt] = ' '.html_safe
|
45 |
|
end
|
46 |
|
super
|
47 |
|
end
|
48 |
|
end)
|
49 |
|
end
|
50 |
|
|
51 |
39 |
module FormHelper
|
52 |
40 |
alias :date_field_without_max :date_field
|
53 |
41 |
def date_field(object_name, method, options = {})
|
... | ... | |
56 |
44 |
end
|
57 |
45 |
|
58 |
46 |
module FormTagHelper
|
59 |
|
alias :select_tag_without_non_empty_blank_option :select_tag
|
60 |
|
def select_tag(name, option_tags = nil, options = {})
|
61 |
|
if options.delete(:include_blank)
|
62 |
|
options[:prompt] = ' '.html_safe
|
63 |
|
end
|
64 |
|
select_tag_without_non_empty_blank_option(name, option_tags, options)
|
65 |
|
end
|
66 |
|
|
67 |
47 |
alias :date_field_tag_without_max :date_field_tag
|
68 |
48 |
def date_field_tag(name, value = nil, options = {})
|
69 |
49 |
date_field_tag_without_max(name, value, options.reverse_merge(max: '9999-12-31'))
|
70 |
50 |
end
|
71 |
51 |
end
|
72 |
|
|
73 |
|
module FormOptionsHelper
|
74 |
|
alias :options_for_select_without_non_empty_blank_option :options_for_select
|
75 |
|
def options_for_select(container, selected = nil)
|
76 |
|
if container.is_a?(Array)
|
77 |
|
container = container.map {|element| element.presence || [" ".html_safe, ""]}
|
78 |
|
end
|
79 |
|
options_for_select_without_non_empty_blank_option(container, selected)
|
80 |
|
end
|
81 |
|
end
|
82 |
52 |
end
|
83 |
53 |
end
|
84 |
54 |
|