Skip to content

Conversation

@pienkowb
Copy link
Contributor

@pienkowb pienkowb commented Oct 4, 2025

This PR fixes how boolean options (e.g. inline_errors) are handled in the fields_for helper.

Currently, option defaults are loaded in the helper using the following code:

%i[layout control_col inline_errors label_errors].each do |option|
  field_options[option] ||= options[option]
end

This approach doesn't work for boolean options, because false evalues as falsy, even though it's a legitimate value. As a result, the option value is being overriden with a default value.

For example, the code below does not work as indended (inline errors are still added to the City field):

bootstrap_form_for @user, inline_errors: true do |f|
  f.fields_for :address, inline_errors: false do |af|
    af.text_field :city
  end
end

In order to fix this, I changed:

field_options[option] ||= options[option]

to:

field_options[option] = field_options.key?(option) ? field_options[option] : options[option]

which is more verbose, but works corrently for boolean options.

Copy link
Contributor

@lcreid lcreid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent catch! Thanks for the PR!

field_options = record_object if record_object.is_a?(Hash) && record_object.extractable_options?
%i[layout control_col inline_errors label_errors].each do |option|
field_options[option] ||= options[option]
field_options[option] = field_options.key?(option) ? field_options[option] : options[option]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@lcreid lcreid merged commit 00d072a into bootstrap-ruby:main Oct 24, 2025
14 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants