Skip to content

Commit

Permalink
Add support for append and prepend on grouped_collection_select (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
judylovesruby committed May 15, 2022
1 parent 92505b5 commit 05b9947
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/grouped_collection_select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def grouped_collection_select_with_bootstrap(method, collection, group_method,
option_value_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
grouped_collection_select_without_bootstrap(method, collection, group_method,
group_label_method, option_key_method,
option_value_method, options, html_options)
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 @@ -311,6 +311,24 @@ def options_range(start: 1, stop: 31, selected: nil, months: false)
class: "my-select")
end

test "grouped_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.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s,
{ prepend: "Before", append: "After", prompt: "Please Select" })
end

test "date selects are wrapped correctly" do
travel_to(Time.utc(2012, 2, 3)) do
expected = <<~HTML
Expand Down

0 comments on commit 05b9947

Please sign in to comment.