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
67
68
69
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 67
def autoValidate(autoValidate)
@autoValidate = autoValidate
end
|
#context ⇒ Object
107
108
109
110
111
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 107
def context
form = page.current_form
association = form.nested_associations.last
@context ||= association || form
end
|
#created ⇒ Object
72
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
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 72
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
17
18
19
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 17
def default_url_options
{ only_path: true }
end
|
#determine_value(context, prop) ⇒ Object
103
104
105
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 103
def determine_value(context, prop)
context.field_value(prop)
end
|
#hint(hint) ⇒ Object
39
40
41
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 39
def hint(hint)
@hint = hint
end
|
#hint_args(hint_args) ⇒ Object
43
44
45
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 43
def hint_args(hint_args)
@hint_args = hint_args
end
|
#label(label) ⇒ Object
31
32
33
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 31
def label(label)
@label = label
end
|
#label_args(label_args) ⇒ Object
35
36
37
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 35
def label_args(label_args)
@label_args = label_args
end
|
#name(name) ⇒ Object
55
56
57
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 55
def name(name)
@name = name if name != Glib::Value::DEFAULT
end
|
#placeholder(placeholder) ⇒ Object
47
48
49
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 47
def placeholder(placeholder)
@placeholder = placeholder
end
|
#placeholder_args(placeholder_args) ⇒ Object
51
52
53
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 51
def placeholder_args(placeholder_args)
@placeholder_args = placeholder_args
end
|
#prop(prop) ⇒ Object
63
64
65
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 63
def prop(prop)
@prop = prop
end
|
#validation(validation) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 21
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
59
60
61
|
# File 'app/helpers/glib/json_ui/view_builder/fields.rb', line 59
def value(value)
@value = value if value != Glib::Value::DEFAULT
end
|