Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions demo/app/models/address.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class Address < ApplicationRecord
belongs_to :user

validates :city, presence: true
end
1 change: 1 addition & 0 deletions demo/app/models/model_user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ModelUser
include ActiveModel::Model

attr_accessor :email, :password, :comments, :misc

validates :email, :password, presence: true
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/8.0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ eval File.read(gems), binding, gems # rubocop: disable Security/Eval
gem "bigdecimal" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0")
gem "drb" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0")
gem "mutex_m" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0")
gem "rails", "~> 8.0.1"
gem "propshaft"
gem "rails", "~> 8.0.1"
gem "sqlite3"
2 changes: 1 addition & 1 deletion gemfiles/edge.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ eval File.read(gems), binding, gems # rubocop: disable Security/Eval
gem "bigdecimal" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0")
gem "drb" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0")
gem "mutex_m" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0")
gem "rails", git: "https://github.com/rails/rails.git", branch: "main"
gem "propshaft"
gem "rails", git: "https://github.com/rails/rails.git", branch: "main"
gem "sqlite3"
2 changes: 1 addition & 1 deletion lib/bootstrap_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def fields_for_options(record_object, fields_options)
field_options = fields_options
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]
end
field_options[:label_col] = field_options[:label_col].present? ? field_options[:label_col].to_s : options[:label_col]
field_options
Expand Down
22 changes: 22 additions & 0 deletions test/bootstrap_fields_for_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ class BootstrapFieldsForTest < ActionView::TestCase
assert_equivalent_html expected, output
end

test "bootstrap_fields_for helper works with boolean options" do
@user.address = Address.new
@user.valid?

output = bootstrap_form_for(@user, inline_errors: true) do |_f|
bootstrap_fields_for :address, @user.address, inline_errors: false do |af|
af.text_field(:city)
end
end

expected = <<~HTML
<form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
<div class="mb-3">
<label class="form-label required" for="address_city">City</label>
<input class="form-control is-invalid" id="address_city" name="address[city]" type="text" required="required" />
<!-- No `<div class="invalid-feedback">can't be blank</div>` -->
</div>
</form>
HTML
assert_equivalent_html expected, output
end

test "bootstrap_fields_for helper works for serialized hash attributes" do
@user.preferences = { "favorite_color" => "cerulean" }

Expand Down