Class: Matestack::Ui::VueJs::Components::Form::Base
- Inherits:
-
Vue
- Object
- Vue
- Matestack::Ui::VueJs::Components::Form::Base
show all
- Defined in:
- lib/matestack/ui/vue_js/components/form/base.rb
Instance Method Summary
collapse
Methods inherited from Vue
#base_vue_props, #component_uid, #create_children, inherited, #initialize, #matestack_ui_vuejs_ref, #vue_component, vue_name, #vue_name, #vue_props
Instance Method Details
#attribute_key ⇒ Object
81
82
83
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 81
def attribute_key
key.to_s + "#{'[]' if ctx.multiple && ctx.type == :file}"
end
|
#attributes ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 66
def attributes
(options || {}).merge({
"matestack-ui-vuejs-ref": matestack_ui_vuejs_ref("input.#{attribute_key}"),
":id": id,
type: ctx.type,
multiple: ctx.multiple,
placeholder: ctx.placeholder,
'v-on:change': change_event,
'init-value': init_value,
'v-bind:class': "{ '#{input_error_class}': #{error_key} }",
}).tap do |attrs|
attrs[:"#{v_model_type}"] = input_key unless type == :file
end
end
|
#change_event ⇒ Object
96
97
98
99
100
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 96
def change_event
input_changed = "vc.inputChanged('#{attribute_key}');"
input_changed << "vc.filesAdded('#{attribute_key}');" if type == :file
input_changed
end
|
#component_attributes ⇒ Object
14
15
16
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 14
def component_attributes
super.merge("matestack-ui-vuejs-ref": "#{form_context.component_uid}-#{component_id}")
end
|
#component_id ⇒ Object
18
19
20
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 18
def component_id
end
|
#display_errors? ⇒ Boolean
126
127
128
129
130
131
132
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 126
def display_errors?
if form_context.ctx.errors == false
error_config ? true : false
else
error_config != false
end
end
|
#error_class ⇒ Object
138
139
140
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 138
def error_class
get_from_error_config(:class) || 'error'
end
|
#error_config ⇒ Object
40
41
42
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 40
def error_config
ctx.errors
end
|
#error_key ⇒ Object
134
135
136
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 134
def error_key
"vc.parentFormErrors['#{key}']"
end
|
#error_tag ⇒ Object
142
143
144
145
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 142
def error_tag
get_from_error_config(:tag) || :div
end
|
#get_from_error_config(*keys) ⇒ Object
162
163
164
165
166
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 162
def get_from_error_config(*keys)
comp_error_config = error_config.dig(*keys) if error_config.is_a?(Hash)
form_error_config = form_context.ctx.errors.dig(*keys) if form_context.ctx.errors.is_a?(Hash)
comp_error_config || form_error_config
end
|
#id ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 44
def id
if ctx.id.present?
"'#{ctx.id}'"
else
if form_context.is_nested_form?
"'#{key}'+vc.parentNestedFormRuntimeId"
else
"'#{key}'"
end
end
end
|
#init ⇒ Object
36
37
38
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 36
def init
ctx.init
end
|
#init_value ⇒ Object
89
90
91
92
93
94
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 89
def init_value
return init unless init.nil?
if form_context.for_option.respond_to?(key)
form_context.for_option.send(key)
end
end
|
147
148
149
150
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 147
def input_error_class
get_from_error_config(:input, :class) || 'error'
end
|
102
103
104
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 102
def input_key
"vc.parentFormData['#{key}']"
end
|
32
33
34
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 32
def input_label
ctx.label
end
|
#key ⇒ Object
24
25
26
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 24
def key
ctx.key
end
|
#multiple ⇒ Object
56
57
58
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 56
def multiple
ctx.multiple
end
|
#name ⇒ Object
85
86
87
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 85
def name
attribute_key
end
|
#placeholder ⇒ Object
60
61
62
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 60
def placeholder
ctx.placeholder
end
|
#render_errors ⇒ Object
168
169
170
171
172
173
174
175
176
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 168
def render_errors
if display_errors?
Matestack::Ui::Component.new(wrapper_tag, class: wrapper_error_class, 'v-if': error_key) do
Matestack::Ui::Component.new(error_tag, class: error_class, 'v-for': "error in #{error_key}") do
plain vue.error
end
end
end
end
|
#type ⇒ Object
28
29
30
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 28
def type
ctx.type
end
|
#v_model_type(item = nil) ⇒ Object
set v-model.number for all numeric init values or options
107
108
109
110
111
112
113
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 107
def v_model_type(item=nil)
if item.nil?
(type == :number || init_value.is_a?(Numeric)) ? 'v-model.number' : 'v-model'
else
item.is_a?(Integer) ? 'v-model.number' : 'v-model'
end
end
|
#value_type(item = nil) ⇒ Object
set value-type “Integer” for all numeric init values or options
116
117
118
119
120
121
122
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 116
def value_type(item=nil)
if item.nil?
(type == :number || init_value.is_a?(Numeric)) ? Integer : nil
else
item.is_a?(Integer)? Integer : nil
end
end
|
#wrapper_error_class ⇒ Object
157
158
159
160
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 157
def wrapper_error_class
get_from_error_config(:wrapper, :class) || 'errors'
end
|
#wrapper_tag ⇒ Object
152
153
154
155
|
# File 'lib/matestack/ui/vue_js/components/form/base.rb', line 152
def wrapper_tag
get_from_error_config(:wrapper, :tag) || :div
end
|