Class: Bootstrap3FormBuilder::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Bootstrap3FormBuilder::FormBuilder
- Defined in:
- lib/bootstrap3_form_builder/form_builder.rb
Class Method Summary collapse
-
.create_tagged_field(method_name) ⇒ Object
Generates form fields that work with Twitter Bootstrap 3.
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 3.
13 14 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bootstrap3_form_builder/form_builder.rb', line 13 def self.create_tagged_field(method_name) define_method(method_name) do |label, *args| = args. custom_label = [:label] || label.to_s.humanize [:title] = [:title] || custom_label.capitalize label_class = [:label_class] || "" allow_pattern = allow_pattern?() validators = @object.class.validators_on(label).select { |validator| !validator..key? :if } (validators, ) (validators, ) (validators, ) (validators, ) (validators, , method_name) if ![:class] && method_name != :check_box [:class] = "form-control" end input_prefix = [:input_prefix] ? @template.content_tag("div", [:input_prefix], :class => "input-group-addon") : "" input_suffix = [:input_suffix] ? @template.content_tag("div", [:input_suffix], :class => "input-group-addon") : "" if !input_prefix.empty? || !input_suffix.empty? input = @template.content_tag("div", input_prefix.html_safe + super(label, *(args << )) + input_suffix.html_safe, :class => "input-group " + ([:input_container_class] || "")) else input = super(label, *(args << )) if [:input_container_class] input = @template.content_tag("div", input.html_safe, :class => [:input_container_class]) end end input = input.html_safe + ([:help_block] ? @template.content_tag("p", [:help_block], :class => "help-block") : "" ) + ([:help_inline] ? @template.content_tag("span", [:help_inline], :class => "help-inline") : "" ) if method_name == :check_box return @template.content_tag("div", @template.content_tag("label", input.html_safe + custom_label), :class => "checkbox") end @template.content_tag("div", @template.content_tag("label", custom_label, :for => "#{@object_name}_#{label}", :class => label_class) + input.html_safe, :class => control_group_class(label)) end end |
Instance Method Details
#submit(label, *args) ⇒ Object
Replace form submit input with styled buttons
4 5 6 7 8 |
# File 'lib/bootstrap3_form_builder/form_builder.rb', line 4 def submit(label, *args) = args. new_class = [:class] || Bootstrap3FormBuilder.default_submit_style super(label, *(args << .merge(:class => new_class))) end |