From d5cea0aeb5f7c86aca3ffc1327ca0536d480e9a6 Mon Sep 17 00:00:00 2001 From: Uwe Kubosch Date: Tue, 18 Apr 2017 22:19:44 +0200 Subject: [PATCH 1/2] Support :prepend and :append for the `select` helper Fixes #147 --- CHANGELOG.md | 2 ++ lib/bootstrap_form/form_builder.rb | 8 ++++++-- test/bootstrap_selects_test.rb | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83b9ebea7..9ed6f469d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index 91a4e7ae7..423360e6e 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -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 diff --git a/test/bootstrap_selects_test.rb b/test/bootstrap_selects_test.rb index 310126aae..2417f4434 100644 --- a/test/bootstrap_selects_test.rb +++ b/test/bootstrap_selects_test.rb @@ -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 +
+ +
+ Before + + After +
+
+ 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 = %{
} From 4f59f34cc2312d00a47b7b3676a2fcbc4c12e361 Mon Sep 17 00:00:00 2001 From: Uwe Kubosch Date: Mon, 24 Apr 2017 21:07:47 +0200 Subject: [PATCH 2/2] Bootstrap 4 has renamed `control-label` to `form-control-label` --- test/bootstrap_selects_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bootstrap_selects_test.rb b/test/bootstrap_selects_test.rb index 2417f4434..f934fdd4b 100644 --- a/test/bootstrap_selects_test.rb +++ b/test/bootstrap_selects_test.rb @@ -35,7 +35,7 @@ def setup test 'selects with addons are wrapped correctly' do expected = <<-HTML.strip_heredoc
- +
Before