Class: ExpressTemplates::Components::Forms::Radio
Constant Summary
Constants inherited
from Base
Base::MAP
Instance Attribute Summary
#input_attributes
Instance Method Summary
collapse
#belongs_to_association, #has_many_through_association, #related_collection
#field_helper_options, #field_id_attribute, #field_name, #field_name_attribute, #field_value, #label_name, #label_text, #parent_form, #resource, #resource_class, #resource_name
included
Methods inherited from Base
abstract_component, abstract_component?, before_build, #build, builder_method, builder_method_and_class, contains, descendants, has_attributes, inherited, #initialize, require_parent, required_parent, tag
Instance Method Details
#collection_from_association ⇒ Object
76
77
78
|
# File 'lib/express_templates/components/forms/radio.rb', line 76
def collection_from_association
related_collection or raise "No association collection for: #{resource_name}.#{field_name}"
end
|
#generate_options_from_specified_values ⇒ Object
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
|
# File 'lib/express_templates/components/forms/radio.rb', line 42
def generate_options_from_specified_values
if !option_collection.kind_of?(Array) &&
!option_collection.kind_of?(Hash)
raise ArgumentError, "Radio collection should be Array or Hash: #{option_collection.inspect}"
end
option_collection_hash = option_collection
if option_collection.kind_of?(Array)
option_collection_hash = option_collection.inject({}) do |hash, val|
hash[val] = val
hash
end
end
option_collection_hash.each_pair do |key, value|
if label_after?
div(class: "radio-input-container") {
radio_button(resource_name, field_name.to_sym, key, class: 'radio')
label({
class: config[:label_wrapper_class],
for: [resource_name, field_name, key].join("_").downcase,
}) {
current_arbre_element.add_child value
}
}
else
label(class: config[:label_wrapper_class]) {
radio_button(resource_name, field_name.to_sym, key, class: 'radio')
current_arbre_element.add_child value
}
end
end
end
|
#option_collection ⇒ Object
38
39
40
|
# File 'lib/express_templates/components/forms/radio.rb', line 38
def option_collection
config[:options]
end
|
#option_values_specified? ⇒ Boolean
34
35
36
|
# File 'lib/express_templates/components/forms/radio.rb', line 34
def option_values_specified?
[Array, Hash].include?(option_collection.class)
end
|
24
25
26
27
28
29
30
31
32
|
# File 'lib/express_templates/components/forms/radio.rb', line 24
def use_options_from_collection_radio_buttons_helper
collection_radio_buttons(resource_name, field_name.to_sym, collection_from_association,
option_value_method, option_name_method,
input_attributes) do |b|
b.label(class: "radio") {
b.radio_button + b.text
}
end
end
|