Class: BootstrapForms::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- BootstrapForms::FormBuilder
- Includes:
- Helpers::Wrappers
- Defined in:
- lib/bootstrap_forms/form_builder.rb
Instance Method Summary collapse
- #actions(&block) ⇒ Object
- #button(name = nil, args = {}) ⇒ Object
- #cancel(name = nil, args = {}) ⇒ Object
- #check_box(name, args = {}) ⇒ Object
- #collection_check_boxes(attribute, records, record_id, record_name, args = {}) ⇒ Object
- #collection_radio_buttons(attribute, records, record_id, record_name, args = {}) ⇒ Object
- #error_messages ⇒ Object
- #radio_buttons(name, values = {}, opts = {}) ⇒ Object
- #submit(name = nil, args = {}) ⇒ Object
- #uneditable_input(name, args = {}) ⇒ Object
Instance Method Details
#actions(&block) ⇒ Object
204 205 206 207 208 209 210 211 212 |
# File 'lib/bootstrap_forms/form_builder.rb', line 204 def actions(&block) content_tag(:div, :class => 'form-actions') do if block_given? yield else [submit, cancel].join(' ').html_safe end end end |
#button(name = nil, args = {}) ⇒ Object
175 176 177 178 179 180 181 182 183 |
# File 'lib/bootstrap_forms/form_builder.rb', line 175 def (name = nil, args = {}) name, args = nil, name if name.is_a?(Hash) @name = name = (args) @args = args [:class] ||= 'btn' super(name, args.merge()) end |
#cancel(name = nil, args = {}) ⇒ Object
195 196 197 198 199 200 201 202 |
# File 'lib/bootstrap_forms/form_builder.rb', line 195 def cancel(name = nil, args = {}) name, args = nil, name if name.is_a?(Hash) name ||= I18n.t('bootstrap_forms.buttons.cancel') = (args) [:class] ||= 'btn cancel' [:back] ||= :back link_to(name, [:back], :class => [:class]) end |
#check_box(name, args = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/bootstrap_forms/form_builder.rb', line 74 def check_box(name, args = {}) @name = name = (args) @args = args control_group_div do input_div do .merge!(required_attribute) if [:label] == false || [:label] == '' extras { super(name, @args.merge()) } else klasses = 'checkbox' klasses << ' inline' if .delete(:inline) == true @args.delete :inline label(@name, :class => klasses) do extras { super(name, @args.merge()) + ([:label].blank? ? human_attribute_name : [:label])} end end end end end |
#collection_check_boxes(attribute, records, record_id, record_name, args = {}) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/bootstrap_forms/form_builder.rb', line 112 def collection_check_boxes(attribute, records, record_id, record_name, args = {}) @name = attribute = (args) @args = args control_group_div do label_field + extras do content_tag(:div, :class => 'controls') do = .merge(required_attribute) records.collect do |record| [:id] = "#{object_name}_#{attribute}_#{record.send(record_id)}" checkbox = check_box_tag("#{object_name}[#{attribute}][]", record.send(record_id), [object.send(attribute)].flatten.include?(record.send(record_id)), ) content_tag(:label, :class => ['checkbox', ('inline' if [:inline])].compact) do checkbox + content_tag(:span, record.send(record_name)) end end.join('').html_safe end end end end |
#collection_radio_buttons(attribute, records, record_id, record_name, args = {}) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/bootstrap_forms/form_builder.rb', line 134 def (attribute, records, record_id, record_name, args = {}) @name = attribute = (args) @args = args control_group_div do label_field + extras do content_tag(:div, :class => 'controls') do = .merge(required_attribute) records.collect do |record| [:id] = "#{object_name}_#{attribute}_#{record.send(record_id)}" = ("#{object_name}[#{attribute}]", record.send(record_id), object.send(attribute) == record.send(record_id), ) content_tag(:label, :class => ['radio', ('inline' if [:inline])].compact) do + content_tag(:span, record.send(record_name)) end end.join('').html_safe end end end end |
#error_messages ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bootstrap_forms/form_builder.rb', line 7 def if object.try(:errors) and object.errors..any? content_tag(:div, :class => 'alert alert-block alert-error validation-errors') do content_tag(:h4, I18n.t('bootstrap_forms.errors.header', :model => object.class.model_name.human), :class => 'alert-heading') + content_tag(:ul) do object.errors..map do || content_tag(:li, ) end.join('').html_safe end end else '' # return empty string end end |
#radio_buttons(name, values = {}, opts = {}) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/bootstrap_forms/form_builder.rb', line 96 def (name, values = {}, opts = {}) @name = name = .slice(:namespace, :index).merge(opts.merge(required_attribute)) control_group_div do label_field + input_div do klasses = 'radio' klasses << ' inline' if .delete(:inline) == true values.map do |text, value| label("#{@name}_#{value}", :class => klasses) do extras { (name, value, ) + text } end end.join.html_safe end end end |
#submit(name = nil, args = {}) ⇒ Object
185 186 187 188 189 190 191 192 193 |
# File 'lib/bootstrap_forms/form_builder.rb', line 185 def submit(name = nil, args = {}) name, args = nil, name if name.is_a?(Hash) @name = name = (args) @args = args [:class] ||= 'btn btn-primary' super(name, args.merge()) end |
#uneditable_input(name, args = {}) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/bootstrap_forms/form_builder.rb', line 156 def uneditable_input(name, args = {}) @name = name = (args) @args = args control_group_div do label_field + input_div do extras do value = .delete(:value) [:class] = [[:class], 'uneditable-input'].compact content_tag(:span, ) do value || object.send(@name.to_sym) rescue nil end end end end end |