diff --git a/demo/app/views/bootstrap/form.html.erb b/demo/app/views/bootstrap/form.html.erb index 105e462e..bbcdf76e 100644 --- a/demo/app/views/bootstrap/form.html.erb +++ b/demo/app/views/bootstrap/form.html.erb @@ -5,9 +5,9 @@ <%= form.email_field :email, placeholder: "Enter Email", label: "Email address", help: "We'll never share your email with anyone else" %> <%= form.password_field :password, placeholder: "Password" %> <%= form.select :status, [['activated', 1], ['blocked', 2]], prompt: "Please Select" %> - <%= form.text_area :comments %> - <%= form.check_box :terms, label: "Agree to Terms" %> - <%= form.collection_check_boxes :checkboxes, @collection, :id, :street %> + <%= form.textarea :comments %> + <%= form.checkbox :terms, label: "Agree to Terms" %> + <%= form.collection_checkboxes :checkboxes, @collection, :id, :street %> <%= form.collection_radio_buttons :radio_buttons, @collection, :id, :street %> <%= form.file_field :file %> <%= form.datetime_select :created_at, include_blank: true %> @@ -23,7 +23,7 @@ <%= form.alert_message "This is an alert" %> <%= form.error_summary %> <%= form.email_field :email, placeholder: "Enter Email", label: "Email address", help: "We'll never share your email with anyone else" %> - <%= form.collection_check_boxes :misc, @collection, :id, :street %> + <%= form.collection_checkboxes :misc, @collection, :id, :street %> <%= form.submit %> <% end %> <% end %> @@ -34,8 +34,8 @@ <%= bootstrap_form_for @user, layout: :inline do |form| %> <%= form.email_field :email, placeholder: "Enter Email", label: "Email address", help: "We'll never share your email with anyone else" %> <%= form.password_field :password, placeholder: "Password" %> - <%= form.check_box :terms, label: "Agree to Terms" %> - <%= form.collection_check_boxes :misc, @collection, :id, :street %> + <%= form.checkbox :terms, label: "Agree to Terms" %> + <%= form.collection_checkboxes :misc, @collection, :id, :street %> <%= form.submit %> <% end %> <% end %> @@ -46,9 +46,9 @@ <%= bootstrap_form_for @user, url: "/" do |form| %> <%= form.email_field :email, placeholder: "Enter Email", label: "Email address", help: "We'll never share your email with anyone else" %> <%= form.password_field :password, placeholder: "Password" %> - <%= form.check_box :terms, label: "Agree to Terms" %> - <%= form.collection_check_boxes :misc, @collection, :id, :street %> - <%= form.rich_text_area(:life_story) %> + <%= form.checkbox :terms, label: "Agree to Terms" %> + <%= form.collection_checkboxes :misc, @collection, :id, :street %> + <%= form.rich_textarea(:life_story) %> <%= form.submit %> <% end %> <% end %> @@ -60,7 +60,7 @@ <%= form.email_field :email, placeholder: "Enter Email", label: "Email address", help: "We'll never share your email with anyone else", floating: true %> <%= form.password_field :password, placeholder: "Password", floating: true %> <%= form.text_field :misc, floating: true %> - <%= form.text_area :comments, floating: true %> + <%= form.textarea :comments, floating: true %> <%= form.select :status, [["Active", 1], ["Inactive", 2]], include_blank: "Select a value", floating: true %> <%= form.submit %> <% end %> diff --git a/lib/bootstrap_form/inputs/check_box.rb b/lib/bootstrap_form/inputs/check_box.rb index 3c44ec6c..d7b50206 100644 --- a/lib/bootstrap_form/inputs/check_box.rb +++ b/lib/bootstrap_form/inputs/check_box.rb @@ -20,6 +20,8 @@ def check_box_with_bootstrap(name, options={}, checked_value="1", unchecked_valu end bootstrap_alias :check_box + alias_method :checkbox_with_bootstrap, :check_box_with_bootstrap if Rails::VERSION::MAJOR >= 8 + bootstrap_alias :checkbox if Rails::VERSION::MAJOR >= 8 end private diff --git a/lib/bootstrap_form/inputs/collection_check_boxes.rb b/lib/bootstrap_form/inputs/collection_check_boxes.rb index 65991186..6b18edb7 100644 --- a/lib/bootstrap_form/inputs/collection_check_boxes.rb +++ b/lib/bootstrap_form/inputs/collection_check_boxes.rb @@ -7,7 +7,7 @@ module CollectionCheckBoxes include Base include InputsCollection - included do # rubocop:disable Metrics/BlockLength + included do def collection_check_boxes_with_bootstrap(*args) html = inputs_collection(*args) do |name, value, options| options[:multiple] = true @@ -21,27 +21,8 @@ def collection_check_boxes_with_bootstrap(*args) end bootstrap_alias :collection_check_boxes - - if Rails::VERSION::MAJOR < 7 - def field_name(method, *methods, multiple: false, index: @options[:index]) - object_name = @options.fetch(:as) { @object_name } - - field_name_shim(object_name, method, *methods, index: index, multiple: multiple) - end - - private - - def field_name_shim(object_name, method_name, *method_names, multiple: false, index: nil) - names = method_names.map! { |name| "[#{name}]" }.join - if object_name.blank? - "#{method_name}#{names}#{'[]' if multiple}" - elsif index - "#{object_name}[#{index}][#{method_name}]#{names}#{'[]' if multiple}" - else - "#{object_name}[#{method_name}]#{names}#{'[]' if multiple}" - end - end - end + alias_method :collection_checkboxes_with_bootstrap, :collection_check_boxes_with_bootstrap if Rails::VERSION::MAJOR >= 8 + bootstrap_alias :collection_checkboxes if Rails::VERSION::MAJOR >= 8 end end end diff --git a/lib/bootstrap_form/inputs/rich_text_area.rb b/lib/bootstrap_form/inputs/rich_text_area.rb index 7a72da3e..c7fd5da0 100644 --- a/lib/bootstrap_form/inputs/rich_text_area.rb +++ b/lib/bootstrap_form/inputs/rich_text_area.rb @@ -17,6 +17,8 @@ def rich_text_area_with_bootstrap(name, options={}) end bootstrap_alias :rich_text_area + alias_method :rich_textarea, :rich_text_area if Rails::VERSION::MAJOR >= 8 + bootstrap_alias :rich_textarea if Rails::VERSION::MAJOR >= 8 end end end diff --git a/lib/bootstrap_form/inputs/text_area.rb b/lib/bootstrap_form/inputs/text_area.rb index 3586928b..9fee1edf 100644 --- a/lib/bootstrap_form/inputs/text_area.rb +++ b/lib/bootstrap_form/inputs/text_area.rb @@ -8,6 +8,8 @@ module TextArea included do bootstrap_field :text_area + alias_method :textarea_with_bootstrap, :text_area_with_bootstrap if Rails::VERSION::MAJOR >= 8 + bootstrap_field :textarea if Rails::VERSION::MAJOR >= 8 end end end diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb index 6fdfd454..9c9063e6 100644 --- a/test/bootstrap_checkbox_test.rb +++ b/test/bootstrap_checkbox_test.rb @@ -184,6 +184,26 @@ class BootstrapCheckboxTest < ActionView::TestCase label: "This is a checkbox collection", help: "With a help!") end + if Rails::VERSION::MAJOR >= 8 + test "collection_checkboxes renders the form_group correctly" do + collection = [Address.new(id: 1, street: "Foobar")] + expected = <<~HTML + +
+ +
+ + +
+ With a help! +
+ HTML + + assert_equivalent_html expected, @builder.collection_checkboxes(:misc, collection, :id, :street, + label: "This is a checkbox collection", help: "With a help!") + end + end + test "collection_check_boxes renders multiple checkboxes correctly" do collection = [Address.new(id: 1, street: "Foo"), Address.new(id: 2, street: "Bar")] expected = <<~HTML @@ -680,4 +700,19 @@ class BootstrapCheckboxTest < ActionView::TestCase HTML assert_equivalent_html expected, @builder.check_box(:misc) end + + if Rails::VERSION::MAJOR >= 8 + test "checkbox alias works" do + expected = <<~HTML +
+ + + +
+ HTML + assert_equivalent_html expected, @builder.checkbox(:terms, label: "I agree to the terms", extra: "extra arg") + end + end end diff --git a/test/bootstrap_fields_test.rb b/test/bootstrap_fields_test.rb index 8d39d9d7..d023bd42 100644 --- a/test/bootstrap_fields_test.rb +++ b/test/bootstrap_fields_test.rb @@ -213,6 +213,18 @@ class BootstrapFieldsTest < ActionView::TestCase assert_equivalent_html expected, @builder.text_area(:comments) end + if Rails::VERSION::MAJOR >= 8 + test "text areas are aliased" do + expected = <<~HTML +
+ + +
+ HTML + assert_equivalent_html expected, @builder.textarea(:comments) + end + end + test "text areas are wrapped correctly using form_with" do expected = <<~HTML
diff --git a/test/bootstrap_rich_text_area_test.rb b/test/bootstrap_rich_text_area_test.rb index 949a04ac..79888f6e 100644 --- a/test/bootstrap_rich_text_area_test.rb +++ b/test/bootstrap_rich_text_area_test.rb @@ -21,6 +21,22 @@ class BootstrapRichTextAreaTest < ActionView::TestCase assert_equivalent_html expected, form_with_builder.rich_text_area(:life_story, extra: "extra arg") end + if Rails::VERSION::MAJOR >= 8 + test "rich text areas are aliased" do + expected = nil + with_stub_token do + expected = <<~HTML +
+ + + +
+ HTML + end + assert_equivalent_html expected, form_with_builder.rich_textarea(:life_story, extra: "extra arg") + end + end + def data_blob_url_template "http://test.host/rails/active_storage/blobs/redirect/:signed_id/:filename" end