Skip to content
alexander brugmans edited this page Nov 19, 2018 · 8 revisions

A work in progress for Bulma integration. This works as a basic, any improvements would be higly appreciated.

Currently these things won't work and I think i have a bit of a hacky implementation, but its a start:

  • booleans
  • attributes for associated models with fields_for won't work
  • Im unable to generate html for input checkboxes like in the commented section.

Step 1

Create inside /config/initializers/simple_form_bulma.rb

SimpleForm.setup do |config|

  #config.generate_additional_classes_for = ['field']

  config.wrappers :default, tag: 'div', class: '', error_class: 'has-error' do |b|

    b.use         :placeholder
    b.optional    :maxlength
    b.optional    :pattern
    b.optional    :min_max
    b.optional    :readonly

    b.wrapper tag: 'div', class: 'field' do |ba|

      ba.use      :input,
                  :class      => 'input'

      ba.optional :hint,
                  :wrap_with  => { tag: 'p', class: 'help' }

      ba.optional :label,
                  :class      => 'label',
                  :wrap_with  => { tag: 'label', class: 'label' }
    end

    #
    #   %label.checkbox
    #     %input{:type => "checkbox"}/
    #     I agree to the
    #     %a{:href => "#"} terms and conditions
    # 
    # 

  end

  config.wrappers :boolean, tag: 'div', class: 'control', error_class: 'has-error' do |b|

    b.wrapper :label, tag: "label", class: "checkbox" do |ba|
      ba.use :input,  :class => 'checkbox'
      ba.use :label_text
      ba.use :hint,  :wrap_with => {tag: 'p', class: 'help'}
    end

  end

  class StringInput < SimpleForm::Inputs::StringInput
    def input(wrapper_options)
      template.content_tag(:div, super, class: 'control')
    end
  end

  class TextInput < SimpleForm::Inputs::TextInput
    def input_html_classes
      super.push('textarea')
    end
  end

end

Clone this wiki locally