Class: BootstrapFormHelper::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- BootstrapFormHelper::FormBuilder
- Defined in:
- lib/bootstrap_form_helper/form_builder.rb
Constant Summary collapse
- INPUTS =
(%w(select collection_select grouped_collection_select time_zone_select).map(&:to_sym) + field_helpers - %w(label check_box radio_button fields_for hidden_field).map(&:to_sym))
Instance Method Summary collapse
-
#actions(&block) ⇒ Object
Wraps action buttons into their own styled container.
-
#button(value = nil, options = {}) ⇒ Object
Renders a button with default classes to style it as a form button.
-
#fieldset(legend = nil, options = {}) ⇒ Object
Wraps the contents of the block passed to the method in a
fieldset
tag with a optionallegend
text. -
#label(attribute, text = '', options = {}, &block) ⇒ Object
Attaches a label to the inputs rendered inside of the block passed to it.
-
#submit(value = nil, options = {}) ⇒ Object
Renders a submit tag with default classes to style it as a primary form button.
Instance Method Details
#actions(&block) ⇒ Object
Wraps action buttons into their own styled container.
24 25 26 |
# File 'lib/bootstrap_form_helper/form_builder.rb', line 24 def actions(&block) @template.content_tag(:div, class: 'form-actions', &block) end |
#button(value = nil, options = {}) ⇒ Object
Renders a button with default classes to style it as a form button.
69 70 71 |
# File 'lib/bootstrap_form_helper/form_builder.rb', line 69 def (value = nil, = {}) super value, { type: 'button', class: 'btn' }.merge() end |
#fieldset(legend = nil, options = {}) ⇒ Object
Wraps the contents of the block passed to the method in a fieldset
tag with a optional legend
text.
14 15 16 17 18 19 |
# File 'lib/bootstrap_form_helper/form_builder.rb', line 14 def fieldset(legend = nil, = {}) @template.content_tag(:fieldset, ) do @template.concat @template.content_tag(:legend, legend) unless legend.nil? yield end end |
#label(attribute, text = '', options = {}, &block) ⇒ Object
Attaches a label to the inputs rendered inside of the block passed to it. Associates the label with the input for the attribute
given. If text
is passed, uses that as the text for the label; otherwise humanizes the attribute
name.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/bootstrap_form_helper/form_builder.rb', line 45 def label(attribute, text = '', = {}, &block) text, attribute = attribute, nil if attribute.kind_of? String = { class: 'control-label' }.merge() id = wrapper_id attribute, 'control_group' classes = wrapper_classes attribute, 'control-group' = .merge(builder: BootstrapFormHelper::FormControls) @template.content_tag(:div, id: id, class: classes) do @template.concat case when attribute && text then super(attribute, text, , &nil) when attribute then super(attribute, nil, , &nil) when text then @template.label_tag(nil, text, , &nil) end @template.concat @template.content_tag(:div, class: 'controls') { @template.fields_for object_name, object, , &block } end end |
#submit(value = nil, options = {}) ⇒ Object
Renders a submit tag with default classes to style it as a primary form button.
77 78 79 |
# File 'lib/bootstrap_form_helper/form_builder.rb', line 77 def submit(value = nil, = {}) value, { type: 'submit', class: 'btn btn-primary' }.merge() end |