-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Bulma integration
A work in progress for Bulma integration. This works as a basic, any improvements would be highly 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
- I'm unable to generate html for input checkboxes like in the commented section.
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
Currently Im rendering my forms like so:
= simple_form_for @organisation, wrapper: :default, defaults: { wrapper: false } do |f|
= f.input :email,
placeholder: 'Email',
input_html: { value: current_organisation.email },
label: false
= f.button :submit, "Save »",
class: 'button is-primary is-pulled-right'
config.wrappers :inline_input, tag: "div", class: "field is-horizontal" do |b|
b.wrapper :label, tag: "div", class: "field-label is-normal" do |bl|
bl.optional :label, class: "label"
end
b.wrapper :input, tag: "div", class: "field-body" do |bi|
bi.wrapper :input, tag: "div", class: "field" do |bf|
bf.use :input, class: "input"
bf.optional :hint, wrap_with: {tag: "p", class: "help"}
end
end
end
Take a look at https://gist.github.com/JuanVqz/f8b4941ba627341ae6d298f64e576869 for a more complete, drop in, solution
This page was created by the OSS community and might be outdated or incomplete. Feel free to improve or update this content according to the latest versions of SimpleForm and Rails to help the next developer who visits this wiki after you.
Keep in mind to maintain the guides as simple as possible and to avoid additional dependencies that might be specific to your application or workflow (such as Haml, RSpec, Guard and similars).