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
212 213 214 215 216 217 218 219 220 |
# File 'lib/bootstrap_forms/form_builder.rb', line 212 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
183 184 185 186 187 188 189 190 191 |
# File 'lib/bootstrap_forms/form_builder.rb', line 183 def (name = nil, args = {}) name, args = nil, name if name.is_a?(Hash) @name = name @field_options = (args) @args = args @field_options[:class] ||= 'btn' super(name, args.merge(@field_options)) end |
#cancel(name = nil, args = {}) ⇒ Object
203 204 205 206 207 208 209 210 |
# File 'lib/bootstrap_forms/form_builder.rb', line 203 def cancel(name = nil, args = {}) name, args = nil, name if name.is_a?(Hash) name ||= I18n.t('bootstrap_forms.buttons.cancel') @field_options = (args) @field_options[:class] ||= 'btn cancel' @field_options[:back] ||= :back link_to(name, @field_options[:back], :class => @field_options[:class]) end |
#check_box(name, args = {}) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/bootstrap_forms/form_builder.rb', line 82 def check_box(name, args = {}) @name = name @field_options = (args) @args = args control_group_div do input_div do @field_options.merge!(required_attribute) if @field_options[:label] == false || @field_options[:label] == '' extras { super(name, @args.merge(@field_options)) } else klasses = 'checkbox' klasses << ' inline' if @field_options.delete(:inline) == true @args.delete :inline label(@name, :class => klasses) do extras { super(name, @args.merge(@field_options)) + (@field_options[:label].blank? ? human_attribute_name : @field_options[:label])} end end end end end |
#collection_check_boxes(attribute, records, record_id, record_name, args = {}) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/bootstrap_forms/form_builder.rb', line 120 def collection_check_boxes(attribute, records, record_id, record_name, args = {}) @name = attribute @field_options = (args) @args = args control_group_div do label_field + extras do content_tag(:div, :class => 'controls') do = @field_options.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 @field_options[: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
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/bootstrap_forms/form_builder.rb', line 142 def (attribute, records, record_id, record_name, args = {}) @name = attribute @field_options = (args) @args = args control_group_div do label_field + extras do content_tag(:div, :class => 'controls') do = @field_options.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 @field_options[:inline])].compact) do + content_tag(:span, record.send(record_name)) end end.join('').html_safe end end end end |
#error_messages ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bootstrap_forms/form_builder.rb', line 8 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
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/bootstrap_forms/form_builder.rb', line 104 def (name, values = {}, opts = {}) @name = name @field_options = @options.slice(:namespace, :index).merge(opts.merge(required_attribute)) control_group_div do label_field + input_div do klasses = 'radio' klasses << ' inline' if @field_options.delete(:inline) == true values.map do |text, value| label("#{@name}_#{value}", :class => klasses) do extras { (name, value, @field_options) + text } end end.join.html_safe end end end |
#submit(name = nil, args = {}) ⇒ Object
193 194 195 196 197 198 199 200 201 |
# File 'lib/bootstrap_forms/form_builder.rb', line 193 def submit(name = nil, args = {}) name, args = nil, name if name.is_a?(Hash) @name = name @field_options = (args) @args = args @field_options[:class] ||= 'btn btn-primary' super(name, args.merge(@field_options)) end |
#uneditable_input(name, args = {}) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/bootstrap_forms/form_builder.rb', line 164 def uneditable_input(name, args = {}) @name = name @field_options = (args) @args = args control_group_div do label_field + input_div do extras do value = @field_options.delete(:value) @field_options[:class] = [@field_options[:class], 'uneditable-input'].compact content_tag(:span, @field_options) do value || object.send(@name.to_sym) rescue nil end end end end end |