Class: Matestack::Ui::VueJs::Components::Form::Select
- Inherits:
-
Base
- Object
- Vue
- Base
- Matestack::Ui::VueJs::Components::Form::Select
show all
- Defined in:
- lib/matestack/ui/vue_js/components/form/select.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, #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
#component_id ⇒ Object
32
33
34
|
# File 'lib/matestack/ui/vue_js/components/form/select.rb', line 32
def component_id
"select-component-for-#{key}"
end
|
#disabled_options ⇒ Object
87
88
89
|
# File 'lib/matestack/ui/vue_js/components/form/select.rb', line 87
def disabled_options
@disabled_options ||= options.delete(:disabled_options)
end
|
#item_disabled?(item) ⇒ Boolean
73
74
75
|
# File 'lib/matestack/ui/vue_js/components/form/select.rb', line 73
def item_disabled?(item)
disabled_options && disabled_options.to_a.include?(item)
end
|
#item_id(item) ⇒ Object
69
70
71
|
# File 'lib/matestack/ui/vue_js/components/form/select.rb', line 69
def item_id(item)
"#{key}_#{item_value(item)}"
end
|
#item_label(item) ⇒ Object
65
66
67
|
# File 'lib/matestack/ui/vue_js/components/form/select.rb', line 65
def item_label(item)
item.is_a?(Array) ? item.first : item
end
|
#item_value(item) ⇒ Object
61
62
63
|
# File 'lib/matestack/ui/vue_js/components/form/select.rb', line 61
def item_value(item)
item.is_a?(Array) ? item.last : item
end
|
#render_options ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/matestack/ui/vue_js/components/form/select.rb', line 19
def render_options
if placeholder
option value: nil, disabled: true, selected: init_value.nil?, text: placeholder
end
select_options.to_a.each do |item|
option_config = {}.tap do |attrs|
attrs[value_key(item)] = item_value(item)
attrs[:disabled] = item_disabled?(item)
end
option item_label(item), option_config
end
end
|
#response ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/matestack/ui/vue_js/components/form/select.rb', line 9
def response
div class: 'matestack-ui-core-form-select' do
label input_label, ":for": id if input_label
select select_attributes do
render_options
end
render_errors
end
end
|
#select_attributes ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/matestack/ui/vue_js/components/form/select.rb', line 43
def select_attributes
attributes.except(:options).merge({
multiple: multiple,
":id": id,
"matestack-ui-vuejs-ref": matestack_ui_vuejs_ref("select#{'.multiple' if multiple}.#{key}"),
'value-type': value_type(select_options.first),
'init-value': init_value,
})
end
|
#select_options ⇒ Object
55
56
57
|
# File 'lib/matestack/ui/vue_js/components/form/select.rb', line 55
def select_options
@select_options ||= options.delete(:options)
end
|
#v_model_type ⇒ Object
77
78
79
|
# File 'lib/matestack/ui/vue_js/components/form/select.rb', line 77
def v_model_type
item_value(select_options.first).is_a?(Numeric) ? 'v-model.number' : 'v-model'
end
|
#value_key(value) ⇒ Object
81
82
83
|
# File 'lib/matestack/ui/vue_js/components/form/select.rb', line 81
def value_key(value)
value.is_a?(Numeric) ? ':value' : 'value'
end
|
#vue_props ⇒ Object
36
37
38
39
40
41
|
# File 'lib/matestack/ui/vue_js/components/form/select.rb', line 36
def vue_props
{
init_value: init_value,
key: key,
}
end
|