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

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

Constant Summary collapse

WRAPPER_OPTIONS =
[:help, :label, :hide_label]

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



32
33
34
# File 'lib/trestle/form/fields/form_group.rb', line 32

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

#error_messageObject



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

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

#extract_options!Object



36
37
38
# File 'lib/trestle/form/fields/form_group.rb', line 36

def extract_options!
  # Do not call super
end

#help_messageObject



18
19
20
# File 'lib/trestle/form/fields/form_group.rb', line 18

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

#labelObject



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

#renderObject



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?

  (: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