Skip to content

Commit

Permalink
Merge pull request #824 from bullet-train-co/jeremy/button_field_opti…
Browse files Browse the repository at this point in the history
…ons_fix

Bug fix for passing options to the `buttons` field partial
  • Loading branch information
jagthedrummer authored May 7, 2024
2 parents 9f03882 + e47843b commit 04c0081
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ form ||= current_fields_form
# TODO: We need to do this because `options` is currently an array of strings.
# i.e. - ["One", "Two", "Three"]
if defined?(options) && options.is_a?(Array)
button_field_buttons = options
button_field_options = options
options = defined?(html_options) ? html_options : {}
ActiveSupport::Deprecation.new.warn(
"`options` will be replaced with `button_field_options` in a later version. " \
"Please pass all of the strings you want to appear in your buttons to `button_field_buttons`."
"Please pass all of the strings you want to appear in your buttons to `button_field_options`."
)
end

options ||= {}
button_field_buttons ||= {}
other_options ||= {}

if defined?(html_options)
Expand All @@ -27,7 +26,7 @@ if defined?(html_options)
)
end

button_field_options = options_for(form, method) if button_field_buttons.empty?
button_field_options ||= options_for(form, method)

options[:data] ||= {}
options[:data]["#{stimulus_controller}-target"] = 'shadowField'
Expand Down
6 changes: 3 additions & 3 deletions bullet_train/docs/field-partials/buttons.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ en:
## Generate Buttons Programmatically
You can generate the available buttons using a collection of database objects by passing the `options` option like so:
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,
options: Category.all.map { |category| [category.id, category.label_string] } %>
button_field_options: Category.all.map { |category| [category.id, category.label_string] } %>
```

## Allow Multiple Button Selections
Expand All @@ -38,7 +38,7 @@ You can allow multiple buttons to be selected using the `multiple` option, like

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

## Dynamically Updating Form Fields
Expand Down

0 comments on commit 04c0081

Please sign in to comment.