Sha256: 80186ec87e4550bc39db6ea04910a9703a17733ef5609d7cce9b4d2815c4444c

Contents?: true

Size: 1.54 KB

Versions: 4

Compression:

Stored size: 1.54 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 `options` option like so:

```erb
<%= render 'shared/fields/buttons', form: form, method: :category_id,
  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,
  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

4 entries across 4 versions & 1 rubygems

Version Path
bullet_train-1.7.3 docs/field-partials/buttons.md
bullet_train-1.7.2 docs/field-partials/buttons.md
bullet_train-1.7.1 docs/field-partials/buttons.md
bullet_train-1.7.0 docs/field-partials/buttons.md