Skip to content

Commit

Permalink
Draft: Is this what we meant? (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcreid authored Feb 28, 2024
1 parent c26ec98 commit ba6f19a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
17 changes: 15 additions & 2 deletions lib/bootstrap_form/inputs/collection_check_boxes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module CollectionCheckBoxes
include Base
include InputsCollection

included do
included do # rubocop:disable Metrics/BlockLength
def collection_check_boxes_with_bootstrap(*args)
html = inputs_collection(*args) do |name, value, options|
options[:multiple] = true
Expand All @@ -26,7 +26,20 @@ def collection_check_boxes_with_bootstrap(*args)
def field_name(method, *methods, multiple: false, index: @options[:index])
object_name = @options.fetch(:as) { @object_name }

@template.field_name(object_name, method, *methods, index: index, multiple: multiple)
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}#{multiple ? '[]' : ''}"
elsif index
"#{object_name}[#{index}][#{method_name}]#{names}#{multiple ? '[]' : ''}"
else
"#{object_name}[#{method_name}]#{names}#{multiple ? '[]' : ''}"
end
end
end
end
Expand Down
13 changes: 0 additions & 13 deletions test/bootstrap_checkbox_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,19 +473,6 @@ class BootstrapCheckboxTest < ActionView::TestCase
:street, checked: collection)
end

if Rails::VERSION::MAJOR < 7
def field_name(object_name, method_name, *method_names, multiple: false, index: nil)
names = method_names.map! { |name| "[#{name}]" }.join
if object_name.blank?
"#{method_name}#{names}#{multiple ? '[]' : ''}"
elsif index
"#{object_name}[#{index}][#{method_name}]#{names}#{multiple ? '[]' : ''}"
else
"#{object_name}[#{method_name}]#{names}#{multiple ? '[]' : ''}"
end
end
end

test "collection_check_boxes renders with include_hidden options correctly" do
collection = [Address.new(id: 1, street: "Foo"), Address.new(id: 2, street: "Bar")]
expected = <<~HTML
Expand Down

0 comments on commit ba6f19a

Please sign in to comment.