From 1fe7500bfe372494605aab9e850976fa62b1689c Mon Sep 17 00:00:00 2001 From: Anton Pawlik Date: Tue, 18 Oct 2016 11:27:46 +0200 Subject: [PATCH 1/7] Update to Bootstrap v4 --- CHANGELOG.md | 6 +++--- README.md | 4 ++-- lib/bootstrap_form/form_builder.rb | 2 +- test/bootstrap_form_group_test.rb | 6 +++--- test/bootstrap_form_test.rb | 12 ++++++------ 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e51ef160..5ecb37e72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,10 @@ -## [Pending Release][] +## [Pending Release][] (2016-10-18) Bugfixes: - - Your contribution here! + - Change error class from `has-error` to `has-danger` Features: - - Your contribution here! + - Update to Bootstrap v4 ## [2.5.2][] (2016-10-08) diff --git a/README.md b/README.md index 1bf9ab036..319367186 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ twitter bootstrap-style forms into your rails application. * Ruby 1.9+ * Rails 4.0+ -* Twitter Bootstrap 3.0+ +* Twitter Bootstrap 4.0+ ## Installation @@ -468,7 +468,7 @@ error will be displayed below the field. Rails normally wraps the fields in a div (field_with_errors), but this behavior is suppressed. Here's an example: ```html -
+
can't be blank diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index d89c96643..fe4acfe27 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -263,7 +263,7 @@ def label_class end def error_class - "has-error" + "has-danger" end def feedback_class diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index 72b0e93c9..2cbfff6bb 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -176,7 +176,7 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

