Skip to content

Instantly share code, notes, and snippets.

@flexbox
Last active July 16, 2018 13:22
Show Gist options
  • Save flexbox/5932968 to your computer and use it in GitHub Desktop.
Save flexbox/5932968 to your computer and use it in GitHub Desktop.
ruby on rails - simple_form syntax helper
= f.input :name, input_html: { autofocus: f.object.name.blank? }
# Remplace input type="submit" with button type="submit"
# to use :after and :before pseudo classes
f.button :button
# jQuery analytics tracking code
= simple_form do |f|
= f.association :brand, input_html: { class: 'js-smart-search', data: { placeholder: 'Foo', placeholder: 'Bar' } }
= f.input :mobile, as: :tel
= f.input :phone, as: :tel
= f.input :fax, as: :tel
# HTML5 Search input
= simple_form
= search_field_tag :search, id: "search_field", placeholder: "Rechercher", "autosave" => ""
= main_address_form.input :salutation, label: false, include_blank: '-'
, { prompt: '-' }
SimpleForm.setup do |config|
# Custom wrapper for custom_foundation_project forms.
config.wrappers :custom_foundation_project, tag: 'div', error_class: 'error' do |b|
b.use :html5
b.use :placeholder
b.use :label
b.use :input
b.use :error, wrap_with: { tag: 'small', class: 'error' }
end
# Style for required fields.
config.label_text = lambda { |label, required| "#{label} #{required}" }
end
# Custom wrapper for project
= simple_form_for [:account, address], wrapper: :custom_foundation_project, html: { class: 'custom' } do |form|
# Wrapper HTML
= simple_form
= form.input :engraving, wrapper: 'checkbox_right', wrapper_html: { class: 'no-left-label' }, label: t('.engraving')
@epodczaszy-silicon
Copy link

= f.collection_check_boxes(:activity_kinds, Project.activity_kinds.values, :to_s, :text) do |b|
  p
    = b.check_box
    = b.label do
      = b.text
      span class="checkbox-description" = t("simple_form.placeholders.activity_kinds.#{b.value}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment