Class: Components::InputRow
- Inherits:
-
Base
- Object
- Base
- Components::InputRow
show all
- Defined in:
- app/components/input_row.rb
Instance Method Summary
collapse
Constructor Details
#initialize(form:, attribute:, label:, help: nil, group: false, options: {}) ⇒ InputRow
Returns a new instance of InputRow.
2
3
4
5
6
7
8
9
10
|
# File 'app/components/input_row.rb', line 2
def initialize(form:, attribute:, label:, help: nil, group: false, options: {})
@form = form
@attribute = attribute
@attribute_without_id = @attribute.to_s.gsub("_id", "")
@label = label
@help = help
@options = options
@group = group
end
|
Instance Method Details
#errors_for(object, attribute) ⇒ Object
41
42
43
44
45
46
47
|
# File 'app/components/input_row.rb', line 41
def errors_for(object, attribute)
return if object.nil? || attribute.nil?
return unless object.errors.include? attribute
div class: "invalid-feedback d-block" do
object.errors.full_messages_for(attribute).join("; ")
end
end
|
#help ⇒ Object
37
38
39
|
# File 'app/components/input_row.rb', line 37
def help
span(class: "form-text") { @help } if @help
end
|
33
34
35
|
# File 'app/components/input_row.rb', line 33
def input_element
raise NotImplementedError
end
|
27
28
29
30
31
|
# File 'app/components/input_row.rb', line 27
def input_group
div class: @group ? "input-group" : nil do
input_element
end
end
|
#label_class ⇒ Object
23
24
25
|
# File 'app/components/input_row.rb', line 23
def label_class
"col-form-label"
end
|
#view_template ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'app/components/input_row.rb', line 12
def view_template
div do
@form.label(@attribute, @label, class: label_class)
end
div do
input_group
errors_for(@form.object, @attribute_without_id)
help
end
end
|