Class: Bootstrap2FormBuilder::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Bootstrap2FormBuilder::FormBuilder
- Defined in:
- lib/bootstrap2_form_builder/form_builder.rb
Class Method Summary collapse
-
.create_tagged_field(method_name) ⇒ Object
Generates form fields that work with Twitter Bootstrap.
Instance Method Summary collapse
-
#submit(label, *args) ⇒ Object
Replace form submit input with styled buttons.
Class Method Details
.create_tagged_field(method_name) ⇒ Object
Generates form fields that work with Twitter Bootstrap. Automatically marks required things as required and places errors on matching inputs.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bootstrap2_form_builder/form_builder.rb', line 15 def self.create_tagged_field(method_name) define_method(method_name) do |label, *args| = args. custom_label = [:label] || label.to_s.humanize label_class = [:label_class] || "control-label" if @object.class.validators_on(label).collect(&:class).include? ActiveModel::Validations::PresenceValidator if label_class.nil? label_class = "required" else label_class = label_class + " required" end end control_group_class = "control-group" if @object.errors.[label] control_group_class = control_group_class + " error" end @template.content_tag("div", @template.content_tag("label", custom_label, :for => "#{@object_name}_#{label}", :class => label_class) + @template.content_tag("div", super(label, *(args << )) + (@template.content_tag("p", [:help_block], :class => "help-block") if [:help_block]) + (@template.content_tag("span", [:help_inline], :class => "help-inline") if [:help_inline]), :class => "controls"), :class => control_group_class) end end |
Instance Method Details
#submit(label, *args) ⇒ Object
Replace form submit input with styled buttons
4 5 6 7 8 9 |
# File 'lib/bootstrap2_form_builder/form_builder.rb', line 4 def submit(label, *args) = args. new_class = [:class] || "btn btn-primary" @template.content_tag("div", super(label, *(args << .merge(:class => new_class))), :class => "form-actions") end |