Class: Glib::JsonUi::ViewBuilder::Fields::AbstractField
- Inherits:
-
View
show all
- Defined in:
- app/helpers/glib/json_ui/view_builder/fields.rb
Direct Known Subclasses
CheckGroup, ChipGroup, CreditCard, Date, Datetime, DynamicGroup, DynamicSelect, Location, MultiUpload, Otp, Phone, RadioGroup, Rating, Select, Sign, StripeExternalAccount, StripeToken, Submit, Text, TimeZone
Instance Attribute Summary
#json, #page
Instance Method Summary
collapse
Methods inherited from View
component_name
#initialize, #props
Instance Method Details
#autoValidate(autoValidate) ⇒ Object
68
69
70
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 68
def autoValidate(autoValidate)
@autoValidate = autoValidate
end
|
#context ⇒ Object
108
109
110
111
112
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 108
def context
form = page.current_form
association = form.nested_associations.last
@context ||= association || form
end
|
#created ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 73
def created
if @prop && (form = page.current_form)
context.field_assert_respond_to(@prop)
@name ||= context.field_name(@prop, @multiple || false)
@label ||= context.field_label(@prop, @label_args || {})
@hint ||= context.hint_label(@prop, @hint_args || {})
@placeholder ||= context.placeholder_label(@prop, @placeholder_args || {})
if form._autoValidate && @autoValidate.nil? || !@autoValidate.nil? && @autoValidate
@validation ||= context.field_validation(@prop)
end
if form.current_dynamic_group.nil?
@value ||= determine_value(context, @prop)
end
end
json.name @name
json.value @value if @value
json.label @label if @label
json.hint @hint if @hint
json.placeholder @placeholder if @placeholder
json.validation @validation if @validation.present?
end
|
#default_url_options ⇒ Object
18
19
20
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 18
def default_url_options
{ only_path: true }
end
|
#determine_value(context, prop) ⇒ Object
104
105
106
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 104
def determine_value(context, prop)
context.field_value(prop)
end
|
#hint(hint) ⇒ Object
40
41
42
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 40
def hint(hint)
@hint = hint
end
|
#hint_args(hint_args) ⇒ Object
44
45
46
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 44
def hint_args(hint_args)
@hint_args = hint_args
end
|
#label(label) ⇒ Object
32
33
34
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 32
def label(label)
@label = label
end
|
#label_args(label_args) ⇒ Object
36
37
38
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 36
def label_args(label_args)
@label_args = label_args
end
|
#name(name) ⇒ Object
56
57
58
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 56
def name(name)
@name = name if name != Glib::Value::DEFAULT
end
|
#placeholder(placeholder) ⇒ Object
48
49
50
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 48
def placeholder(placeholder)
@placeholder = placeholder
end
|
#placeholder_args(placeholder_args) ⇒ Object
52
53
54
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 52
def placeholder_args(placeholder_args)
@placeholder_args = placeholder_args
end
|
#prop(prop) ⇒ Object
64
65
66
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 64
def prop(prop)
@prop = prop
end
|
#validation(validation) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 22
def validation(validation)
return if validation.blank?
if validation[:format].present?
context.cast_to_js_regex(validation[:format])
end
json.validation validation
end
|
#value(value) ⇒ Object
60
61
62
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 60
def value(value)
@value = value if value != Glib::Value::DEFAULT
end
|