Class: Trestle::Form::Fields::FormGroup
Constant Summary
collapse
- WRAPPER_OPTIONS =
[:help, :label, :hide_label]
Instance Attribute Summary
#block, #builder, #name, #options, #template
Instance Method Summary
collapse
#errors, #field, #form_group, #initialize
Instance Method Details
#defaults ⇒ Object
32
33
34
|
# File 'lib/trestle/form/fields/form_group.rb', line 32
def defaults
super.merge(class: ["form-group"])
end
|
#error_message ⇒ Object
22
23
24
25
26
|
# File 'lib/trestle/form/fields/form_group.rb', line 22
def error_message
content_tag(:p, class: "help-block") do
safe_join([icon("fa fa-warning"), errors.first], " ")
end
end
|
36
37
38
|
# File 'lib/trestle/form/fields/form_group.rb', line 36
def
end
|
#help_message ⇒ Object
18
19
20
|
# File 'lib/trestle/form/fields/form_group.rb', line 18
def help_message
content_tag(:p, options[:help], class: "help-block")
end
|
#label ⇒ Object
28
29
30
|
# File 'lib/trestle/form/fields/form_group.rb', line 28
def label
builder.label(name, options[:label], class: ["control-label", ("sr-only" if options[:hide_label])].compact)
end
|
#render ⇒ Object
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/trestle/form/fields/form_group.rb', line 7
def render
options[:class] << 'has-error' if errors.any?
content_tag(:div, options.except(*WRAPPER_OPTIONS)) do
concat label unless options[:label] == false
concat template.capture(&block) if block
concat help_message if options[:help]
concat error_message if errors.any?
end
end
|