Skip to content

Console togglable fields

Petr Marek edited this page Jun 20, 2019 · 2 revisions

Use Folio::Console::FormsHelper or include it into your cell.

togglable_fields(simple_form_f_object, boolean_attr_key)

Simple usage

= simple_form_for model do |f|
  = f.input :name
  = f.input :email

  = f.simple_fields_for f, :billing_address do |g|
    = g.input :street

  = togglable_fields(f, :use_shipping_address)
    = f.simple_fields_for f, :shipping_address do |g|
      = g.input :street

Advanced usage

Hiding some of the fields within the form. Example showing User model with a company boolean attribute.

= simple_form_for user_model do |f|
  = f.input :email

  = togglable_fields(f, :company, parent: true)
    = togglable_fields_content
      .row
        .col-sm-6 = g.input :company_name
        .col-sm-6 = g.input :company_job

    = togglable_fields_content(reverse: true)
      .row
        .col-sm-6 = g.input :sex
        .col-sm-6 = g.input :birthdate

    .row
      .col-sm-6 = g.input :account_number

HTML in the togglable_fields_content block is visible when the checkbox is checked. HTML in the togglable_fields_content(reverse: true) block is visible when unchecked.