Sha256: a62e75ac30eebf630d1129f3dea3198170cd8290662644b9c343a70a15108513

Contents?: true

Size: 1.38 KB

Versions: 8

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

8 entries across 8 versions & 1 rubygems

Version Path
brightcontent-core-2.6.0 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.5.1 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.5.0 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.4.6 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.4.5 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.4.4 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.4.3 config/initializers/simple_form_bootstrap.rb
brightcontent-core-2.4.2 config/initializers/simple_form_bootstrap.rb