Skip to content

Commit

Permalink
bootstrap wrapper added.
Browse files Browse the repository at this point in the history
  • Loading branch information
OCC authored and OCC committed Aug 29, 2013
1 parent b407ec2 commit e7b79f2
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions config/initializers/simple_form_bootstrap.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
config.wrappers :bootstrap, tag: 'div', class: 'control-group', error_class: 'error' do |b|
config.wrappers :bootstrap, tag: 'div', class: 'form-group', error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper tag: 'div', class: 'controls' do |ba|
ba.use :input
ba.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end
b.use :label, class: 'control-label'
b.use :input
b.use :error, wrap_with: { tag: 'span', class: 'help-inline' }
b.use :hint, wrap_with: { tag: 'p', class: 'help-block' }
end

config.wrappers :prepend, tag: 'div', class: "control-group", error_class: 'error' do |b|
config.wrappers :prepend, tag: 'div', class: 'form-group', error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper tag: 'div', class: 'controls' do |input|
b.use :label, class: 'control-label'
b.wrapper tag: 'div', class: 'input-group' do |input|
input.wrapper tag: 'div', class: 'input-prepend' do |prepend|
prepend.use :input
end
Expand All @@ -24,11 +21,11 @@
end
end

config.wrappers :append, tag: 'div', class: "control-group", error_class: 'error' do |b|
config.wrappers :append, tag: 'div', class: 'form-group', error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper tag: 'div', class: 'controls' do |input|
b.wrapper tag: 'div', class: 'input-group' do |input|
input.wrapper tag: 'div', class: 'input-append' do |append|
append.use :input
end
Expand All @@ -37,21 +34,34 @@
end
end

config.wrappers :inline_checkbox, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
b.use :html5
b.use :placeholder
b.wrapper :tag => 'div', :class => 'controls' do |ba|
ba.wrapper :tag => 'label', :class => 'checkbox' do |bb|
bb.use :input
bb.use :label_text
end
ba.use :error, :wrap_with => { :tag => 'span', :class => 'help-inline' }
ba.use :hint, :wrap_with => { :tag => 'p', :class => 'help-block' }
end
end
# Wrappers for forms and inputs using the Twitter Bootstrap toolkit.
# Check the Bootstrap docs (http://twitter.github.com/bootstrap)
# to learn about the different styles for forms and inputs,
# buttons and other elements.
config.default_wrapper = :bootstrap
end


inputs = %w[
CollectionSelectInput
DateTimeInput
FileInput
GroupedCollectionSelectInput
NumericInput
PasswordInput
RangeInput
StringInput
TextInput
]

inputs.each do |input_type|
superclass = "SimpleForm::Inputs::#{input_type}".constantize

new_class = Class.new(superclass) do
def input_html_classes
super.push('form-control')
end
end

Object.const_set(input_type, new_class)
end

0 comments on commit e7b79f2

Please sign in to comment.