24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/form_props/select_renderer.rb', line 24
def select_content_props(option_tags, options, html_options)
html_options = html_options.stringify_keys
add_default_name_and_id(html_options)
if placeholder_required?(html_options)
raise ArgumentError, "include_blank cannot be false for a required field." if options[:include_blank] == false
options[:include_blank] ||= true unless options[:prompt]
end
html_options["type"] = "select"
value_for_blank = options.fetch(:selected) { value }
option_tags = add_options(option_tags, options, value_for_blank)
if options[:multiple]
html_options["multiple"] = options[:multiple]
end
if selected_values.any?
html_options["value"] ||= if html_options["multiple"]
Array(selected_values)
else
selected_values.first
end
end
json.set!(sanitized_key) do
input_props(html_options)
if options.key?(:include_hidden)
json.includeHidden options[:include_hidden]
end
json.options(option_tags)
end
end
|