Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Bugfixes:

Features:
- Your contribution here!
* [#325](https://github.com/bootstrap-ruby/rails-bootstrap-forms/pull/325): Support :prepend and :append for the `select` helper - [@donv](https://github.com/donv).


## [2.6.0][] (2017-02-03)

Expand Down
8 changes: 6 additions & 2 deletions lib/bootstrap_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ def file_field_with_bootstrap(name, options = {})
if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("4.1.0")
def select_with_bootstrap(method, choices = nil, options = {}, html_options = {}, &block)
form_group_builder(method, options, html_options) do
select_without_bootstrap(method, choices, options, html_options, &block)
prepend_and_append_input(options) do
select_without_bootstrap(method, choices, options, html_options, &block)
end
end
end
else
def select_with_bootstrap(method, choices, options = {}, html_options = {})
form_group_builder(method, options, html_options) do
select_without_bootstrap(method, choices, options, html_options)
prepend_and_append_input(options) do
select_without_bootstrap(method, choices, options, html_options)
end
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions test/bootstrap_selects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ def setup
assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], { prompt: "Please Select" }, class: "my-select")
end

test 'selects with addons are wrapped correctly' do
expected = <<-HTML.strip_heredoc
<div class="form-group">
<label class="form-control-label" for="user_status">Status</label>
<div class="input-group">
<span class="input-group-addon">Before</span>
<select class="form-control" id="user_status" name="user[status]">
<option value="1">activated</option>
<option value="2">blocked</option>
</select>
<span class="input-group-addon">After</span>
</div>
</div>
HTML
assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], prepend: 'Before', append: 'After')
end

if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("4.1.0")
test "selects with block use block as content" do
expected = %{<div class="form-group"><label class="form-control-label" for="user_status">Status</label><select class="form-control" name="user[status]" id="user_status"><option>Option 1</option><option>Option 2</option></select></div>}
Expand Down