Class: MNE::TwitterBootstrapFormBuilder::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- MNE::TwitterBootstrapFormBuilder::FormBuilder
- Includes:
- ActionView::Helpers::DynamicForm::FormBuilderMethods
- Defined in:
- lib/twitter-bootstrap-form-builder/form_builder.rb
Instance Method Summary collapse
-
#check_box(field, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
Special handling for check boxes, which can have two labels.
- #control_group(field = nil, opts = {}, &block) ⇒ Object
-
#submit(value = nil, options = {}) ⇒ Object
Very light wrapper around FormBuilder#submit which adds a ‘btn’ class.
Instance Method Details
#check_box(field, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
Special handling for check boxes, which can have two labels
Options
:label - As the *_field methods
:text - Like :label but for the right-hand label
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/twitter-bootstrap-form-builder/form_builder.rb', line 66 def check_box(field, = {}, checked_value = "1", unchecked_value = "0") label_tag = build_label_tag(field, ) return super if label_tag === false control_group_opts = [:control_group] || {} [:text] ||= false control_group(field, control_group_opts) do label_tag + @template.content_tag(:div, :class => "controls") do opts = .clone opts[:text] = nil check_box_tag = super(field, opts, checked_value, unchecked_value).html_safe text_tag = build_label_tag(field, , :text, {:class => "checkbox"}) do |opts| "#{check_box_tag} #{opts[0]}".html_safe end text_tag ||= @template.content_tag(:label, check_box_tag, :class => "checkbox") text_tag.html_safe + errors_for(field) end.html_safe end.html_safe end |
#control_group(field = nil, opts = {}, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/twitter-bootstrap-form-builder/form_builder.rb', line 9 def control_group(field = nil, opts = {}, &block) raise "Expected hash for options, got #{opts.inspect}" unless opts.is_a? Hash # wrap in array if not an array opts[:class] = Array(opts[:class]) opts[:class] << "control-group" opts[:class] << field.to_s.gsub(/[^-_a-zA-Z0-9]/, "") if field opts[:class] << "error" if @object && @object.errors..has_key?(field) && @object.errors.[field].any? @template.content_tag(:div, opts) do @template.capture &block end end |
#submit(value = nil, options = {}) ⇒ Object
Very light wrapper around FormBuilder#submit which adds a ‘btn’ class
Options:
:label => false - fall back to FormBuilder#submit
:primary => true - add btn-primary class
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/twitter-bootstrap-form-builder/form_builder.rb', line 98 def submit(value = nil, = {}) if [:label] === false .delete(:label) return super end [:class] = "#{[:class]} btn" [:class] = "#{[:class]} btn-primary" if .delete(:primary) super(value, ) end |