rails_bootstrap_form 0.5.3 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +111 -2
  3. data/Gemfile.lock +9 -3
  4. data/README.md +68 -0
  5. data/Rakefile +2 -0
  6. data/app/assets/stylesheets/rails_bootstrap_form.css +3 -0
  7. data/demo/app/views/users/_form.html.erb +2 -0
  8. data/demo/app/views/users/_horizontal_form.html.erb +32 -0
  9. data/demo/app/views/users/_vertical_form.html.erb +8 -8
  10. data/demo/config/database.yml +7 -15
  11. data/demo/db/schema.rb +8 -5
  12. data/gemfiles/common.gemfile +10 -2
  13. data/lib/rails_bootstrap_form/bootstrap_form_builder.rb +1 -1
  14. data/lib/rails_bootstrap_form/bootstrap_form_options.rb +21 -3
  15. data/lib/rails_bootstrap_form/field_wrapper_builder.rb +31 -17
  16. data/lib/rails_bootstrap_form/{components → helpers}/check_box.rb +10 -3
  17. data/lib/rails_bootstrap_form/{components → helpers}/errors.rb +1 -1
  18. data/lib/rails_bootstrap_form/{components → helpers}/help_text.rb +1 -1
  19. data/lib/rails_bootstrap_form/{components → helpers}/labels.rb +8 -2
  20. data/lib/rails_bootstrap_form/{components → helpers}/radio_button.rb +10 -3
  21. data/lib/rails_bootstrap_form/{components → helpers}/required_field.rb +1 -1
  22. data/lib/rails_bootstrap_form/helpers.rb +45 -0
  23. data/lib/rails_bootstrap_form/inputs/base.rb +16 -11
  24. data/lib/rails_bootstrap_form/inputs/check_box.rb +45 -0
  25. data/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb +41 -0
  26. data/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb +39 -0
  27. data/lib/rails_bootstrap_form/inputs/collection_select.rb +21 -0
  28. data/lib/rails_bootstrap_form/inputs/color_field.rb +21 -0
  29. data/lib/rails_bootstrap_form/inputs/date_field.rb +15 -0
  30. data/lib/rails_bootstrap_form/inputs/date_select.rb +15 -0
  31. data/lib/rails_bootstrap_form/inputs/datetime_field.rb +15 -0
  32. data/lib/rails_bootstrap_form/inputs/datetime_local_field.rb +15 -0
  33. data/lib/rails_bootstrap_form/inputs/datetime_select.rb +15 -0
  34. data/lib/rails_bootstrap_form/inputs/email_field.rb +15 -0
  35. data/lib/rails_bootstrap_form/inputs/file_field.rb +15 -0
  36. data/lib/rails_bootstrap_form/inputs/grouped_collection_select.rb +21 -0
  37. data/lib/rails_bootstrap_form/inputs/hidden_field.rb +19 -0
  38. data/lib/rails_bootstrap_form/inputs/month_field.rb +15 -0
  39. data/lib/rails_bootstrap_form/inputs/number_field.rb +15 -0
  40. data/lib/rails_bootstrap_form/inputs/password_field.rb +15 -0
  41. data/lib/rails_bootstrap_form/inputs/phone_field.rb +15 -0
  42. data/lib/rails_bootstrap_form/inputs/radio_button.rb +45 -0
  43. data/lib/rails_bootstrap_form/inputs/range_field.rb +21 -0
  44. data/lib/rails_bootstrap_form/inputs/search_field.rb +15 -0
  45. data/lib/rails_bootstrap_form/inputs/select.rb +21 -0
  46. data/lib/rails_bootstrap_form/inputs/static_field.rb +30 -0
  47. data/lib/rails_bootstrap_form/inputs/telephone_field.rb +15 -0
  48. data/lib/rails_bootstrap_form/inputs/text_area.rb +15 -0
  49. data/lib/rails_bootstrap_form/inputs/text_field.rb +15 -0
  50. data/lib/rails_bootstrap_form/inputs/time_field.rb +15 -0
  51. data/lib/rails_bootstrap_form/inputs/time_select.rb +15 -0
  52. data/lib/rails_bootstrap_form/inputs/time_zone_select.rb +21 -0
  53. data/lib/rails_bootstrap_form/inputs/url_field.rb +15 -0
  54. data/lib/rails_bootstrap_form/inputs/week_field.rb +15 -0
  55. data/lib/rails_bootstrap_form/inputs.rb +62 -209
  56. data/lib/rails_bootstrap_form/version.rb +1 -1
  57. data/lib/rails_bootstrap_form.rb +3 -2
  58. metadata +70 -10
  59. data/lib/rails_bootstrap_form/components.rb +0 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1031de2aa81bb74657e9a45f334c4dc4d67ee673e89874358881d8021388d8b9
4
- data.tar.gz: 4a5d3c85afb71bd06005eb95c0b8abb76a429a46ea49f22b470943bba2a6f7ae
3
+ metadata.gz: 34303679b08cf0617516305e5b4e1f21d8c201ffcd9f4cc8eb90f26a587a7f7a
4
+ data.tar.gz: 4e01e2321eb0318e222e802ce84e8c63648296c50e78de5de9f3c8e14be9570e
5
5
  SHA512:
6
- metadata.gz: 188081d3651b5f6977df21c3bfb4436e44b3d96685ef8b6fc36b7805056b205ab77ced5f3ad4d3094217116e47f04e8a07a914db1f073c60be664bd4acf33694
7
- data.tar.gz: 180295d5dbc0159f5181183be148203565d877d874d978074af43dd31ba0cfb7e7d8d2be3bcf3d3c72e1abe6d4ff58636da8c4386be3b09d64380edc4ef06b2d
6
+ metadata.gz: c7f4349d0933eeea1f1965df83eb80ec0fd83392a3a47e2299214a797ec36e5c198e647d727969443779d60910741f91b49f88973a6ebcf6d93a29302f308b46
7
+ data.tar.gz: adab966d0ca4b8064094e7e941296d95e75e594452384e9cb6e7370ca19fd288a4e9d9cea1e56dbf7981804ef58f9cafc1398d1e0203bb1eefb80004f27ab18d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,114 @@
1
- ## [Unreleased]
1
+ # Change Log
2
+
3
+ You can find recent releases with docs in GitHub:
4
+
5
+ https://github.com/shivam091/rails_bootstrap_form/releases
6
+
7
+ ## [0.6.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.6.0...v0.6.1) - 2023-05-24
8
+
9
+ ### What's changed
10
+ - Changes in directory structure
11
+ - Added test cases
12
+ - Added README and CHANGELOG
13
+
14
+ ## [0.6.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.5.3...v0.6.0) - 2023-05-22
15
+
16
+ ### What's new
17
+ - Added support for **`horizontal`** form layout
18
+
19
+ ## [0.5.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.5.2...v0.5.3) - 2023-05-21
20
+
21
+ ### What's changed
22
+ - Added new option inline to render checkboxes and radio buttons inline
23
+
24
+ ## [0.5.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.5.1...v0.5.2) - 2023-05-21
25
+
26
+ ### What's new
27
+ - Added option to add custom options to the field's wrapper
28
+ - Added option to apply user defined CSS class to the field
29
+ - Added option to control size of input group and field
30
+ - Added provision to change id of the field and corresponding label
31
+
32
+ ### What's changed
33
+ - Added `mb-3` css class to field wrapper if radio buttons or check boxes are not inline
34
+
35
+ ## [0.5.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.5.0...v0.5.1) - 2023-05-20
36
+
37
+ ### What's new
38
+ - Wrapped `collection_check_boxes` and `collection_radio_buttons` inside field wrapper.
39
+
40
+ ## [0.5.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.4.2...v0.5.0) - 2023-05-20
41
+
42
+ ### What's new
43
+ - Added wrapper methods for `check_box`, `collection_check_boxes`, `radio_button`, and `collection_radio_buttons` to support Bootstrap 5 form styles
44
+
45
+ ### What's changed
46
+ - Replaced HTML tag of help_text component from `<span>` to `<div>`
47
+
48
+ ## [0.4.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.4.1...v0.4.2) - 2023-05-16
49
+
50
+ ### What's new
51
+ - Added wrapper method for `grouped_collection_select`
52
+
53
+ ## [0.4.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.4.0...v0.4.1) - 2023-05-16
2
54
 
3
- ## [0.1.0] - 2023-05-15
55
+ ### What's fixed
56
+ - Replaced `reverse_merge` by `deep_merge!` in adding new option values to fix bug causing not to merge options.
57
+
58
+ ## [0.4.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.3.1...v0.4.0) - 2023-05-15
59
+
60
+ ### What's new
61
+ - Added wrapper methods for `range_field` and `color_field`
62
+ - Added wrapper methods for `time_zone_select` and `hidden_field`
63
+ - Added wrapper methods for `date_select`, `time_select`, and `datetime_select`
64
+ - Added wrapper method to render static control
65
+ - Added wrapper method for `collection_select`
66
+
67
+ ## [0.3.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.3.0...v0.3.1) - 2023-05-15
68
+
69
+ ### What's fixed
70
+ - Bug causing fields to wrap in input group even when content to append and prepend is not available.
71
+
72
+ ## [0.3.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.2.3...v0.3.0) - 2023-05-15
73
+
74
+ ### What's new
75
+ - Added support to wrap field in input group
76
+ - Added support to display error messages below the field
77
+ - Added support for floating labels for inputs.
78
+
79
+ ## [0.2.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.2.2...v0.2.3) - 2023-05-15
80
+
81
+ ### What's new
82
+ - Added component to mark labels as required
83
+
84
+ ## [0.2.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.2.1...v0.2.2) - 2023-05-15
85
+
86
+ ### What's new
87
+ - Added support to display labels along with the field.
88
+
89
+ ## [0.2.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.2.0...v0.2.1) - 2023-05-15
90
+
91
+ ### What's new
92
+ - Added FieldWrapperBuilder to create wrapper for placing fields and other related components
93
+ - Added support to display help text along with the field
94
+ - Added wrapper methods for simple form fields
95
+
96
+ ## [0.2.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.1.1...v0.2.0) - 2023-05-15
97
+
98
+ ### What's new
99
+ - Added PORO class `BootstrapFormOptions` to maintain gem specific configuration.
100
+ - Added BoostrapFormBuilder and extension methods for Rails form builder.
101
+ - Added required models, controllers, and views in demo application.
102
+
103
+ ## [0.1.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.1.0...v0.1.1) - 2023-05-15
104
+
105
+ ### What's new
106
+ - Initialized demo application for demonstrating the working.
107
+ - Added generater to copy initializer file required for maintaining global configuration.
108
+ - Added Configuration class to maintain configurable options.
109
+
110
+ ## 0.1.0 - 2023-05-15
4
111
 
5
112
  - Initial release
113
+
114
+ ## [Unreleased]
data/Gemfile.lock CHANGED
@@ -1,7 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_form (0.5.3)
4
+ rails_bootstrap_form (0.6.1)
5
+ actionpack (~> 7.0)
6
+ activemodel (~> 7.0)
5
7
 
6
8
  GEM
7
9
  remote: http://rubygems.org/
@@ -79,6 +81,8 @@ GEM
79
81
  sassc-rails (>= 2.0.0)
80
82
  builder (3.2.4)
81
83
  byebug (11.1.3)
84
+ compare-xml (0.66)
85
+ nokogiri (~> 1.8)
82
86
  concurrent-ruby (1.2.2)
83
87
  crass (1.0.6)
84
88
  date (3.3.3)
@@ -118,6 +122,7 @@ GEM
118
122
  nio4r (2.5.9)
119
123
  nokogiri (1.14.4-x86_64-linux)
120
124
  racc (~> 1.4)
125
+ pg (1.5.3)
121
126
  popper_js (2.11.7)
122
127
  puma (6.2.2)
123
128
  nio4r (~> 2.0)
@@ -190,7 +195,6 @@ GEM
190
195
  actionpack (>= 5.2)
191
196
  activesupport (>= 5.2)
192
197
  sprockets (>= 3.0.0)
193
- sqlite3 (1.6.2-x86_64-linux)
194
198
  thor (1.2.2)
195
199
  tilt (2.1.0)
