Class: Trestle::Form::Fields::FormControl

Inherits:
Trestle::Form::Field show all
Defined in:
lib/trestle/form/fields/form_control.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



25
26
27
# File 'lib/trestle/form/fields/form_control.rb', line 25

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

#extract_options!Object



29
30
31
32
33
34
# File 'lib/trestle/form/fields/form_control.rb', line 29

def extract_options!
  super

  @prepend = options.delete(:prepend)
  @append  = options.delete(:append)
end

#input_groupObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/trestle/form/fields/form_control.rb', line 13

def input_group
  if @prepend || @append
    (:div, class: "input-group") do
      concat (:span, @prepend, class: "input-group-addon") if @prepend
      concat yield
      concat (:span, @append, class: "input-group-addon") if @append
    end
  else
    yield
  end
end

#renderObject



5
6
7
8
9
10
11
# File 'lib/trestle/form/fields/form_control.rb', line 5

def render
  form_group do
    input_group do
      field
    end
  end
end