Skip to content

Instantly share code, notes, and snippets.

@volgar1x
Created January 25, 2014 13:53
Show Gist options
  • Save volgar1x/8616685 to your computer and use it in GitHub Desktop.
Save volgar1x/8616685 to your computer and use it in GitHub Desktop.
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
SimpleForm.setup do |config|
config.wrappers :default, tag: :div, class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.wrapper tag: :div, class: 'col-md-7' do |bb|
bb.use :input
bb.use :hint, wrap_with: { tag: :span, class: 'help-block' }
end
b.use :error, wrap_with: { tag: :span, class: 'help-block has-error' }
end
config.wrappers :checkbox, tag: :div, class: 'form-group', error_class: 'has-error' do |b|
b.wrapper tag: :div, class: 'col-md-offset-3 col-md-7' do |ba|
ba.wrapper :div, class: 'checkbox' do |bb|
bb.wrapper tag: :label do |bc|
bc.use :input, class: ''
bc.use :label_text
end
end
ba.use :hint, wrap_with: { tag: :span, class: 'help-block' }
ba.use :error, wrap_with: { tag: :span, class: 'help-block has-error' }
end
end
config.form_class = 'form-horizontal'
config.label_class = 'col-md-3 control-label'
config.button_class = 'btn btn-primary'
config.default_wrapper = :default
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment