From 4255abb344fce887f83bf6a465ec23a70746317f Mon Sep 17 00:00:00 2001 From: Zulfiqar Ali Date: Mon, 7 Nov 2016 20:44:06 -0500 Subject: [PATCH 01/11] has-error is now has-danger --- README.md | 2 +- lib/bootstrap_form/form_builder.rb | 2 +- test/bootstrap_form_group_test.rb | 6 +++--- test/bootstrap_form_test.rb | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c1404a130..34f7be01c 100644 --- a/README.md +++ b/README.md @@ -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 26a0a62fb..484757163 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml expected, output end diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index b2bcd5c32..9929de9c2 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml expected, output end From d8c3c1dfe994ca84a60d179fa3807d18418c52bd Mon Sep 17 00:00:00 2001 From: Zulfiqar Ali Date: Mon, 7 Nov 2016 21:46:23 -0500 Subject: [PATCH 02/11] inputs with errors should have form-control-feedback --- README.md | 2 +- lib/bootstrap_form/form_builder.rb | 10 +++++++--- 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 +- 8 files changed, 27 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 34f7be01c..f9bc4a592 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..92c7dced5 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -385,12 +385,16 @@ 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 - return if help_text === false + if has_error?(name) && inline_errors + help_text = get_error_messages(name) + help_klass = 'form-control-feedback' + end + return if help_text == false + help_klass ||= 'form-text text-muted' help_text ||= get_help_text_by_i18n_key(name) - content_tag(:span, help_text, class: 'help-block') if help_text.present? + content_tag(:span, help_text, class: help_klass) if help_text.present? end def generate_icon(icon) diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb index 0d2832690..0da45b2e6 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 = %{
With a help!
} assert_equivalent_xml 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 3eaec8ece..a72ddadab 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 = %{
A good password should be at least six characters long
} assert_equivalent_xml expected, @builder.password_field(:password) end diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index 484757163..807cab7ca 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 = %{
This is required
} assert_equivalent_xml expected, @builder.text_field(:email, help: 'This is required') end test "help messages for horizontal forms" do - expected = %{
This is required
} + expected = %{
This is required
} assert_equivalent_xml 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 = %{
A good password should be at least six characters long
} assert_equivalent_xml 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml expected, output end diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 9929de9c2..6254cf998 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml expected, output end diff --git a/test/bootstrap_radio_button_test.rb b/test/bootstrap_radio_button_test.rb index b420c1e01..c7795f8f9 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 = %{
With a help!
} assert_equivalent_xml 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 = %{
With a help!
} assert_equivalent_xml 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 = %{
With a help!
} assert_equivalent_xml 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 = %{
With a help!
} assert_equivalent_xml 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 = %{
With a help!
} assert_equivalent_xml 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 80846bcd1..9c7090128 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 = %{
Help!
} assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], label: "My Status Label", help: "Help!" ) end From 04388cfbdc5360c9cfc7a987140c652f0fb452a8 Mon Sep 17 00:00:00 2001 From: Zulfiqar Ali Date: Mon, 7 Nov 2016 21:47:30 -0500 Subject: [PATCH 03/11] control-label is now form-control-label --- README.md | 8 ++-- lib/bootstrap_form/form_builder.rb | 2 +- test/bootstrap_checkbox_test.rb | 24 +++++------ test/bootstrap_fields_test.rb | 42 +++++++++---------- test/bootstrap_form_group_test.rb | 56 ++++++++++++------------- test/bootstrap_form_test.rb | 26 ++++++------ test/bootstrap_other_components_test.rb | 18 ++++---- test/bootstrap_radio_button_test.rb | 24 +++++------ test/bootstrap_selects_test.rb | 44 +++++++++---------- test/special_form_class_models_test.rb | 6 +-- 10 files changed, 125 insertions(+), 125 deletions(-) diff --git a/README.md b/README.md index f9bc4a592..4c0a5b319 100644 --- a/README.md +++ b/README.md @@ -209,7 +209,7 @@ This automatically adds the `has-feedback` class to the `form-group`: ```html
- +
@@ -249,7 +249,7 @@ Which produces the following output: ```erb
- +
``` @@ -330,7 +330,7 @@ Here's the output: ```html
- +

test@email.com

@@ -469,7 +469,7 @@ div (field_with_errors), but this behavior is suppressed. Here's an example: ```html
- +
diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index 92c7dced5..5d0317f87 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -259,7 +259,7 @@ def control_class end def label_class - "control-label" + "form-control-label" end def error_class diff --git a/test/bootstrap_checkbox_test.rb b/test/bootstrap_checkbox_test.rb index 0da45b2e6..74986b577 100644 --- a/test/bootstrap_checkbox_test.rb +++ b/test/bootstrap_checkbox_test.rb @@ -54,28 +54,28 @@ 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: 1) assert_equivalent_xml 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_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, :id, :street, checked: [1, 2]) assert_equivalent_xml 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street, checked: "address_1") assert_equivalent_xml 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_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: ["address_1", "address_2"]) assert_equivalent_xml expected, @builder.collection_check_boxes(:misc, collection, lambda { |a| "address_#{a.id}" }, :street, checked: collection) diff --git a/test/bootstrap_fields_test.rb b/test/bootstrap_fields_test.rb index a72ddadab..c6f8767cb 100644 --- a/test/bootstrap_fields_test.rb +++ b/test/bootstrap_fields_test.rb @@ -8,32 +8,32 @@ def setup end test "color fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.color_field(:misc) end test "date fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.date_field(:misc) end test "date time fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.datetime_field(:misc) end test "date time local fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.datetime_local_field(:misc) end test "email fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.email_field(:misc) end test "file fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.file_field(:misc) end @@ -43,58 +43,58 @@ def setup end test "month local fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.month_field(:misc) end test "number fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.number_field(:misc) end test "password fields are wrapped correctly" do - expected = %{
A good password should be at least six characters long
} + expected = %{
A good password should be at least six characters long
} assert_equivalent_xml expected, @builder.password_field(:password) end test "phone/telephone fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.phone_field(:misc) assert_equivalent_xml expected, @builder.telephone_field(:misc) end test "range fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.range_field(:misc) end test "search fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.search_field(:misc) end test "text areas are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.text_area(:comments) end test "text fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.text_field(:email) end test "time fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.time_field(:misc) end test "url fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.url_field(:misc) end test "week fields are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.week_field(:misc) end @@ -107,7 +107,7 @@ def setup end end - expected = %{
} + expected = %{
} assert_equivalent_xml expected, output end @@ -120,7 +120,7 @@ def setup end end - expected = %{
} + expected = %{
} assert_equivalent_xml expected, output end @@ -133,7 +133,7 @@ def setup end end - expected = %{
} + expected = %{
} assert_equivalent_xml expected, output end @@ -146,7 +146,7 @@ def setup end end - expected = %{
} + expected = %{
} assert_equivalent_xml expected, output end end diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index 807cab7ca..299410d2c 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -8,32 +8,32 @@ def setup end test "changing the label text via the label option parameter" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.text_field(:email, label: 'Email Address') end test "changing the label text via the html_options label hash" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.text_field(:email, label: {text: 'Email Address'}) end test "hiding a label" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.text_field(:email, hide_label: true) end test "adding a custom label class via the label_class parameter" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.text_field(:email, label_class: 'btn') end test "adding a custom label class via the html_options label hash" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.text_field(:email, label: {class: 'btn'}) end test "adding a custom label and changing the label text via the html_options label hash" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.text_field(:email, label: {class: 'btn', text: "Email Address"}) end @@ -43,22 +43,22 @@ def setup end test "preventing a label from having the required class" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.text_field(:email, skip_required: true) end test "adding prepend text" do - expected = %{
@
} + expected = %{
@
} assert_equivalent_xml expected, @builder.text_field(:email, prepend: '@') end test "adding append text" do - expected = %{
.00
} + expected = %{
.00
} assert_equivalent_xml expected, @builder.text_field(:email, append: '.00') end test "append and prepend button" do - prefix = %{
} + prefix = %{
} field = %{} button = %{Click} suffix = %{
} @@ -72,22 +72,22 @@ def setup end test "adding both prepend and append text" do - expected = %{
$.00
} + expected = %{
$.00
} assert_equivalent_xml expected, @builder.text_field(:email, prepend: '$', append: '.00') end test "help messages for default forms" do - expected = %{
This is required
} + expected = %{
This is required
} assert_equivalent_xml expected, @builder.text_field(:email, help: 'This is required') end test "help messages for horizontal forms" do - expected = %{
This is required
} + expected = %{
This is required
} assert_equivalent_xml 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 = %{
A good password should be at least six characters long
} assert_equivalent_xml expected, @builder.text_field(:password) end @@ -110,7 +110,7 @@ def setup end test "help messages to ignore translation when user disables help" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.text_field(:password, help: false) end @@ -119,7 +119,7 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = %{

Bar

} assert_equivalent_xml expected, output end @@ -137,7 +137,7 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = %{

Bar

} assert_equivalent_xml expected, output end @@ -164,7 +164,7 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = %{

Bar

} assert_equivalent_xml expected, output end @@ -181,7 +181,7 @@ def setup end test "adds class to wrapped form_group by a field" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.search_field(:misc, wrapper_class: 'none-margin') end @@ -189,7 +189,7 @@ def setup @user.email = nil @user.valid? - expected = %{
} + expected = %{
} assert_equivalent_xml 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 = %{
} + expected = %{
} assert_equivalent_xml expected, output end @@ -224,7 +224,7 @@ def setup end test "adding an icon to a field" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.email_field(:misc, icon: 'ok') end @@ -236,17 +236,17 @@ def setup output = output + @horizontal_builder.text_field(:email) - expected = %{
Hallo
} + expected = %{
Hallo
} assert_equivalent_xml expected, output end test "adds data-attributes (or any other options) to wrapper" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.search_field(:misc, wrapper: { data: { foo: 'bar' } }) end test "passing options to a form control get passed through" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.text_field(:email, autofocus: true) end @@ -255,12 +255,12 @@ def setup nil end - expected = %{
} + expected = %{
} assert_equivalent_xml expected, output end test "custom form group layout option" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, layout: :inline } end @@ -283,7 +283,7 @@ def setup end test ":input_group_class should apply to input-group" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.email_field(:email, append: @builder.primary('Subscribe'), input_group_class: 'input-group-lg') end end diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index 6254cf998..a958dd963 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -18,12 +18,12 @@ def setup end test "horizontal-style forms" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email } end test "existing styles aren't clobbered when specifying a form style" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal, html: { class: "my-style" }) { |f| f.email_field :email } end @@ -33,12 +33,12 @@ def setup end test "bootstrap_form_tag acts like a form tag" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_tag(url: '/users') { |f| f.text_field :email, label: "Your Email" } end test "bootstrap_form_tag does not clobber custom options" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_tag(url: '/users') { |f| f.text_field :email, name: 'NAME', id: "ID" } end @@ -51,7 +51,7 @@ def setup @user.email = nil @user.valid? - expected = %{
} + expected = %{
} assert_equivalent_xml 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_equivalent_xml 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_equivalent_xml 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}}}}) @@ -142,7 +142,7 @@ def setup end test "custom label width for horizontal forms" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, label_col: 'col-sm-1' } end @@ -152,7 +152,7 @@ def setup end test "custom input width for horizontal forms" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, control_col: 'col-sm-5' } end @@ -164,7 +164,7 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
} + expected = %{
} assert_equivalent_xml expected, output end @@ -176,7 +176,7 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
} + expected = %{
} assert_equivalent_xml expected, output end @@ -188,13 +188,13 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
This is required
} + expected = %{
This is required
} assert_equivalent_xml expected, output end test "allows the form object to be nil" do builder = BootstrapForm::FormBuilder.new :other_model, nil, self, {} - expected = %{
} + expected = %{
} assert_equivalent_xml expected, builder.text_field(:email) end diff --git a/test/bootstrap_other_components_test.rb b/test/bootstrap_other_components_test.rb index f175c94ed..ff11d1b76 100644 --- a/test/bootstrap_other_components_test.rb +++ b/test/bootstrap_other_components_test.rb @@ -10,7 +10,7 @@ def setup test "static control" do output = @horizontal_builder.static_control :email - expected = %{

steve@example.com

} + expected = %{

steve@example.com

} assert_equivalent_xml expected, output end @@ -19,7 +19,7 @@ def setup "this is a test" end - expected = %{

this is a test

} + expected = %{

this is a test

} assert_equivalent_xml expected, output end @@ -28,7 +28,7 @@ def setup "Custom Control" end - expected = %{

Custom Control

} + expected = %{

Custom Control

} assert_equivalent_xml expected, output end @@ -37,8 +37,8 @@ def setup "this is a test" end - expected = %{
this is a test
} - assert_equal expected, output + expected = %{
this is a test
} + assert_equivalent_xml expected, output end test "custom control doesn't require an actual attribute" do @@ -46,8 +46,8 @@ def setup "this is a test" end - expected = %{
this is a test
} - assert_equal expected, output + expected = %{
this is a test
} + assert_equivalent_xml expected, output end test "custom control doesn't require a name" do @@ -55,8 +55,8 @@ def setup "Custom Control" end - expected = %{
Custom Control
} - assert_equal expected, output + expected = %{
Custom Control
} + assert_equivalent_xml expected, output end test "submit button defaults to rails action name" do diff --git a/test/bootstrap_radio_button_test.rb b/test/bootstrap_radio_button_test.rb index c7795f8f9..2ba720da1 100644 --- a/test/bootstrap_radio_button_test.rb +++ b/test/bootstrap_radio_button_test.rb @@ -39,84 +39,84 @@ def setup test 'collection_radio_buttons renders the form_group correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = %{
With a help!
} assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, label: 'This is a radio button collection', help: 'With a help!') end test 'collection_radio_buttons renders multiple radios correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, :street) end test 'collection_radio_buttons renders inline radios correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, inline: true) end test 'collection_radio_buttons renders with checked option correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, :street, checked: 1) end test 'collection_radio_buttons renders label defined by Proc correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = %{
With a help!
} assert_equivalent_xml 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 = %{
With a help!
} assert_equivalent_xml 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 test 'collection_radio_buttons renders multiple radios with label defined by Proc correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, Proc.new { |a| a.street.reverse }) end test 'collection_radio_buttons renders multiple radios with value defined by Proc correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, Proc.new { |a| "address_#{a.id}" }, :street) end test 'collection_radio_buttons renders label defined by lambda correctly' do collection = [Address.new(id: 1, street: 'Foobar')] - expected = %{
With a help!
} + expected = %{
With a help!
} assert_equivalent_xml 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 = %{
With a help!
} assert_equivalent_xml 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 test 'collection_radio_buttons renders multiple radios with label defined by lambda correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, :id, lambda { |a| a.street.reverse }) end test 'collection_radio_buttons renders multiple radios with value defined by lambda correctly' do collection = [Address.new(id: 1, street: 'Foo'), Address.new(id: 2, street: 'Bar')] - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.collection_radio_buttons(:misc, collection, lambda { |a| "address_#{a.id}" }, :street) end diff --git a/test/bootstrap_selects_test.rb b/test/bootstrap_selects_test.rb index 9c7090128..310126aae 100644 --- a/test/bootstrap_selects_test.rb +++ b/test/bootstrap_selects_test.rb @@ -8,33 +8,33 @@ def setup end test "time zone selects are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.time_zone_select(:misc) end test "selects are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]]) end test "bootstrap_specific options are handled correctly" do - expected = %{
Help!
} + expected = %{
Help!
} assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], label: "My Status Label", help: "Help!" ) end test "selects with options are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], prompt: "Please Select") end test "selects with both options and html_options are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], { prompt: "Please Select" }, class: "my-select") end if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("4.1.0") test "selects with block use block as content" do - expected = %{
} + expected = %{
} select = @builder.select(:status) do content_tag(:option) { 'Option 1' } + content_tag(:option) { 'Option 2' } @@ -44,99 +44,99 @@ def setup end test "selects render labels properly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.select(:status, [['activated', 1], ['blocked', 2]], label: "User Status") end test "collection_selects are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.collection_select(:status, [], :id, :name) end test "collection_selects with options are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.collection_select(:status, [], :id, :name, prompt: "Please Select") end test "collection_selects with options and html_options are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.collection_select(:status, [], :id, :name, { prompt: "Please Select" }, class: "my-select") end test "grouped_collection_selects are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s) end test "grouped_collection_selects with options are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s, prompt: "Please Select") end test "grouped_collection_selects with options and html_options are wrapped correctly" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.grouped_collection_select(:status, [], :last, :first, :to_s, :to_s, { prompt: "Please Select" }, class: "my-select") end test "date selects are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3)) do - expected = %{
\n\n\n
} + expected = %{
\n\n\n
} assert_equivalent_xml expected, @builder.date_select(:misc) end end test "date selects with options are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3)) do - expected = %{
\n\n\n
} + expected = %{
\n\n\n
} assert_equivalent_xml expected, @builder.date_select(:misc, include_blank: true) end end test "date selects with options and html_options are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3)) do - expected = %{
\n\n\n
} + expected = %{
\n\n\n
} assert_equivalent_xml expected, @builder.date_select(:misc, { include_blank: true }, class: "my-date-select") end end test "time selects are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do - expected = %{
\n\n\n\n : \n
} + expected = %{
\n\n\n\n : \n
} assert_equivalent_xml expected, @builder.time_select(:misc) end end test "time selects with options are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do - expected = %{
\n\n\n\n : \n
} + expected = %{
\n\n\n\n : \n
} assert_equivalent_xml expected, @builder.time_select(:misc, include_blank: true) end end test "time selects with options and html_options are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do - expected = %{
\n\n\n\n : \n
} + expected = %{
\n\n\n\n : \n
} assert_equivalent_xml expected, @builder.time_select(:misc, { include_blank: true }, class: "my-time-select") end end test "datetime selects are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do - expected = %{
\n\n\n — \n : \n
} + expected = %{
\n\n\n — \n : \n
} assert_equivalent_xml expected, @builder.datetime_select(:misc) end end test "datetime selects with options are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do - expected = %{
\n\n\n — \n : \n
} + expected = %{
\n\n\n — \n : \n
} assert_equivalent_xml expected, @builder.datetime_select(:misc, include_blank: true) end end test "datetime selects with options and html_options are wrapped correctly" do Timecop.freeze(Time.utc(2012, 2, 3, 12, 0, 0)) do - expected = %{
\n\n\n — \n : \n
} + expected = %{
\n\n\n — \n : \n
} assert_equivalent_xml expected, @builder.datetime_select(:misc, { include_blank: true }, class: "my-datetime-select") end end diff --git a/test/special_form_class_models_test.rb b/test/special_form_class_models_test.rb index 2579c9a48..cc88f836a 100644 --- a/test/special_form_class_models_test.rb +++ b/test/special_form_class_models_test.rb @@ -14,7 +14,7 @@ def user_klass.model_name @horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, {layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10"}) I18n.backend.store_translations(:en, {activerecord: {help: {user: {password: "A good password should be at least six characters long"}}}}) - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.date_field(:misc) end @@ -24,7 +24,7 @@ def user_klass.model_name @horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, {layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10"}) I18n.backend.store_translations(:en, {activerecord: {help: {user: {password: "A good password should be at least six characters long"}}}}) - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.date_field(:misc) end @@ -36,7 +36,7 @@ def user_klass.model_name @horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, {layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10"}) I18n.backend.store_translations(:en, {activerecord: {help: {faux_user: {password: "A good password should be at least six characters long"}}}}) - expected = %{
} + expected = %{
} assert_equivalent_xml expected, @builder.date_field(:misc) end From 47e90fa1f278d29bb6ee48ca96357c42ab5dd443 Mon Sep 17 00:00:00 2001 From: Zulfiqar Ali Date: Mon, 7 Nov 2016 22:14:57 -0500 Subject: [PATCH 04/11] btn-default is now btn-secondary --- README.md | 6 +++--- lib/bootstrap_form/helpers/bootstrap.rb | 2 +- test/bootstrap_form_group_test.rb | 8 ++++---- test/bootstrap_form_test.rb | 2 +- test/bootstrap_other_components_test.rb | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 4c0a5b319..7d7c5c730 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ This generates the following HTML: Remember me
- + ``` @@ -227,7 +227,7 @@ You can also prepend and append buttons. Note: The buttons must contain the `btn` class to generate the correct markup. ```erb -<%= f.text_field :search, append: link_to("Go", "#", class: "btn btn-default") %> +<%= f.text_field :search, append: link_to("Go", "#", class: "btn btn-secondary") %> ``` To add a class to the input group wrapper, use `:input_group_class` option. @@ -355,7 +355,7 @@ this defining these selects as `inline-block` and a width of `auto`. ### Submit Buttons -The `btn btn-default` css classes are automatically added to your submit +The `btn btn-secondary` css classes are automatically added to your submit buttons. ```erb diff --git a/lib/bootstrap_form/helpers/bootstrap.rb b/lib/bootstrap_form/helpers/bootstrap.rb index 988b16280..58b31d76e 100644 --- a/lib/bootstrap_form/helpers/bootstrap.rb +++ b/lib/bootstrap_form/helpers/bootstrap.rb @@ -2,7 +2,7 @@ module BootstrapForm module Helpers module Bootstrap def submit(name = nil, options = {}) - options.reverse_merge! class: 'btn btn-default' + options.reverse_merge! class: 'btn btn-secondary' super(name, options) end diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index 299410d2c..a44a06f49 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -60,12 +60,12 @@ def setup test "append and prepend button" do prefix = %{
} field = %{} - button = %{Click} + button = %{Click} suffix = %{
} after_button = prefix + field + button + suffix before_button = prefix + button + field + suffix both_button = prefix + button + field + button + suffix - button_src = link_to("Click", "#", class: "btn btn-default") + button_src = link_to("Click", "#", class: "btn btn-secondary") assert_equivalent_xml after_button, @builder.text_field(:email, append: button_src) assert_equivalent_xml before_button, @builder.text_field(:email, prepend: button_src) assert_equivalent_xml both_button, @builder.text_field(:email, append: button_src, prepend: button_src) @@ -210,7 +210,7 @@ def setup @horizontal_builder.submit end - expected = %{
} + expected = %{
} assert_equivalent_xml expected, output end @@ -219,7 +219,7 @@ def setup @horizontal_builder.submit end - expected = %{
} + expected = %{
} assert_equivalent_xml expected, output end diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index a958dd963..bd826204b 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -147,7 +147,7 @@ def setup end test "offset for form group without label respects label width for horizontal forms" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal, label_col: 'col-md-2', control_col: 'col-md-10') { |f| f.form_group { f.submit } } end diff --git a/test/bootstrap_other_components_test.rb b/test/bootstrap_other_components_test.rb index ff11d1b76..33e05e069 100644 --- a/test/bootstrap_other_components_test.rb +++ b/test/bootstrap_other_components_test.rb @@ -60,12 +60,12 @@ def setup end test "submit button defaults to rails action name" do - expected = %{} + expected = %{} assert_equivalent_xml expected, @builder.submit end test "submit button uses default button classes" do - expected = %{} + expected = %{} assert_equivalent_xml expected, @builder.submit("Submit Form") end From 2fe6f286760990b998a8795594fe5c4186e9f2a2 Mon Sep 17 00:00:00 2001 From: Zulfiqar Ali Date: Mon, 7 Nov 2016 22:31:49 -0500 Subject: [PATCH 05/11] form-horizontal is no longer a required class --- lib/bootstrap_form/form_builder.rb | 1 + lib/bootstrap_form/helper.rb | 11 ++--------- test/bootstrap_fields_test.rb | 2 +- test/bootstrap_form_group_test.rb | 26 ++++++++++++------------- test/bootstrap_form_test.rb | 10 +++++----- test/bootstrap_other_components_test.rb | 12 ++++++------ 6 files changed, 28 insertions(+), 34 deletions(-) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index 5d0317f87..c68e4f06f 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -194,6 +194,7 @@ def form_group(*args, &block) name = args.first options[:class] = ["form-group", options[:class]].compact.join(' ') + options[:class] << " row" if get_group_layout(options[:layout]) == :horizontal options[:class] << " #{error_class}" if has_error?(name) options[:class] << " #{feedback_class}" if options[:icon] diff --git a/lib/bootstrap_form/helper.rb b/lib/bootstrap_form/helper.rb index ee73c9016..6788588e8 100644 --- a/lib/bootstrap_form/helper.rb +++ b/lib/bootstrap_form/helper.rb @@ -10,15 +10,8 @@ def bootstrap_form_for(object, options = {}, &block) options[:html] ||= {} options[:html][:role] ||= 'form' - layout = case options[:layout] - when :inline - "form-inline" - when :horizontal - "form-horizontal" - end - - if layout - options[:html][:class] = [options[:html][:class], layout].compact.join(" ") + if options[:layout] == :inline + options[:html][:class] = [options[:html][:class], "form-inline"].compact.join(" ") end temporarily_disable_field_error_proc do diff --git a/test/bootstrap_fields_test.rb b/test/bootstrap_fields_test.rb index c6f8767cb..b7d9445c9 100644 --- a/test/bootstrap_fields_test.rb +++ b/test/bootstrap_fields_test.rb @@ -133,7 +133,7 @@ def setup end end - expected = %{
} + expected = %{
} assert_equivalent_xml expected, output end diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index a44a06f49..a4aa9ed58 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -82,7 +82,7 @@ def setup end test "help messages for horizontal forms" do - expected = %{
This is required
} + expected = %{
This is required
} assert_equivalent_xml expected, @horizontal_builder.text_field(:email, help: "This is required") end @@ -119,7 +119,7 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = %{

Bar

} assert_equivalent_xml expected, output end @@ -128,7 +128,7 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = %{

Bar

} assert_equivalent_xml expected, output end @@ -137,7 +137,7 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = %{

Bar

} assert_equivalent_xml expected, output end @@ -146,7 +146,7 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = %{

Bar

} assert_equivalent_xml expected, output end @@ -155,7 +155,7 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = %{

Bar

} assert_equivalent_xml expected, output end @@ -164,7 +164,7 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = %{

Bar

} assert_equivalent_xml expected, output end @@ -210,7 +210,7 @@ def setup @horizontal_builder.submit end - expected = %{
} + expected = %{
} assert_equivalent_xml expected, output end @@ -219,7 +219,7 @@ def setup @horizontal_builder.submit end - expected = %{
} + expected = %{
} assert_equivalent_xml expected, output end @@ -236,7 +236,7 @@ def setup output = output + @horizontal_builder.text_field(:email) - expected = %{
Hallo
} + expected = %{
Hallo
} assert_equivalent_xml expected, output end @@ -260,7 +260,7 @@ def setup end test "custom form group layout option" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, layout: :inline } end @@ -270,7 +270,7 @@ def setup %{

Bar

}.html_safe end - expected = %{

Bar

} + expected = %{

Bar

} assert_equivalent_xml expected, output end @@ -278,7 +278,7 @@ def setup frozen_horizontal_builder = BootstrapForm::FormBuilder.new(:user, @user, self, { layout: :horizontal, label_col: "col-sm-3".freeze, control_col: "col-sm-9".freeze }) output = frozen_horizontal_builder.form_group { 'test' } - expected = %{
test
} + expected = %{
test
} assert_equivalent_xml expected, output end diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index bd826204b..c2c44fd6f 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -18,12 +18,12 @@ def setup end test "horizontal-style forms" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email } end test "existing styles aren't clobbered when specifying a form style" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal, html: { class: "my-style" }) { |f| f.email_field :email } end @@ -142,17 +142,17 @@ def setup end test "custom label width for horizontal forms" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, label_col: 'col-sm-1' } end test "offset for form group without label respects label width for horizontal forms" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal, label_col: 'col-md-2', control_col: 'col-md-10') { |f| f.form_group { f.submit } } end test "custom input width for horizontal forms" do - expected = %{
} + expected = %{
} assert_equivalent_xml expected, bootstrap_form_for(@user, layout: :horizontal) { |f| f.email_field :email, control_col: 'col-sm-5' } end diff --git a/test/bootstrap_other_components_test.rb b/test/bootstrap_other_components_test.rb index 33e05e069..0933c56f2 100644 --- a/test/bootstrap_other_components_test.rb +++ b/test/bootstrap_other_components_test.rb @@ -10,7 +10,7 @@ def setup test "static control" do output = @horizontal_builder.static_control :email - expected = %{

steve@example.com

} + expected = %{

steve@example.com

} assert_equivalent_xml expected, output end @@ -19,7 +19,7 @@ def setup "this is a test" end - expected = %{

this is a test

} + expected = %{

this is a test

} assert_equivalent_xml expected, output end @@ -28,7 +28,7 @@ def setup "Custom Control" end - expected = %{

Custom Control

} + expected = %{

Custom Control

} assert_equivalent_xml expected, output end @@ -37,7 +37,7 @@ def setup "this is a test" end - expected = %{
this is a test
} + expected = %{
this is a test
} assert_equivalent_xml expected, output end @@ -46,7 +46,7 @@ def setup "this is a test" end - expected = %{
this is a test
} + expected = %{
this is a test
} assert_equivalent_xml expected, output end @@ -55,7 +55,7 @@ def setup "Custom Control" end - expected = %{
Custom Control
} + expected = %{
Custom Control
} assert_equivalent_xml expected, output end From fd2dc5725e4f39b6ff250fa6b8ed289bd30326a1 Mon Sep 17 00:00:00 2001 From: Zulfiqar Ali Date: Mon, 7 Nov 2016 22:46:29 -0500 Subject: [PATCH 06/11] input field should have form-control-danger on error --- lib/bootstrap_form/form_builder.rb | 1 + test/bootstrap_form_group_test.rb | 4 ++-- test/bootstrap_form_test.rb | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index c68e4f06f..f8f006fb3 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -310,6 +310,7 @@ def form_group_builder(method, options, html_options = nil) css_options = html_options || options control_classes = css_options.delete(:control_class) { control_class } css_options[:class] = [control_classes, css_options[:class]].compact.join(" ") + css_options[:class] << " form-control-danger" if has_error?(method) options = convert_form_tag_options(method, options) if acts_like_form_tag diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index a4aa9ed58..6c1f6d115 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -189,7 +189,7 @@ def setup @user.email = nil @user.valid? - expected = %{
} + expected = %{
} assert_equivalent_xml 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 = %{
} + expected = %{
} assert_equivalent_xml expected, output end diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index c2c44fd6f..554c01051 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_equivalent_xml 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_equivalent_xml 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_equivalent_xml 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 = %{
} + expected = %{
} assert_equivalent_xml expected, output end @@ -176,7 +176,7 @@ def setup f.text_field(:email, help: 'This is required') end - expected = %{
} + expected = %{
} assert_equivalent_xml 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_equivalent_xml expected, output end From 77ed9ffce706958e6e434334331122ceef592c0a Mon Sep 17 00:00:00 2001 From: Zulfiqar Ali Date: Mon, 7 Nov 2016 23:16:27 -0500 Subject: [PATCH 07/11] checkbox is now form-check --- README.md | 2 +- lib/bootstrap_form/form_builder.rb | 4 +-- test/bootstrap_checkbox_test.rb | 42 +++++++++++++++--------------- test/bootstrap_form_test.rb | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 7d7c5c730..4d6ed5ba2 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ This generates the following HTML:
-
+