196
200
  timeout (0.3.2)
@@ -207,7 +211,10 @@ PLATFORMS
207
211
  DEPENDENCIES
208
212
  bootstrap (~> 5.3.0.alpha3)
209
213
  byebug
214
+ compare-xml
210
215
  generator_spec
216
+ nokogiri
217
+ pg (~> 1.1)
211
218
  puma
212
219
  rails (~> 7.0)
213
220
  rails_bootstrap_form!
@@ -216,7 +223,6 @@ DEPENDENCIES
216
223
  sassc-rails
217
224
  simplecov
218
225
  sprockets-rails
219
- sqlite3 (~> 1.4)
220
226
 
221
227
  BUNDLED WITH
222
228
  2.4.10
data/README.md CHANGED
@@ -0,0 +1,68 @@
1
+ # RailsBootstrapForm
2
+
3
+ **rails_bootstrap_form** is a Rails form builder that makes it super easy to integrate
4
+ [Bootstrap 5](https://getbootstrap.com/) forms into your Rails application.
5
+
6
+ ## Minimum Requirements
7
+
8
+ * Ruby 3.2.2+ (https://www.ruby-lang.org/en/downloads/branches/)
9
+ * Rails 7.0+ (https://guides.rubyonrails.org/maintenance_policy.html)
10
+ * Bootstrap 5.0+ (https://getbootstrap.com/docs/versions/)
11
+
12
+ ## Installation
13
+
14
+ Install Bootstrap 5. There are many ways to do this, depending on the asset pipeline you're using in your Rails application. One way is to use the gem that works with Sprockets. To do so, in a brand new Rails 7.0 application created _without_ the `--webpacker` option, add the `bootstrap` gem to your `Gemfile`:
15
+
16
+ ```ruby
17
+ gem "bootstrap", "~> 5.0"
18
+ ```
19
+
20
+ And follow the remaining instructions in the [official bootstrap installation guide](https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails) for setting up `application.scss` and `application.js`.
21
+
22
+ Add the `rails_bootstrap_form` gem to your `Gemfile`:
23
+
24
+ ```ruby
25
+ gem "rails_bootstrap_form", "~> 0.6.1"
26
+ ```
27
+
28
+ Then:
29
+
30
+ `bundle install`
31
+
32
+ Depending on which CSS pre-processor you are using, adding the bootstrap form styles differs slightly.
33
+ If you use Rails in the default mode without any pre-processor, you'll have to add the following line to your `application.css` file:
34
+
35
+ ```css
36
+ *= require rails_bootstrap_form
37
+ ```
38
+
39
+ If you followed the [official bootstrap installation guide](https://github.com/twbs/bootstrap-rubygem#a-ruby-on-rails), you'll probably have switched to SCSS. In this case add the following line to your `application.scss`:
40
+
41
+ ```scss
42
+ @import "rails_bootstrap_form";
43
+ ```
44
+
45
+ ## Configuration
46
+
47
+ `rails_bootstrap_form` can be used without any configuration. However, `rails_bootstrap_form` does have an optional configuration file at `config/initializers/rails_bootstrap_form.rb` for setting options that affect all generated forms in an application. This configuration file is created using the generator
48
+ by running the command on the terminal.
49
+
50
+ ```
51
+ $ rails generate rails_bootstrap_form:install
52
+ ```
53
+
54
+ Example:
55
+
56
+ ```ruby
57
+ # config/initializers/rails_bootstrap_form.rb
58
+ RailsBootstrapForm.configure do |config|
59
+ # to make forms non-compliant with W3C.
60
+ config.default_form_attributes = {role: "form", novalidate: true}
61
+ end
62
+ ```
63
+
64
+ The current configuration options are:
65
+
66
+ | Option | Default value | Description |
67
+ |---------------------------|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
68
+ | `default_form_attributes` | | Set this option to `{role: "form"}` to make forms non-compliant with W3C, but generate the `role="form"` attribute. |
data/Rakefile CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
  require "bundler/gem_tasks"
6
6
  require "rspec/core/rake_task"
7
+ require_relative "demo/config/application"
7
8
 
9
+ Rails.application.load_tasks
8
10
  RSpec::Core::RakeTask.new(:spec)
9
11
 
10
12
  task default: :spec
@@ -20,3 +20,6 @@ label.required::after {
20
20
  display: inline-block;
21
21
  width: auto;
22
22
  }
23
+ .invalid-feedback {
24
+ display: block;
25
+ }
@@ -3,3 +3,5 @@
3
3
  <% end %>
4
4
 
5
5
  <%= render partial: "users/vertical_form" %>
6
+
7
+ <%= render partial: "users/horizontal_form" %>
@@ -0,0 +1,32 @@
1
+ <div class="card card-primary my-3">
2
+ <div class="card-header fw-bold">
3
+ Profile Form (Horizontal layout)
4
+ </div>
5
+ <div class="card-body">
6
+ <%= bootstrap_form_for @user, bootstrap_form: {layout: :horizontal} do |form| %>
7
+ <%= form.text_field :name, autocomplete: "new-name" %>
8
+ <%= form.email_field :email, autocomplete: "new-email" %>
9
+ <%= form.password_field :password, autocomplete: "new-password" %>
10
+ <%= form.phone_field :mobile_number %>
11
+ <%= form.date_field :birth_date %>
12
+ <%= form.range_field :excellence %>
13
+ <%= form.url_field :blog_url %>
14
+ <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id} %>
15
+ <%= form.color_field :favorite_color %>
16
+ <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name %>
17
+ <%= form.fields_for :address, include_id: false, bootstrap_form: {layout: :horizontal} do |address_form| %>
18
+ <%= address_form.text_area :street %>
19
+ <%= address_form.text_field :state %>
20
+ <%= address_form.grouped_collection_select :city, ::Country.includes(:cities), :cities, :name, :id, :name, {include_blank: "Select city"} %>
21
+ <%= address_form.text_field :postal_code %>
22
+ <%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
23
+ {include_blank: "Select Country"} %>
24
+ <% end %>
25
+ <%= form.check_box :terms, required: true %>
26
+ <div class="mt-3">
27
+ <%= form.submit "Register", class: "btn btn-primary" %>
28
+ <%= link_to "Cancel", users_path, class: "btn btn-secondary" %>
29
+ </div>
30
+ <% end %>
31
+ </div>
32
+ </div>
@@ -3,26 +3,26 @@
3
3
  Profile Form (Vertical layout)
4
4
  </div>
5
5
  <div class="card-body">
6
- <%= bootstrap_form_for @user, bootstrap_form: {} do |form| %>
7
- <%= form.text_field :name, autocomplete: "new-name", class: "dsds", bootstrap_form: {} %>
8
- <%= form.text_field :email, autocomplete: "new-email", bootstrap_form: {} %>
9
- <%= form.text_field :password, autocomplete: "new-password" %>
6
+ <%= bootstrap_form_for @user do |form| %>
7
+ <%= form.text_field :name, autocomplete: "new-name" %>
8
+ <%= form.email_field :email, autocomplete: "new-email" %>
9
+ <%= form.password_field :password, autocomplete: "new-password" %>
10
10
  <%= form.phone_field :mobile_number %>
11
11
  <%= form.date_field :birth_date %>
12
- <%= form.check_box :terms, bootstrap_form: {switch: false}, required: true %>
13
12
  <%= form.range_field :excellence %>
14
13
  <%= form.url_field :blog_url %>
15
- <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {bootstrap_form: {inline: true}, checked: form.object.fruit_id} %>
14
+ <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id} %>
16
15
  <%= form.color_field :favorite_color %>
17
- <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap_form: {inline: true}} %>
16
+ <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name %>
18
17
  <%= form.fields_for :address, include_id: false do |address_form| %>
19
18
  <%= address_form.text_area :street %>
20
19
  <%= address_form.text_field :state %>
21
20
  <%= address_form.grouped_collection_select :city, ::Country.includes(:cities), :cities, :name, :id, :name, {include_blank: "Select city"} %>
22
21
  <%= address_form.text_field :postal_code %>
23
22
  <%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
24
- {include_blank: "Select Country", bootstrap_form: {}} %>
23
+ {include_blank: "Select Country"} %>
25
24
  <% end %>
25
+ <%= form.check_box :terms, required: true %>
26
26
  <div class="mt-3">
27
27
  <%= form.submit "Register", class: "btn btn-primary" %>
28
28
  <%= link_to "Cancel", users_path, class: "btn btn-secondary" %>
@@ -1,25 +1,17 @@
1
- # SQLite. Versions 3.8.0 and up are supported.
2
- # gem install sqlite3
3
- #
4
- # Ensure the SQLite 3 gem is defined in your Gemfile
5
- # gem "sqlite3"
6
- #
7
1
  default: &default
8
- adapter: sqlite3
9
- pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10
- timeout: 5000
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ reconnect: false
5
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 20 } %>
11
6
 
12
7
  development:
13
8
  <<: *default
14
- database: db/development.sqlite3
9
+ url: <%= ENV["DATABASE_URL"] %>
15
10
 
16
- # Warning: The database defined as "test" will be erased and
17
- # re-generated from your development database when you run "rake".
18
- # Do not set this db to the same as development or production.
19
11
  test:
20
12
  <<: *default
21
- database: db/test.sqlite3
13
+ url: <%= ENV["DATABASE_URL"] %>
22
14
 
23
15
  production:
24
16
  <<: *default
25
- database: db/production.sqlite3
17
+ url: <%= ENV["DATABASE_URL"] %>
data/demo/db/schema.rb CHANGED
@@ -11,8 +11,11 @@
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
13
  ActiveRecord::Schema[7.0].define(version: 2023_05_16_044126) do
14
+ # These are extensions that must be enabled in order to support this database
15
+ enable_extension "plpgsql"
16
+
14
17
  create_table "addresses", primary_key: "user_id", force: :cascade do |t|
15
- t.integer "country_id"
18
+ t.bigint "country_id"
16
19
  t.string "street"
17
20
  t.string "city"
18
21
  t.string "state"
@@ -25,7 +28,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_16_044126) do
25
28
 
26
29
  create_table "cities", force: :cascade do |t|
27
30
  t.string "name"
28
- t.integer "country_id"
31
+ t.bigint "country_id"
29
32
  t.datetime "created_at", null: false
30
33
  t.datetime "updated_at", null: false
31
34
  t.index ["country_id"], name: "index_cities_on_country_id"
@@ -50,8 +53,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_16_044126) do
50
53
  end
51
54
 
52
55
  create_table "user_skills", force: :cascade do |t|
53
- t.integer "user_id"
54
- t.integer "skill_id"
56
+ t.bigint "user_id"
57
+ t.bigint "skill_id"
55
58
  t.datetime "created_at", null: false
56
59
  t.datetime "updated_at", null: false
57
60
  t.index ["skill_id"], name: "index_user_skills_on_skill_id"
@@ -65,7 +68,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_16_044126) do
65
68
  t.string "mobile_number"
66
69
  t.string "blog_url"
67
70
  t.date "birth_date"
68
- t.integer "fruit_id"
71
+ t.bigint "fruit_id"
69
72
  t.boolean "terms"
70
73
  t.string "excellence"
71
74
  t.string "favorite_color"
@@ -15,8 +15,8 @@ gem "sassc-rails"
15
15
  # Add bootstrap support
16
16
  gem "bootstrap", "~> 5.3.0.alpha3"
17
17
 
18
- # Use sqlite3 as the database for Active Record
19
- gem "sqlite3", "~> 1.4"
18
+ # Use postgresql as the database for Active Record
19
+ gem "pg", "~> 1.1"
20
20
 
21
21
  # Library to show coverage of the code.
22
22
  gem "simplecov"
@@ -25,6 +25,14 @@ group :development do
25
25
  gem "puma"
26
26
  end
27
27
 
28
+ group :test do
29
+ # make it easy and painless to work with XML and HTML from Ruby.
30
+ gem "nokogiri"
31
+
32
+ # Solve your XML/HTML comparison or diffing needs.
33
+ gem "compare-xml"
34
+ end
35
+
28
36
  group :development, :test do
29
37
  gem "byebug"
30
38
  end
@@ -6,7 +6,7 @@ module RailsBootstrapForm
6
6
  class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
7
7
 
8
8
  include RailsBootstrapForm::FieldWrapperBuilder
9
- include RailsBootstrapForm::Components
9
+ include RailsBootstrapForm::Helpers
10
10
  include RailsBootstrapForm::InputGroupBuilder
11
11
  include RailsBootstrapForm::Inputs
12
12
 
@@ -50,8 +50,9 @@ module RailsBootstrapForm
50
50
  # readers. Default is `visually-hidden`
51
51
  attr_accessor :hide_class
52
52
 
53
- # Default CSS class that will be applied to all label tags.
54
- # Default is `form-label`.
53
+ # Default CSS class that will be applied to all label tags when layout is
54
+ # vertical.
55
+ # The default value is `form-label`.
55
56
  attr_accessor :label_class
56
57
 
57
58
  # An additional CSS class that will be added along with the existing
@@ -105,6 +106,19 @@ module RailsBootstrapForm
105
106
  # form.collection_radio_buttons :choices, ["yes", "no"], :to_s, :to_s, bootstrap_form: {inline: true}
106
107
  attr_accessor :inline
107
108
 
109
+ # Default CSS class that will be applied to all label tags when layout is
110
+ # horizontal.
111
+ # The default value is `col-form-label`.
112
+ attr_accessor :label_col_class
113
+
114
+ # Default CSS class for label column when using horizontal form.
115
+ # The default value is `col-sm-2`.
116
+ attr_accessor :label_col_wrapper_class
117
+
118
+ # Default CSS class for control column when using horizontal form.
119
+ # The default value is `col-sm-10`.
120
+ attr_accessor :field_col_wrapper_class
121
+
108
122
  def initialize(options = {})
109
123
  set_defaults
110
124
  set_bootstrap_form_options(options)
@@ -131,7 +145,7 @@ module RailsBootstrapForm
131
145
  # to a given form field. For example, we can change grid just for one field:
132
146
  #
133
147
  # bootstrap_form_with model: @user do |f|
134
- # f.text_field :email, bootstrap_form: {label_col_class: "col-md-6", control_col_class: "col-md-6"}
148
+ # f.text_field :email, bootstrap_form: {label_col_wrapper_class: "col-md-6", field_col_wrapper_class: "col-md-6"}
135
149
  # f.password_field :password
136
150
  # end
137
151
  #
@@ -173,6 +187,10 @@ module RailsBootstrapForm
173
187
  @size = nil
174
188
 
175
189
  @inline = false
190
+
191
+ @label_col_class = "col-form-label"
192
+ @label_col_wrapper_class = "col-sm-2"
193
+ @field_col_wrapper_class = "col-sm-10"
176
194
  end
177
195
 
178
196
  private :set_defaults
@@ -16,35 +16,49 @@ module RailsBootstrapForm
16
16
  label = draw_label(attribute, options, bootstrap_options)
17
17
  help_text = help_text(attribute, bootstrap_options)
18
18
 
19
- if bootstrap_options.floating
19
+ if bootstrap_options.layout_horizontal?
20
20
  tag.div(**field_wrapper_options(bootstrap_options)) do
