Skip to content

Commit

Permalink
Add support for append and prepend on collection_select (fixes bootst…
Browse files Browse the repository at this point in the history
  • Loading branch information
judylovesruby committed May 13, 2022
1 parent 595a74b commit 92505b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/bootstrap_form/inputs/collection_select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module CollectionSelect
def collection_select_with_bootstrap(method, collection, value_method, text_method, options={}, html_options={})
html_options = html_options.reverse_merge(control_class: "form-select")
form_group_builder(method, options, html_options) do
input_with_error(method) do
prepend_and_append_input(method, options) do
collection_select_without_bootstrap(method, collection, value_method, text_method, options, html_options)
end
end
Expand Down
18 changes: 18 additions & 0 deletions test/bootstrap_selects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,24 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
@builder.collection_select(:status, [], :id, :name, { prompt: "Please Select" }, class: "my-select")
end

test "collection_selects with addons are wrapped correctly" do
expected = <<~HTML
<div class="mb-3">
<label class="form-label" for="user_status">Status</label>
<div class="input-group">
<span class="input-group-text">Before</span>
<select class="form-select" id="user_status" name="user[status]">
<option value="">Please Select</option>
</select>
<span class="input-group-text">After</span>
</div>
</div>
HTML
assert_equivalent_xml expected,
@builder.collection_select(:status, [], :id, :name,
{ prepend: "Before", append: "After", prompt: "Please Select" })
end

test "grouped_collection_selects are wrapped correctly" do
expected = <<~HTML
<div class="mb-3">
Expand Down

0 comments on commit 92505b5

Please sign in to comment.