Class: ActionView::Helpers::FormBuilder

Inherits:
Object
  • Object
show all
Includes:
BootstrapFormHelper, ButtonHelper, FormatHelper
Defined in:
app/helpers/bootstrap_form_options_helper.rb,
app/helpers/bootstrap_form_helper.rb

Constant Summary

Constants included from BootstrapFormHelper

BootstrapFormHelper::FIELD_HELPERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ButtonHelper

#button, #button_group, #button_toolbar, #navbar_button

Methods included from FormatHelper

#parse_content_or_options, #prepend_class, #squeeze_n_strip

Methods included from BootstrapFormHelper

#fields_for, #form_for, #render_field, #render_help_text, #render_input_addon

Methods included from PanelHelper

#panel

Instance Attribute Details

#output_bufferObject

Returns the value of attribute output_buffer.



102
103
104
# File 'app/helpers/bootstrap_form_helper.rb', line 102

def output_buffer
  @output_buffer
end

Instance Method Details

#check_box(method, options = {}, checked_value = '1', unchecked_value = '0') ⇒ Object



104
105
106
107
108
109
110
111
112
113
# File 'app/helpers/bootstrap_form_helper.rb', line 104

def check_box(method, options = {}, checked_value = '1', unchecked_value = '0')
  layout_inline, help_text, label = parse_options(options)

  check_box_proc = proc do
    @template.check_box(@object_name, method, objectify_options(options), checked_value, unchecked_value) +
      label
  end

  render_input_field(layout_inline, help_text, :checkbox, &check_box_proc)
end

#collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/bootstrap_form_options_helper.rb', line 29

def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
  check_boxes_proc = proc do
    @template.collection_check_boxes(@object_name,
                                     method,
                                     collection,
                                     value_method,
                                     text_method,
                                     objectify_options(options),
                                     @default_options.merge(html_options),
                                     &block)
  end

  render_collection(options.delete(:label), &check_boxes_proc)
end

#collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/bootstrap_form_options_helper.rb', line 44

def collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
  radio_buttons_proc = proc do
    @template.collection_radio_buttons(@object_name,
                                       method,
                                       collection,
                                       value_method,
                                       text_method,
                                       objectify_options(options),
                                       @default_options.merge(html_options),
                                       &block)
  end

  render_collection(options.delete(:label), &radio_buttons_proc)
end

#radio_button(method, tag_value, options = {}) ⇒ Object



115
116
117
118
119
120
121
122
123
124
# File 'app/helpers/bootstrap_form_helper.rb', line 115

def radio_button(method, tag_value, options = {})
  layout_inline, help_text, label = parse_options(options)

  radio_button_proc = proc do
    @template.radio_button(@object_name, method, tag_value, objectify_options(options)) +
      label
  end

  render_input_field(layout_inline, help_text, :radio, &radio_button_proc)
end

#select(method, choices = nil, options = {}, html_options = {}, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/bootstrap_form_options_helper.rb', line 7

def select(method, choices = nil, options = {}, html_options = {}, &block)
  label_class, field_wrapper = horizontal_layout? ? ['col-sm-3 control-label', true] : []

  required      = 'required' if options.delete(:required)
  label_sr_only = 'sr-only' if options[:label].is_a?(FalseClass) || layout == :inline
  label_class   = squeeze_n_strip("#{label_class} #{required} #{label_sr_only}")
  help_text     = render_help_text(options.delete(:help))

  prepend_class(html_options, 'form-control')
  select_proc = proc do
    @template.select(@object_name,
                     method,
                     choices,
                     objectify_options(options),
                     @default_options.merge(html_options),
                     &block) + help_text
  end
  label_proc  = proc { label(method, options.delete(:label), class: label_class) }

  render_field(field_wrapper, label_proc, select_proc)
end

#submit(value = nil, options = {}) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'app/helpers/bootstrap_form_helper.rb', line 126

def submit(value=nil, options={})
  value, options = nil, value if value.is_a?(Hash)
  value ||= submit_default_value

  prepend_class(options, 'btn', get_btn_type(options.delete(:type)))

  submit_prc = proc { @template.submit_tag(value, options) }

  return submit_prc.call unless horizontal_layout?

   :div, class: 'form-group' do
     :div, class: 'col-sm-offset-3 col-sm-9', &submit_prc
  end
end