Created
July 28, 2013 19:08
-
-
Save eraserewind/6099719 to your computer and use it in GitHub Desktop.
bootstrap 3 horizontal form rails builder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BootstrapHorizontalForm < ActionView::Helpers::FormBuilder | |
def text_field(method, options={}) | |
width = options[:width] || 10 | |
t = @template | |
t.content_tag(:div, :class => "form-group#{' has-error' unless @object.errors[method].blank?}") { | |
t.concat(t.label(@object_name, method, class: 'col-lg-2 control-label')) | |
t.concat(t.content_tag(:div, class: "col-lg-#{width}") { | |
t.concat(t.text_field(@object_name, method, options.merge(class: 'form-control'))) | |
if @object.errors[method].present? | |
t.concat(t.content_tag(:span, @object.errors[method].join(', '), :class => 'help-block')) | |
end | |
}) | |
} | |
end | |
def check_box(method, options={}) | |
t = @template | |
t.content_tag(:div, class: "form-group #{' has-error' unless @object.errors[method].blank?}") { | |
t.concat(t.content_tag(:div, class: 'col-lg-10 col-offset-2') { | |
t.concat(t.content_tag(:div, class: 'checkbox') { | |
t.concat(t.check_box(@object_name, method)) | |
t.concat(t.label(@object_name, method)) | |
}) | |
}) | |
} | |
end | |
def submit(value=nil, options={}) | |
@template.content_tag(:div, class: 'col-lg-10 col-offset-2') { | |
super(value, options.merge(class: 'btn btn-primary')) | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment