Class: Fluxbit::Form::Component
- Inherits:
-
Component
- Object
- ViewComponent::Base
- Component
- Fluxbit::Form::Component
show all
- Defined in:
- app/components/fluxbit/form/component.rb
Overview
Instance Method Summary
collapse
Methods inherited from Component
#add, #add_popover_or_tooltip, #anyicon, #element_name, #fx_id, #icon, #initialize, #options, #popover?, #random_id, #remove_class, #remove_class_from_props, #render_popover_or_tooltip, #target, #tooltip?
#chevron_double_left, #chevron_double_right, #chevron_down, #chevron_left, #chevron_right, #chevron_up, #close_icon, #ellipsis_horizontal, #eye_icon, #eye_slash_icon, #plus_icon
Instance Method Details
#define_help_text(help_text, object, attribute) ⇒ 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_help_text(help_text, object, attribute)
return nil if help_text.is_a? FalseClass
if help_text.nil? && !object.nil? && !attribute.nil?
help_text = I18n.t(
attribute,
scope: [ object.class.name.pluralize.underscore.to_sym, :help_text ],
default: nil
)
end
(help_text.is_a?(Array) ? help_text : [ help_text ]) + errors
end
|
#define_helper_popover(helper_popover, object, attribute) ⇒ Object
26
27
28
29
30
31
|
# File 'app/components/fluxbit/form/component.rb', line 26
def define_helper_popover(helper_popover, object, attribute)
return nil if helper_popover == false
return helper_popover if !helper_popover.nil? || object.nil?
I18n.t(attribute, scope: [ object.class.name.pluralize.underscore.to_sym, :helper_popover ], default: nil)
end
|
#errors ⇒ Object
58
59
60
61
62
|
# File 'app/components/fluxbit/form/component.rb', line 58
def errors
return [] unless @object&.errors&.any?
@object.errors.filter { |f| f.attribute == @attribute }.map(&:full_message)
end
|
#help_text ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'app/components/fluxbit/form/component.rb', line 64
def help_text
return "" if @help_text.blank? || @help_text.compact.blank?
nodes = @help_text.compact.map do |text|
Fluxbit::Form::HelpTextComponent.new(color: @color).with_content(text).render_in(view_context)
end
view_context.safe_join(nodes)
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}_#{@attribute}"
end
|
#label ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/components/fluxbit/form/component.rb', line 45
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,
required: @required
).with_content(@label).render_in(view_context)
end
|
#label_value(label, object, attribute, id) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/components/fluxbit/form/component.rb', line 33
def label_value(label, object, attribute, id)
if label.nil? && !object.nil? && !attribute.nil?
key = [ object.class.name.pluralize.underscore.to_sym, :fields, attribute ]
return I18n.exists?(key) ? I18n.t(attribute, scope: key[0..-2]) : object.class.human_attribute_name(attribute)
end
return attribute.to_s.humanize if label.nil? && object.nil?
return id.to_s.humanize if label.nil? && !id.nil?
return label unless label.nil?
nil
end
|