Skip to content

wrapper_class: false #758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 1 addition & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ Layout/SpaceAroundEqualsInParameterDefault:

Metrics/AbcSize:
Max: 18
Exclude:
- "demo/test/**/*"
- "test/**/*"
Enabled: false

Metrics/BlockLength:
Exclude:
Expand Down
94 changes: 54 additions & 40 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions demo/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class User < ApplicationRecord

serialize :preferences, coder: JSON

validates :email, presence: true, length: { minimum: 5 }, if: :always
validates :email, presence: true, length: { minimum: 5 }, if: :always?
validates :terms, acceptance: { accept: true }

# Conditional (always disabled) validators used in tests
Expand All @@ -15,7 +15,7 @@ class User < ApplicationRecord

has_rich_text(:life_story)

def always # rubocop:disable Naming/PredicateMethod
def always?
true
end

Expand Down
Binary file modified demo/doc/screenshots/bootstrap/readme/16_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/17_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/18_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/19_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/20_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/21_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/22_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/23_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/24_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/25_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/26_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/27_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/28_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/29_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/31_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/32_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/33_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/34_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/35_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/36_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/37_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/38_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/39_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/40_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/41_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/doc/screenshots/bootstrap/readme/42_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/43_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/44_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/45_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/46_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/47_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/48_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/49_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/50_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/51_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/52_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/53_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/54_example.png
Binary file modified demo/doc/screenshots/bootstrap/readme/55_example.png
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"
1 change: 0 additions & 1 deletion lib/bootstrap_form/components/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def generate_error(name)
content_tag(help_tag, help_text, class: help_klass)
end

# rubocop:disable Metrics/AbcSize
def get_error_messages(name)
object.class.try(:reflections)&.each do |association_name, a|
next unless a.is_a?(ActiveRecord::Reflection::BelongsToReflection)
Expand Down
2 changes: 1 addition & 1 deletion lib/bootstrap_form/form_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def form_group_content_tag(name, field_name, without_field_name, options, html_o
end
end

def form_group_content(label, help_text, options, &) # rubocop:disable Metrics/AbcSize
def form_group_content(label, help_text, options, &)
label ||= ActiveSupport::SafeBuffer.new
if group_layout_horizontal?(options[:layout])
label + tag.div(capture(&) + help_text, class: form_group_control_class(options))
Expand Down
5 changes: 4 additions & 1 deletion lib/bootstrap_form/inputs/check_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def check_box_label_class(options)
def check_box_wrapper_class(options)
classes = ["form-check"]
classes << "form-check-inline" if layout_inline?(options[:inline])
classes << "mb-3" unless options[:multiple] || %i[horizontal inline].include?(layout)
classes << "mb-3" unless options[:multiple] ||
%i[horizontal inline].include?(layout) ||
options[:wrapper_class] == false ||
options.dig(:wrapper, :class) == false
classes << "form-switch" if options[:switch]
classes << options.dig(:wrapper, :class).presence
classes << options[:wrapper_class].presence
Expand Down
14 changes: 14 additions & 0 deletions test/bootstrap_checkbox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,20 @@ class BootstrapCheckboxTest < ActionView::TestCase
assert_equivalent_html expected, @builder.check_box(:terms, label: "I agree to the terms", wrapper_class: "custom-class")
end

test "check box with custom wrapper class false" do
expected = <<~HTML
<div class="form-check">
<input #{autocomplete_attr} name="user[terms]" type="hidden" value="0" />
<input class="form-check-input" id="user_terms" name="user[terms]" type="checkbox" value="1" />
<label class="form-check-label" for="user_terms">
I agree to the terms
</label>
</div>
HTML
assert_equivalent_html expected, @builder.check_box(:terms, label: "I agree to the terms", wrapper_class: false)
assert_equivalent_html expected, @builder.check_box(:terms, label: "I agree to the terms", wrapper: { class: false })
end

test "inline check box with custom wrapper class" do
expected = <<~HTML
<div class="form-check form-check-inline mb-3 custom-class">
Expand Down
22 changes: 22 additions & 0 deletions test/bootstrap_fields_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,28 @@ class BootstrapFieldsTest < ActionView::TestCase
assert_equivalent_html expected, @builder.text_field(:email)
end

test "text fields are wrapped correctly with wrapper_class and wrapper: { class: 'custom-class' }" do
expected = <<~HTML
<div class="custom-class">
<label class="form-label required" for="user_email">Email</label>
<input required="required" class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" />
</div>
HTML
assert_equivalent_html expected, @builder.text_field(:email, wrapper_class: "custom-class")
assert_equivalent_html expected, @builder.text_field(:email, wrapper: { class: "custom-class" })
end

test "text fields are wrapped correctly with wrapper_class false" do
expected = <<~HTML
<div>
<label class="form-label required" for="user_email">Email</label>
<input required="required" class="form-control" id="user_email" name="user[email]" type="text" value="steve@example.com" />
</div>
HTML
assert_equivalent_html expected, @builder.text_field(:email, wrapper_class: false)
assert_equivalent_html expected, @builder.text_field(:email, wrapper: { class: false })
end

test "text fields are wrapped correctly when horizontal and gutter classes are given" do
expected = <<~HTML
<div class="mb-3 g-3">
Expand Down
15 changes: 15 additions & 0 deletions test/bootstrap_radio_button_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,21 @@ class BootstrapRadioButtonTest < ActionView::TestCase
@builder.radio_button(:misc, "1", label: "This is a radio button", wrapper_class: "custom-class")
end

test "radio button with wrapper class false" do
expected = <<~HTML
<div class="form-check">
<input class="form-check-input" id="user_misc_1" name="user[misc]" type="radio" value="1" />
<label class="form-check-label" for="user_misc_1">
This is a radio button
</label>
</div>
HTML
assert_equivalent_html expected,
@builder.radio_button(:misc, "1", label: "This is a radio button", wrapper_class: false)
assert_equivalent_html expected,
@builder.radio_button(:misc, "1", label: "This is a radio button", wrapper: { class: false })
end

test "inline radio button with custom wrapper class" do
expected = <<~HTML
<div class="form-check form-check-inline custom-class">
Expand Down
Loading