Class: Fluxbit::Form::Component
- Inherits:
-
Component
- Object
- ViewComponent::Base
- Component
- Fluxbit::Form::Component
show all
- Defined in:
- app/components/fluxbit/form/component.rb
Overview
Direct Known Subclasses
CheckboxInputComponent, DatepickerComponent, HelperTextComponent, LabelComponent, RadioInputComponent, RangeInputComponent, SelectFreeInputComponent, SelectInputComponent, TextInputComponent, TextareaInputComponent, ToggleInputComponent, UploadImageInputComponent, UploadInputComponent
Constant Summary
Constants inherited
from Component
Component::ComponentObj
Instance Method Summary
collapse
Methods inherited from Component
#add, #add_popover_or_tooltip, #anyicon, #element_name, #fx_id, #initialize, #options, #random_id, #remove_class, #render_popover_or_tooltip, #target
Instance Method Details
#define_helper_popover(helper_popover, object, field) ⇒ Object
26
27
28
29
30
31
|
# File 'app/components/fluxbit/form/component.rb', line 26
def define_helper_popover(helper_popover, object, field)
return helper_popover if (helper_popover != false && !helper_popover.nil?) || object.nil?
object_name = object.class.name.underscore.to_sym
I18n.t(field, scope: [ :activerecord, :helper_popover, object_name ], default: nil)
end
|
#define_helper_text(helper_text, object, field) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/components/fluxbit/form/component.rb', line 12
def define_helper_text(helper_text, object, field)
return nil if helper_text.is_a? FalseClass
if helper_text.nil? && !object.nil? && !field.nil?
helper_text = I18n.t(
field,
scope: [ :activerecord, :helper_text, object.class.name.underscore.to_sym ],
default: nil
)
end
(helper_text.is_a?(Array) ? helper_text : [ helper_text ]) + errors
end
|
#errors ⇒ Object
53
54
55
56
57
|
# File 'app/components/fluxbit/form/component.rb', line 53
def errors
return [] unless @object&.errors&.any?
@object.errors.filter { |f| f.attribute == @field }.map(&:full_message)
end
|
#helper_text ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'app/components/fluxbit/form/component.rb', line 59
def helper_text
return "" if @helper_text.blank?
@helper_text.compact.map do |text|
concat Fluxbit::Form::HelperTextComponent.new(color: @color).with_content(text).render_in(view_context)
end
end
|
#id ⇒ Object
5
6
7
8
9
10
|
# File 'app/components/fluxbit/form/component.rb', line 5
def id
return @id ||= random_id if @props[:id].nil? && @form.nil?
return @props[:id] unless @props[:id].nil?
"#{@form.object_name}_#{@field}"
end
|
#label ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'app/components/fluxbit/form/component.rb', line 41
def label
return "" if @label.blank?
Fluxbit::Form::LabelComponent.new(
for: id,
color: @color,
helper_popover: @helper_popover,
helper_popover_placement: @helper_popover_placement,
class: @label_class
).with_content(@label).render_in(view_context)
end
|
#label_value(label, object, field, id) ⇒ Object
33
34
35
36
37
38
39
|
# File 'app/components/fluxbit/form/component.rb', line 33
def label_value(label, object, field, id)
return object.class.human_attribute_name(field) if label.nil? && !object.nil? && !field.nil?
return id.to_s.humanize if label.nil? && !id.nil?
return label unless label.nil?
nil
end
|