Sha256: 634ddc774ba822860cc784e24724e8e1322487726b4f68df555d65e3a1c82da3

Contents?: true

Size: 1.38 KB

Versions: 16

Compression:

Stored size: 1.38 KB

Contents

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.boolean_style = :nested

  config.wrappers :bootstrap, tag: 'div', class: 'form-group', error_class: 'has-error',
      defaults: { input_html: { class: 'default_class' } } do |b|

    b.use :html5
    b.use :min_max
    b.use :maxlength
    b.use :placeholder

    b.optional :pattern
    b.optional :readonly

    b.use :label

    b.wrapper tag: 'div', class: 'col-sm-10' do |ba|
      ba.use :input
      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.wrappers :checkbox, tag: :div, class: "checkbox", error_class: "has-error" do |b|
    b.use :html5

    b.wrapper tag: :label do |ba|
      ba.use :input
      ba.use :label_text
    end

    b.use :hint,  wrap_with: { tag: :p, class: "help-block" }
    b.use :error, wrap_with: { tag: :span, class: "help-block text-danger" }
  end

  config.default_wrapper = :bootstrap
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
brightcontent-core-2.4.1 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.4.0 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.3.4 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.3.3 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.3.2 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.3.1 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.3.0 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.2.2 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.2.1 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.2.0 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.1.5 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.1.4 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.1.3 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.1.2 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.1.1 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.1.0 config/initializers/simple_form_bootstrap.rb