Last active
December 23, 2015 23:39
-
-
Save miharekar/6711044 to your computer and use it in GitHub Desktop.
Simple Form Bootstrap 3 initializer
This file contains 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
inputs = %w[ | |
CollectionSelectInput | |
DateTimeInput | |
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 :bootstrap3, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| | |
b.use :html5 | |
b.use :min_max | |
b.use :maxlength | |
b.use :placeholder | |
b.optional :pattern | |
b.optional :readonly | |
b.use :label_input | |
b.use :hint, wrap_with: { tag: 'span', class: 'help-block' } | |
b.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' } | |
end | |
config.wrappers :prepend, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| | |
b.use :html5 | |
b.use :placeholder | |
b.wrapper tag: 'div', class: 'controls' do |input| | |
input.wrapper tag: 'div', class: 'input-group' do |prepend| | |
prepend.use :label , class: 'input-group-addon' | |
prepend.use :input | |
end | |
input.use :hint, wrap_with: { tag: 'span', class: 'help-block' } | |
input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' } | |
end | |
end | |
config.wrappers :append, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| | |
b.use :html5 | |
b.use :placeholder | |
b.wrapper tag: 'div', class: 'controls' do |input| | |
input.wrapper tag: 'div', class: 'input-group' do |prepend| | |
prepend.use :input | |
prepend.use :label , class: 'input-group-addon' | |
end | |
input.use :hint, wrap_with: { tag: 'span', class: 'help-block' } | |
input.use :error, wrap_with: { tag: 'span', class: 'help-block has-error' } | |
end | |
end | |
config.boolean_style = :nested | |
config.default_wrapper = :bootstrap3 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment