Sha256: e9354f3b9cd42f6bf11f77b77829ac0d630e87a8a442e1cf3b05ddba67c69bde

Contents?: true

Size: 1.57 KB

Versions: 39

Compression:

Stored size: 1.57 KB

Contents

# Examples for the `buttons` Field Partial

## Define Available Buttons via Localization Yaml

If you invoke the field partial in `app/views/account/some_class_name/_form.html.erb` like so:

```erb
<%= render 'shared/fields/buttons', form: form, method: :enabled %>
```

You can define the available buttons in `config/locales/en/some_class_name.en.yml` like so:

```yaml
en:
  some_class_name:
    fields:
      enabled:
        name: &enabled Enabled
        label: Should this item be enabled?
        heading: Enabled?
        options:
          yes: "Yes, this item should be enabled."
          no: "No, this item should be disabled."
```

## Generate Buttons Programmatically

You can generate the available buttons using a collection of database objects by passing the `button_field_options` option like so:

```erb
<%= render 'shared/fields/buttons', form: form, method: :category_id,
  button_field_options: Category.all.map { |category| [category.id, category.label_string] } %>
```

## Allow Multiple Button Selections

You can allow multiple buttons to be selected using the `multiple` option, like so:

```erb
<%= render 'shared/fields/buttons', form: form, method: :category_ids,
  button_field_options: Category.all.map { |category| [category.id, category.label_string] }, options: {multiple: true} %>
```

## Dynamically Updating Form Fields

If you'd like to:

* modify other fields based on the value of your `buttons` field, or
* modify your `buttons` field based on the value of other fields

See [Dynamic Forms and Dependent Fields](/docs/field-partials/dynamic-forms-dependent-fields.md).

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
bullet_train-1.19.1 docs/field-partials/buttons.md
bullet_train-1.19.0 docs/field-partials/buttons.md
bullet_train-1.18.0 docs/field-partials/buttons.md
bullet_train-1.17.1 docs/field-partials/buttons.md
bullet_train-1.17.0 docs/field-partials/buttons.md
bullet_train-1.16.0 docs/field-partials/buttons.md
bullet_train-1.15.0 docs/field-partials/buttons.md
bullet_train-1.14.2 docs/field-partials/buttons.md
bullet_train-1.14.1 docs/field-partials/buttons.md
bullet_train-1.14.0 docs/field-partials/buttons.md
bullet_train-1.13.0 docs/field-partials/buttons.md
bullet_train-1.12.3 docs/field-partials/buttons.md
bullet_train-1.12.2 docs/field-partials/buttons.md
bullet_train-1.12.1 docs/field-partials/buttons.md
bullet_train-1.12.0 docs/field-partials/buttons.md
bullet_train-1.11.0 docs/field-partials/buttons.md
bullet_train-1.10.0 docs/field-partials/buttons.md
bullet_train-1.9.0 docs/field-partials/buttons.md
bullet_train-1.8.5 docs/field-partials/buttons.md
bullet_train-1.8.4 docs/field-partials/buttons.md