21
- concat(input_group_wrapper(attribute, bootstrap_options) do
22
- tag.div(class: floating_label_classes(attribute)) do
23
- concat(capture(&block))
24
- concat(label)
25
- end
21
+ concat(label)
22
+ concat(tag.div(class: bootstrap_options.field_col_wrapper_class) do
23
+ concat(input_group_wrapper(attribute, bootstrap_options) do
24
+ capture(&block)
25
+ end)
26
+ concat(help_text)
26
27
  end)
27
- concat(help_text)
28
28
  end
29
29
  else
30
- tag.div(**field_wrapper_options(bootstrap_options)) do
31
- concat(label)
32
- concat(input_group_wrapper(attribute, bootstrap_options) do
33
- capture(&block)
34
- end)
35
- concat(help_text)
30
+ if bootstrap_options.floating
31
+ tag.div(**field_wrapper_options(bootstrap_options)) do
32
+ concat(input_group_wrapper(attribute, bootstrap_options) do
33
+ tag.div(class: floating_label_classes(attribute)) do
34
+ concat(capture(&block))
35
+ concat(label)
36
+ end
37
+ end)
38
+ concat(help_text)
39
+ end
40
+ else
41
+ tag.div(**field_wrapper_options(bootstrap_options)) do
42
+ concat(label)
43
+ concat(input_group_wrapper(attribute, bootstrap_options) do
44
+ capture(&block)
45
+ end)
46
+ concat(help_text)
47
+ end
36
48
  end
37
49
  end
38
50
  end
39
51
 
40
52
  def field_wrapper_options(bootstrap_options)
41
53
  {}.tap do |option|
42
- option[:class] = field_wrapper_classes
54
+ option[:class] = field_wrapper_classes(bootstrap_options)
43
55
  end.merge(bootstrap_options.wrapper_options)
44
56
  end
45
57
 
46
- def field_wrapper_classes
47
- classes = [form_wrapper_default_class]
58
+ def field_wrapper_classes(bootstrap_options)
59
+ classes = []
60
+ classes << "row" if bootstrap_options.layout_horizontal?
61
+ classes << form_wrapper_default_class
48
62
  classes.flatten.compact
49
63
  end
50
64
 
@@ -68,7 +82,7 @@ module RailsBootstrapForm
68
82
  css_options[:class] = field_classes.flatten.compact
69
83
  css_options.merge!(required_field_options(attribute, options))
70
84
 
71
- if bootstrap_options.floating
85
+ if (bootstrap_options.floating && !bootstrap_options.layout_horizontal?)
72
86
  css_options[:placeholder] ||= label_text(attribute, bootstrap_options)
73
87
  end
74
88
 
@@ -3,7 +3,7 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- module Components
6
+ module Helpers
7
7
  module CheckBox
8
8
  extend ActiveSupport::Concern
9
9
 
@@ -62,11 +62,18 @@ module RailsBootstrapForm
62
62
  classes = Array("form-check")
63
63
  classes << "form-switch" if bootstrap_options.switch
64
64
  classes << "form-check-inline" if bootstrap_options.inline?
65
- classes << "mb-3"
65
+ classes << "mb-3" unless (bootstrap_options.layout_horizontal? || bootstrap_options.inline?)
66
66
  classes.flatten.compact
67
67
  end
68
68
 
69
- private :check_box_label, :check_box_classes, :check_box_label_class, :check_box_wrapper_class
69
+ def check_box_container_classes(bootstrap_options)
70
+ classes = Array(bootstrap_options.field_col_wrapper_class)
71
+ classes << field_offset_class(bootstrap_options.label_col_wrapper_class)
72
+ classes.flatten.compact
73
+ end
74
+
75
+ private :check_box_label, :check_box_classes, :check_box_label_class,
76
+ :check_box_wrapper_class, :check_box_container_classes
70
77
  end
71
78
  end
72
79
  end
@@ -3,7 +3,7 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- module Components
6
+ module Helpers
7
7
  module Errors
8
8
  extend ActiveSupport::Concern
9
9
 
@@ -3,7 +3,7 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- module Components
6
+ module Helpers
7
7
  module HelpText
8
8
  extend ActiveSupport::Concern
9
9
 
@@ -3,7 +3,7 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- module Components
6
+ module Helpers
7
7
  module Labels
8
8
  extend ActiveSupport::Concern
9
9
 
@@ -21,7 +21,13 @@ module RailsBootstrapForm
21
21
  end
22
22
 
23
23
  def label_classes(attribute, bootstrap_options)
24
- classes = [bootstrap_options.label_class, bootstrap_options.additional_label_class]
24
+ classes = []
25
+ classes << if bootstrap_options.layout_horizontal?
26
+ [bootstrap_options.label_col_class, bootstrap_options.label_col_wrapper_class]
27
+ else
28
+ bootstrap_options.label_class
29
+ end
30
+ classes << bootstrap_options.additional_label_class
25
31
  classes << bootstrap_options.hide_class if bootstrap_options.hide_label
26
32
  classes << "required" if is_attribute_required?(attribute)
27
33
  classes << "is-invalid" if is_invalid?(attribute)