Class: Matestack::Ui::VueJs::Components::Form::Checkbox
- Inherits:
-
Base
- Object
- Vue
- Base
- Matestack::Ui::VueJs::Components::Form::Checkbox
show all
- Defined in:
- lib/matestack/ui/vue_js/components/form/checkbox.rb
Instance Method Summary
collapse
Methods inherited from Base
#attribute_key, #attributes, #change_event, #component_attributes, #display_errors?, #error_class, #error_config, #error_key, #error_tag, #form_context, #get_from_error_config, #id, #init, #init_value, #input_error_class, #input_key, #input_label, #key, #multiple, #name, #placeholder, #render_errors, #type, #v_model_type, #value_type, #wrapper_error_class, #wrapper_tag
Methods inherited from Vue
#base_vue_props, #component_attributes, #component_uid, #create_children, inherited, #initialize, #matestack_ui_vuejs_ref, #vue_component, vue_name, #vue_name
Instance Method Details
#checkbox_attributes(item) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 44
def checkbox_attributes(item)
{
":id": item_id(item),
type: :checkbox,
name: item_label(item),
"#{value_key(item)}": item_value(item),
"matestack-ui-vuejs-ref": matestack_ui_vuejs_ref("select.multiple.#{key}"),
'v-on:change': change_event,
'init-value': (init_value || []).to_json,
'v-bind:class': "{ '#{error_class}': #{error_key} }",
'value-type': value_type(item),
"#{v_model_type(item)}": input_key,
}.merge(self.options)
end
|
#checkbox_options ⇒ Object
82
83
84
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 82
def checkbox_options
@checkbox_options ||= options.delete(:options)
end
|
#component_id ⇒ Object
24
25
26
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 24
def component_id
"checkbox-component-for-#{key}"
end
|
71
72
73
74
75
76
77
78
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 71
def init_value_for_single_input
if init_value == true || init_value == 1
return "true"
end
if init_value == false || init_value == 0
return "false"
end
end
|
#item_id(item) ⇒ Object
96
97
98
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 96
def item_id(item)
"#{id}+'_#{item_value(item).to_s.gsub(" ", '_')}'"
end
|
#item_label(item) ⇒ Object
92
93
94
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 92
def item_label(item)
item.is_a?(Array) ? item.first : item
end
|
#item_value(item) ⇒ Object
88
89
90
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 88
def item_value(item)
item.is_a?(Array) ? item.last : item
end
|
#render_checkbox_options ⇒ Object
37
38
39
40
41
42
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 37
def render_checkbox_options
checkbox_options.to_a.each do |item|
input checkbox_attributes(item)
label item_label(item), ":for": item_id(item)
end
end
|
#render_options ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 16
def render_options
if checkbox_options
render_checkbox_options
else
render_true_false_checkbox
end
end
|
#render_true_false_checkbox ⇒ Object
59
60
61
62
63
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 59
def render_true_false_checkbox
input true_false_checkbox_attributes.merge(type: :hidden, ":id": nil)
input true_false_checkbox_attributes.merge(type: :checkbox, ":id": item_id(1))
label input_label, ":for": item_id(1) if input_label
end
|
#response ⇒ Object
9
10
11
12
13
14
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 9
def response
div class: 'matestack-ui-core-form-checkbox' do
render_options
render_errors
end
end
|
#true_false_checkbox_attributes ⇒ Object
65
66
67
68
69
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 65
def true_false_checkbox_attributes
attributes.merge({
'init-value': init_value_for_single_input,
})
end
|
#value_key(value) ⇒ Object
100
101
102
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 100
def value_key(value)
value.is_a?(Numeric) ? ':value' : 'value'
end
|
#vue_props ⇒ Object
28
29
30
31
32
33
|
# File 'lib/matestack/ui/vue_js/components/form/checkbox.rb', line 28
def vue_props
{
init_value: init_value,
key: key,
}
end
|