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, #readonly?

Constructor Details

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

Instance Method Details

#defaultsObject



33
34
35
# File 'lib/trestle/form/fields/form_control.rb', line 33

def defaults
  super.merge(class: ["form-control"])
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 (:div, input_group_addon(@prepend), class: "input-group-prepend") if @prepend
      concat yield
      concat (:div, input_group_addon(@append), class: "input-group-append") if @append
    end
  else
    yield
  end
end

#input_group_addon(addon) ⇒ Object



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

def input_group_addon(addon)
  if addon[:wrap]
    (:span, addon[:content], class: "input-group-text")
  else
    addon[:content]
  end
end

#normalize_options!Object



37
38
39
40
41
42
43
44
# File 'lib/trestle/form/fields/form_control.rb', line 37

def normalize_options!
  super

  @prepend = { content: options.delete(:prepend),  wrap: true }  if options[:prepend]
  @prepend = { content: options.delete(:prepend!), wrap: false } if options[:prepend!]
  @append  = { content: options.delete(:append),   wrap: true }  if options[:append]
  @append  = { content: options.delete(:append!),  wrap: false } if options[:append!]
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