can't be blank, is too short (minimum is 5 characters)
} + expected = %{

Bar

can't be blank, is too short (minimum is 5 characters)
} assert_equal expected, output end @@ -189,7 +189,7 @@ def setup @user.email = nil @user.valid? - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
can't be blank, is too short (minimum is 5 characters)
} assert_equal expected, @builder.email_field(:email, wrapper_class: 'none-margin') end @@ -201,7 +201,7 @@ def setup f.text_field(:email, help: 'This is required', wrapper_class: 'none-margin') end - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
can't be blank, is too short (minimum is 5 characters)
} assert_equal expected, output end diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index f9485e86d..3312e88ad 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -51,7 +51,7 @@ def setup @user.email = nil @user.valid? - expected = %{
} + expected = %{
} assert_equal expected, bootstrap_form_for(@user, label_errors: true) { |f| f.text_field :email } end @@ -59,7 +59,7 @@ def setup @user.email = nil @user.valid? - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
can't be blank, is too short (minimum is 5 characters)
} assert_equal expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email } end @@ -69,7 +69,7 @@ def setup @user.email = nil @user.valid? - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
can't be blank, is too short (minimum is 5 characters)
} assert_equal expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email } I18n.backend.store_translations(:en, {activerecord: {attributes: {user: {email: nil}}}}) @@ -164,7 +164,7 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
can't be blank, is too short (minimum is 5 characters)
} assert_equal expected, output end @@ -176,7 +176,7 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
can't be blank, is too short (minimum is 5 characters)
} assert_equal expected, output end @@ -188,7 +188,7 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
This is required
} + expected = %{
This is required
} assert_equal expected, output end From f46f865d0ee9b33034420bb28e9673cbf8a3f6d5 Mon Sep 17 00:00:00 2001 From: Anton Pawlik Date: Tue, 18 Oct 2016 11:38:18 +0200 Subject: [PATCH 2/7] Change validation text class from `help-block` to `form-control-feedback` --- CHANGELOG.md | 1 + README.md | 2 +- lib/bootstrap_form/form_builder.rb | 2 +- test/bootstrap_checkbox_test.rb | 2 +- test/bootstrap_fields_test.rb | 2 +- test/bootstrap_form_group_test.rb | 12 ++++++------ test/bootstrap_form_test.rb | 10 +++++----- test/bootstrap_radio_button_test.rb | 10 +++++----- test/bootstrap_selects_test.rb | 2 +- 9 files changed, 22 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ecb37e72..99a49557b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Bugfixes: - Change error class from `has-error` to `has-danger` + - Change validation text class from `help-block` to `form-control-feedback` Features: - Update to Bootstrap v4 diff --git a/README.md b/README.md index 319367186..34d8a0c8e 100644 --- a/README.md +++ b/README.md @@ -471,7 +471,7 @@ div (field_with_errors), but this behavior is suppressed. Here's an example:
- can't be blank +
``` diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index fe4acfe27..5af6ae8a9 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -390,7 +390,7 @@ def generate_help(name, help_text) help_text ||= get_help_text_by_i18n_key(name) - content_tag(:span, help_text, class: 'help-block') if help_text.present? + content_tag(:div, help_text, class: 'form-control-feedback') if help_text.present? end def generate_icon(icon) diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb index e9ae6eab9..886e9c31c 100644 --- a/test/bootstrap_checkbox_test.rb +++ b/test/bootstrap_checkbox_test.rb @@ -54,7 +54,7 @@ def setup test 'collection_check_boxes renders the form_group correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, label: 'This is a checkbox collection', help: 'With a help!') end diff --git a/test/bootstrap_fields_test.rb b/test/bootstrap_fields_test.rb index 41d889c4b..87cf14bec 100644 --- a/test/bootstrap_fields_test.rb +++ b/test/bootstrap_fields_test.rb @@ -53,7 +53,7 @@ def setup end test "password fields are wrapped correctly" do - expected = %{
A good password should be at least six characters long
} + expected = %{
} assert_equal expected, @builder.password_field(:password) end diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index 2cbfff6bb..2baf44b69 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -77,17 +77,17 @@ def setup end test "help messages for default forms" do - expected = %{
This is required
} + expected = %{
} assert_equal expected, @builder.text_field(:email, help: 'This is required') end test "help messages for horizontal forms" do - expected = %{
This is required
} + expected = %{
} assert_equal expected, @horizontal_builder.text_field(:email, help: "This is required") end test "help messages to look up I18n automatically" do - expected = %{
A good password should be at least six characters long
} + expected = %{
} assert_equal expected, @builder.text_field(:password) end @@ -176,7 +176,7 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

can't be blank, is too short (minimum is 5 characters)
} + expected = %{

Bar

} assert_equal expected, output end @@ -189,7 +189,7 @@ def setup @user.email = nil @user.valid? - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
} assert_equal expected, @builder.email_field(:email, wrapper_class: 'none-margin') end @@ -201,7 +201,7 @@ def setup f.text_field(:email, help: 'This is required', wrapper_class: 'none-margin') end - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
} assert_equal expected, output end diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 3312e88ad..3599b93bf 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -59,7 +59,7 @@ def setup @user.email = nil @user.valid? - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
can't be blank, is too short (minimum is 5 characters)
} assert_equal expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email } end @@ -69,7 +69,7 @@ def setup @user.email = nil @user.valid? - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
can't be blank, is too short (minimum is 5 characters)
} assert_equal expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email } I18n.backend.store_translations(:en, {activerecord: {attributes: {user: {email: nil}}}}) @@ -164,7 +164,7 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
} assert_equal expected, output end @@ -176,7 +176,7 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
} assert_equal expected, output end @@ -188,7 +188,7 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
This is required
} + expected = %{
} assert_equal expected, output end diff --git a/test/bootstrap_radio_button_test.rb b/test/bootstrap_radio_button_test.rb index a1204c879..a99a9c31e 100644 --- a/test/bootstrap_radio_button_test.rb +++ b/test/bootstrap_radio_button_test.rb @@ -39,7 +39,7 @@ def setup test 'collection_radio_buttons renders the form_group correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = %{
} assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, label: 'This is a radio button collection', help: 'With a help!') end @@ -67,14 +67,14 @@ def setup test 'collection_radio_buttons renders label defined by Proc correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = %{
} assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, Proc.new { |a| a.street.reverse }, label: 'This is a radio button collection', help: 'With a help!') end test 'collection_radio_buttons renders value defined by Proc correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = %{
} assert_equal expected, @builder.collection_radio_buttons(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, label: 'This is a radio button collection', help: 'With a help!') end @@ -95,14 +95,14 @@ def setup test 'collection_radio_buttons renders label defined by lambda correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = %{
} assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, lambda { |a| a.street.reverse }, label: 'This is a radio button collection', help: 'With a help!') end test 'collection_radio_buttons renders value defined by lambda correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = %{
} assert_equal expected, @builder.collection_radio_buttons(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, label: 'This is a radio button collection', help: 'With a help!') end diff --git a/test/bootstrap_selects_test.rb b/test/bootstrap_selects_test.rb index 8812d6f2a..5f13fa832 100644 --- a/test/bootstrap_selects_test.rb +++ b/test/bootstrap_selects_test.rb @@ -18,7 +18,7 @@ def setup end test "bootstrap_specific options are handled correctly" do - expected = %{
Help!
} + expected = %{
} assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], label: "My Status Label", help: "Help!" ) end From f1c7dc5c29a4e440a905ef85324549510826d356 Mon Sep 17 00:00:00 2001 From: Anton Pawlik Date: Wed, 19 Oct 2016 13:54:04 +0200 Subject: [PATCH 3/7] Change validation text class from `form-control-feedback ` to `form-text text-muted` --- CHANGELOG.md | 1 + lib/bootstrap_form/form_builder.rb | 12 ++++++++++-- test/bootstrap_checkbox_test.rb | 2 +- test/bootstrap_fields_test.rb | 2 +- test/bootstrap_form_group_test.rb | 8 ++++---- test/bootstrap_form_test.rb | 6 +++--- test/bootstrap_radio_button_test.rb | 10 +++++----- test/bootstrap_selects_test.rb | 2 +- 8 files changed, 26 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99a49557b..151d33dfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Bugfixes: - Change error class from `has-error` to `has-danger` - Change validation text class from `help-block` to `form-control-feedback` + - Change help text class from `help-block` to `form-text text-muted` Features: - Update to Bootstrap v4 diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index 5af6ae8a9..e4f3437b2 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -201,6 +201,7 @@ def form_group(*args, &block) label = generate_label(options[:id], name, options[:label], options[:label_col], options[:layout]) if options[:label] control = capture(&block).to_s control.concat(generate_help(name, options[:help]).to_s) + # TODO create `generate_error` control.concat(generate_icon(options[:icon])) if options[:icon] if get_group_layout(options[:layout]) == :horizontal @@ -385,12 +386,19 @@ def generate_label(id, name, options, custom_label_col, group_layout) end def generate_help(name, help_text) - help_text = get_error_messages(name) if has_error?(name) && inline_errors + if is_error = has_error?(name) && inline_errors + help_text = get_error_messages(name) + end return if help_text === false help_text ||= get_help_text_by_i18n_key(name) - content_tag(:div, help_text, class: 'form-control-feedback') if help_text.present? + return if help_text.blank? + if is_error + content_tag(:div, help_text, class: 'form-control-feedback') + else + content_tag(:p, help_text, class: 'form-text text-muted') + end end def generate_icon(icon) diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb index 886e9c31c..be0c4f3d2 100644 --- a/test/bootstrap_checkbox_test.rb +++ b/test/bootstrap_checkbox_test.rb @@ -54,7 +54,7 @@ def setup test 'collection_check_boxes renders the form_group correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
} + expected = %{

With a help!

} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, label: 'This is a checkbox collection', help: 'With a help!') end diff --git a/test/bootstrap_fields_test.rb b/test/bootstrap_fields_test.rb index 87cf14bec..3820b9ce3 100644 --- a/test/bootstrap_fields_test.rb +++ b/test/bootstrap_fields_test.rb @@ -53,7 +53,7 @@ def setup end test "password fields are wrapped correctly" do - expected = %{
} + expected = %{

A good password should be at least six characters long

} assert_equal expected, @builder.password_field(:password) end diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index 2baf44b69..c0a35c1dd 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -77,17 +77,17 @@ def setup end test "help messages for default forms" do - expected = %{
} + expected = %{

This is required

} assert_equal expected, @builder.text_field(:email, help: 'This is required') end test "help messages for horizontal forms" do - expected = %{
} + expected = %{

This is required

} assert_equal expected, @horizontal_builder.text_field(:email, help: "This is required") end test "help messages to look up I18n automatically" do - expected = %{
} + expected = %{

A good password should be at least six characters long

} assert_equal expected, @builder.text_field(:password) end @@ -201,7 +201,7 @@ def setup f.text_field(:email, help: 'This is required', wrapper_class: 'none-margin') end - expected = %{
} + expected = %{
} assert_equal expected, output end diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 3599b93bf..28bdc87d4 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -59,7 +59,7 @@ def setup @user.email = nil @user.valid? - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
can't be blank, is too short (minimum is 5 characters)
} assert_equal expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email } end @@ -69,7 +69,7 @@ def setup @user.email = nil @user.valid? - expected = %{
can't be blank, is too short (minimum is 5 characters)
} + expected = %{
can't be blank, is too short (minimum is 5 characters)
} assert_equal expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email } I18n.backend.store_translations(:en, {activerecord: {attributes: {user: {email: nil}}}}) @@ -188,7 +188,7 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
} + expected = %{

This is required

} assert_equal expected, output end diff --git a/test/bootstrap_radio_button_test.rb b/test/bootstrap_radio_button_test.rb index a99a9c31e..2158649c0 100644 --- a/test/bootstrap_radio_button_test.rb +++ b/test/bootstrap_radio_button_test.rb @@ -39,7 +39,7 @@ def setup test 'collection_radio_buttons renders the form_group correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
} + expected = %{

With a help!

} assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, label: 'This is a radio button collection', help: 'With a help!') end @@ -67,14 +67,14 @@ def setup test 'collection_radio_buttons renders label defined by Proc correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
} + expected = %{

With a help!

} assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, Proc.new { |a| a.street.reverse }, label: 'This is a radio button collection', help: 'With a help!') end test 'collection_radio_buttons renders value defined by Proc correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
} + expected = %{

With a help!

} assert_equal expected, @builder.collection_radio_buttons(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, label: 'This is a radio button collection', help: 'With a help!') end @@ -95,14 +95,14 @@ def setup test 'collection_radio_buttons renders label defined by lambda correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
} + expected = %{

With a help!

} assert_equal expected, @builder.collection_radio_buttons(:misc, collection, :id, lambda { |a| a.street.reverse }, label: 'This is a radio button collection', help: 'With a help!') end test 'collection_radio_buttons renders value defined by lambda correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
} + expected = %{

With a help!

} assert_equal expected, @builder.collection_radio_buttons(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, label: 'This is a radio button collection', help: 'With a help!') end diff --git a/test/bootstrap_selects_test.rb b/test/bootstrap_selects_test.rb index 5f13fa832..84b207560 100644 --- a/test/bootstrap_selects_test.rb +++ b/test/bootstrap_selects_test.rb @@ -18,7 +18,7 @@ def setup end test "bootstrap_specific options are handled correctly" do - expected = %{
} + expected = %{

Help!

} assert_equal expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], label: "My Status Label", help: "Help!" ) end From 34ee2d9a01cb06be0426109a4f81db82e491b26a Mon Sep 17 00:00:00 2001 From: Jonathon Padfield Date: Thu, 27 Oct 2016 14:01:31 +0800 Subject: [PATCH 4/7] Switched wrapper classes for checkboxes from "checkbox" to "form-check" for Boostrap v4 --- lib/bootstrap_form/form_builder.rb | 4 +-- test/bootstrap_checkbox_test.rb | 42 +++++++++++++++--------------- test/bootstrap_form_test.rb | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index e4f3437b2..1a7f5426b 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -130,9 +130,9 @@ def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_ if options[:inline] label_class = " #{label_class}" if label_class - label(label_name, html, class: "checkbox-inline#{disabled_class}#{label_class}") + label(label_name, html, class: "form-check-inline#{disabled_class}#{label_class}") else - content_tag(:div, class: "checkbox#{disabled_class}") do + content_tag(:div, class: "form-check#{disabled_class}") do label(label_name, html, class: label_class) end end diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb index be0c4f3d2..52f0aead7 100644 --- a/test/bootstrap_checkbox_test.rb +++ b/test/bootstrap_checkbox_test.rb @@ -8,74 +8,74 @@ def setup end test "check_box is wrapped correctly" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms') end test "disabled check_box has proper wrapper classes" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms', disabled: true) end test "check_box label allows html" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, label: %{I agree to the terms}.html_safe) end test "check_box accepts a block to define the label" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms) { "I agree to the terms" } end test "check_box accepts a custom label class" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, label_class: 'btn') end test "check_box responds to checked_value and unchecked_value arguments" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, {label: 'I agree to the terms'}, 'yes', 'no') end test "inline checkboxes" do - expected = %{} + expected = %{} assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true) end test "disabled inline check_box" do - expected = %{} + expected = %{} assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true, disabled: true) end test "inline checkboxes with custom label class" do - expected = %{} + expected = %{} assert_equal expected, @builder.check_box(:terms, inline: true, label_class: 'btn') end test 'collection_check_boxes renders the form_group correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{

With a help!

} + expected = %{

With a help!

} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, label: 'This is a checkbox collection', help: 'With a help!') end test 'collection_check_boxes renders multiple checkboxes correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street) end test 'collection_check_boxes renders inline checkboxes correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, inline: true) end test 'collection_check_boxes renders with checked option correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: 1) assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: collection.first) @@ -83,7 +83,7 @@ def setup test 'collection_check_boxes renders with multiple checked options correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: [1, 2]) assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: collection) @@ -91,42 +91,42 @@ def setup test 'collection_check_boxes sanitizes values when generating label `for`' do collection = [Address.new(id: 1, street: 'Foo St')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :street, :street) end test 'collection_check_boxes renders multiple checkboxes with labels defined by Proc :text_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, Proc.new { |a| a.street.reverse }) end test 'collection_check_boxes renders multiple checkboxes with values defined by Proc :value_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street) end test 'collection_check_boxes renders multiple checkboxes with labels defined by lambda :text_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, lambda { |a| a.street.reverse }) end test 'collection_check_boxes renders multiple checkboxes with values defined by lambda :value_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street) end test 'collection_check_boxes renders with checked option correctly with Proc :value_method' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, checked: "address_1") assert_equal expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, checked: collection.first) @@ -134,7 +134,7 @@ def setup test 'collection_check_boxes renders with multiple checked options correctly with lambda :value_method' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: ["address_1", "address_2"]) assert_equal expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: collection) diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 28bdc87d4..e2e78fa2c 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -43,7 +43,7 @@ def setup end test "bootstrap_form_tag allows an empty name for checkboxes" do - expected = %{
} + expected = %{
} assert_equal expected, bootstrap_form_tag(url: '/users') { |f| f.check_box :misc } end From 98a613125c01e80e8c75f0db5f07ebc2166c6863 Mon Sep 17 00:00:00 2001 From: Jonathon Padfield Date: Thu, 27 Oct 2016 14:31:56 +0800 Subject: [PATCH 5/7] Added form-check-input class to input types of 'checkbox' type for Boostrap v4 --- lib/bootstrap_form/form_builder.rb | 1 + test/bootstrap_checkbox_test.rb | 42 +++++++++++++++--------------- test/bootstrap_form_test.rb | 2 +- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index 1a7f5426b..1da97c70e 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -111,6 +111,7 @@ def time_zone_select_with_bootstrap(method, priority_zones = nil, options = {}, def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_value = "0", &block) options = options.symbolize_keys! check_box_options = options.except(:label, :label_class, :help, :inline) + check_box_options[:class] = ["form-check-input", check_box_options[:class]].compact.join(' ') html = check_box_without_bootstrap(name, check_box_options, checked_value, unchecked_value) label_content = block_given? ? capture(&block) : options[:label] diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb index 52f0aead7..eaf1be0e8 100644 --- a/test/bootstrap_checkbox_test.rb +++ b/test/bootstrap_checkbox_test.rb @@ -8,74 +8,74 @@ def setup end test "check_box is wrapped correctly" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms') end test "disabled check_box has proper wrapper classes" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms', disabled: true) end test "check_box label allows html" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, label: %{I agree to the terms}.html_safe) end test "check_box accepts a block to define the label" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms) { "I agree to the terms" } end test "check_box accepts a custom label class" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, label_class: 'btn') end test "check_box responds to checked_value and unchecked_value arguments" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, {label: 'I agree to the terms'}, 'yes', 'no') end test "inline checkboxes" do - expected = %{} + expected = %{} assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true) end test "disabled inline check_box" do - expected = %{} + expected = %{} assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms', inline: true, disabled: true) end test "inline checkboxes with custom label class" do - expected = %{} + expected = %{} assert_equal expected, @builder.check_box(:terms, inline: true, label_class: 'btn') end test 'collection_check_boxes renders the form_group correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{

With a help!

} + expected = %{

With a help!

} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, label: 'This is a checkbox collection', help: 'With a help!') end test 'collection_check_boxes renders multiple checkboxes correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street) end test 'collection_check_boxes renders inline checkboxes correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, inline: true) end test 'collection_check_boxes renders with checked option correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: 1) assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: collection.first) @@ -83,7 +83,7 @@ def setup test 'collection_check_boxes renders with multiple checked options correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: [1, 2]) assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: collection) @@ -91,42 +91,42 @@ def setup test 'collection_check_boxes sanitizes values when generating label `for`' do collection = [Address.new(id: 1, street: 'Foo St')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :street, :street) end test 'collection_check_boxes renders multiple checkboxes with labels defined by Proc :text_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, Proc.new { |a| a.street.reverse }) end test 'collection_check_boxes renders multiple checkboxes with values defined by Proc :value_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street) end test 'collection_check_boxes renders multiple checkboxes with labels defined by lambda :text_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, lambda { |a| a.street.reverse }) end test 'collection_check_boxes renders multiple checkboxes with values defined by lambda :value_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street) end test 'collection_check_boxes renders with checked option correctly with Proc :value_method' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, checked: "address_1") assert_equal expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, checked: collection.first) @@ -134,7 +134,7 @@ def setup test 'collection_check_boxes renders with multiple checked options correctly with lambda :value_method' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: ["address_1", "address_2"]) assert_equal expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: collection) diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index e2e78fa2c..1fd2a7b5a 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -43,7 +43,7 @@ def setup end test "bootstrap_form_tag allows an empty name for checkboxes" do - expected = %{
} + expected = %{
} assert_equal expected, bootstrap_form_tag(url: '/users') { |f| f.check_box :misc } end From b7a1921753ffbe8ad3ed3087090b15be0ab523b7 Mon Sep 17 00:00:00 2001 From: Jonathon Padfield Date: Thu, 27 Oct 2016 15:50:50 +0800 Subject: [PATCH 6/7] Added form-check-label to form-labels, but not to inline-form-label's because they're not supported yet. Bootstrap v4 fixes. --- lib/bootstrap_form/form_builder.rb | 4 ++-- test/bootstrap_checkbox_test.rb | 34 +++++++++++++++--------------- test/bootstrap_form_test.rb | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index 1da97c70e..77d50e7c7 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -127,12 +127,12 @@ def check_box_with_bootstrap(name, options = {}, checked_value = "1", unchecked_ end disabled_class = " disabled" if options[:disabled] - label_class = options[:label_class] if options[:inline] - label_class = " #{label_class}" if label_class + label_class = " #{options[:label_class]}" if options[:label_class] label(label_name, html, class: "form-check-inline#{disabled_class}#{label_class}") else + label_class = ["form-check-label", options[:label_class]].compact.join(' ') content_tag(:div, class: "form-check#{disabled_class}") do label(label_name, html, class: label_class) end diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb index eaf1be0e8..64093947f 100644 --- a/test/bootstrap_checkbox_test.rb +++ b/test/bootstrap_checkbox_test.rb @@ -8,32 +8,32 @@ def setup end test "check_box is wrapped correctly" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms') end test "disabled check_box has proper wrapper classes" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, label: 'I agree to the terms', disabled: true) end test "check_box label allows html" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, label: %{I agree to the terms}.html_safe) end test "check_box accepts a block to define the label" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms) { "I agree to the terms" } end test "check_box accepts a custom label class" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, label_class: 'btn') end test "check_box responds to checked_value and unchecked_value arguments" do - expected = %{
} + expected = %{
} assert_equal expected, @builder.check_box(:terms, {label: 'I agree to the terms'}, 'yes', 'no') end @@ -54,14 +54,14 @@ def setup test 'collection_check_boxes renders the form_group correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{

With a help!

} + expected = %{

With a help!

} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, label: 'This is a checkbox collection', help: 'With a help!') end test 'collection_check_boxes renders multiple checkboxes correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street) end @@ -75,7 +75,7 @@ def setup test 'collection_check_boxes renders with checked option correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: 1) assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: collection.first) @@ -83,7 +83,7 @@ def setup test 'collection_check_boxes renders with multiple checked options correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: [1, 2]) assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: collection) @@ -91,42 +91,42 @@ def setup test 'collection_check_boxes sanitizes values when generating label `for`' do collection = [Address.new(id: 1, street: 'Foo St')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :street, :street) end test 'collection_check_boxes renders multiple checkboxes with labels defined by Proc :text_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, Proc.new { |a| a.street.reverse }) end test 'collection_check_boxes renders multiple checkboxes with values defined by Proc :value_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street) end test 'collection_check_boxes renders multiple checkboxes with labels defined by lambda :text_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, :id, lambda { |a| a.street.reverse }) end test 'collection_check_boxes renders multiple checkboxes with values defined by lambda :value_method correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street) end test 'collection_check_boxes renders with checked option correctly with Proc :value_method' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, checked: "address_1") assert_equal expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, checked: collection.first) @@ -134,7 +134,7 @@ def setup test 'collection_check_boxes renders with multiple checked options correctly with lambda :value_method' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equal expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: ["address_1", "address_2"]) assert_equal expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: collection) diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 1fd2a7b5a..6ecc3c44b 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -43,7 +43,7 @@ def setup end test "bootstrap_form_tag allows an empty name for checkboxes" do - expected = %{
} + expected = %{
} assert_equal expected, bootstrap_form_tag(url: '/users') { |f| f.check_box :misc } end From cc9db72ad66c2926f7f9a025b926e8c1e85c6d46 Mon Sep 17 00:00:00 2001 From: Jonathon Padfield Date: Thu, 27 Oct 2016 15:56:03 +0800 Subject: [PATCH 7/7] Updated CHANGELOG.md to include info about checkboxes for Bootstrap v4 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 151d33dfe..963654c14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Bugfixes: - Change error class from `has-error` to `has-danger` - Change validation text class from `help-block` to `form-control-feedback` - Change help text class from `help-block` to `form-text text-muted` + - Change checkbox classes from `checkbox` to `form-check` and added `form-check-label` to labels Features: - Update to Bootstrap v4