Class: Trestle::Form::Fields::FormGroup

Inherits:
Trestle::Form::Field show all
Defined in:
lib/trestle/form/fields/form_group.rb

Instance Attribute Summary

Attributes inherited from Trestle::Form::Field

#block, #builder, #name, #options, #template

Instance Method Summary collapse

Methods inherited from Trestle::Form::Field

#errors, #field, #form_group, #initialize

Constructor Details

This class inherits a constructor from Trestle::Form::Field

Instance Method Details

#defaultsObject



30
31
32
# File 'lib/trestle/form/fields/form_group.rb', line 30

def defaults
  super.merge(class: ["form-group"])
end

#error_messageObject



20
21
22
23
24
# File 'lib/trestle/form/fields/form_group.rb', line 20

def error_message
  (:p, class: "help-block") do
    safe_join([icon("fa fa-warning"), errors.first], " ")
  end
end

#extract_options!Object



34
35
36
# File 'lib/trestle/form/fields/form_group.rb', line 34

def extract_options!
  # Do not call super
end

#help_messageObject



16
17
18
# File 'lib/trestle/form/fields/form_group.rb', line 16

def help_message
  (:p, options[:help], class: "help-block")
end

#labelObject



26
27
28
# File 'lib/trestle/form/fields/form_group.rb', line 26

def label
  builder.label(name, options[:label], class: ["control-label", ("sr-only" if options[:hide_label])].compact)
end

#renderObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/trestle/form/fields/form_group.rb', line 5

def render
  options[:class] << 'has-error' if errors.any?

  (:div, options) do
    concat label unless options[:label] == false
    concat block.call if block
    concat help_message if options[:help]
    concat error_message if errors.any?
  end
end