5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'app/components/polaris/select_component.rb', line 5
def initialize(
options: {},
form: nil,
attribute: nil,
name: nil,
selected: nil,
disabled_options: nil,
label: nil,
prompt: nil,
divider: nil,
time_zone: nil,
label_hidden: false,
label_inline: false,
label_action: nil,
disabled: false,
required: false,
help_text: nil,
error: false,
grouped: false,
clear_errors_on_focus: false,
wrapper_arguments: {},
select_options: {},
input_options: {},
**system_arguments
)
@form = form
@attribute = attribute
@name = name
@options = options
@selected = selected
@disabled_options = disabled_options
@label = label
@label_hidden = label_hidden
@label_inline = label_inline
@disabled = disabled
@grouped = grouped
@prompt = prompt
@divider = divider
@time_zone = time_zone
if @time_zone
@options = ::ActiveSupport::TimeZone.all
end
@system_arguments = system_arguments
@system_arguments[:tag] = "div"
@system_arguments[:data] ||= {}
prepend_option(@system_arguments[:data], :controller, "polaris-select")
prepend_option(@system_arguments[:data], :selected_value, @selected)
@system_arguments[:classes] = class_names(
@system_arguments[:classes],
"Polaris-Select",
"Polaris-Select--disabled": disabled,
"Polaris-Select--error": error
)
@wrapper_arguments = {
form: form,
attribute: attribute,
name: name,
label: label,
label_hidden: hides_label?,
label_action: label_action,
required: required,
help_text: help_text,
error: error
}.merge(wrapper_arguments)
@clear_errors_on_focus = clear_errors_on_focus
@select_options = select_options
@input_options = input_options
@input_options.deep_merge!(select_options) unless @form
@input_options[:class] = class_names(@input_options[:classes], "Polaris-Select__Input")
@input_options[:disabled] = disabled
@input_options[:data] ||= {}
prepend_option(@input_options[:data], :polaris_select_target, "select")
if @clear_errors_on_focus
prepend_option(@input_options[:data], :action, "click->polaris-select#clearErrorMessages")
end
prepend_option(@input_options[:data], :action, "polaris-select#update")
end
|