rails_bootstrap_form 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23429dc16ad64529ba65b78cf376ff4bb5b31134bb87b1f8808af1fd32fe0427
4
- data.tar.gz: 83785c866c4705460b55cbad301971492f360407b4d91abf49e0f11d25f07070
3
+ metadata.gz: 8bb2a8a391176d2d0e578b3ce1591c6f1f996cc8f5ebbb1ad6fcaddf9087be7e
4
+ data.tar.gz: a995a9c68d6509edc9f3327674783fb85c831f0107e269fc1ffbd75b98438b04
5
5
  SHA512:
6
- metadata.gz: 3be8e0f60800ddd2fabf8b6db7a5d2d996bb45c932f184578448e4525bddd85d87f798b69dbc13787e04e87d2d2ed53dcabd4f9e78f97914247379a83237bafb
7
- data.tar.gz: 2ab6a13c6b251556033636c06baa061b4379b8acea6461e1b6a36ddda9fd85a8892b322c660aa7d68e2377f6271250fa28fe35691c7f35a5001e5b928597d21f
6
+ metadata.gz: 62c3811ebcb7356b7e5333c48146f2f2958aa16ecefc71cd7c9a05dcb1bafac659d019484e26a1bb5b0e901d1cbc041b9d88509816cb270a6ceb11a870252a12
7
+ data.tar.gz: d395785a7267dd780584e0ca968faf265e9ca5d637e206d66fa46a7c77da69b71314ae397b02a5a8b6e4bb6cb1cbc79dfcecf62ddbc11b2951af733668ee2a8e
data/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ You can find recent releases with docs in GitHub:
4
4
 
5
5
  https://github.com/shivam091/rails_bootstrap_form/releases
6
6
 
7
+ ## [0.9.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.2...v0.9.3) - 2023-06-04
8
+
9
+ ### What's changed
10
+
11
+ - Disabled floating labels for unsupported helpers
12
+
13
+ ### What's fixed
14
+
15
+ - `id` of check box field when used in collection and don't has multiple select. (`collection_check_boxes` with `multiple: false`)
16
+
7
17
  ## [0.9.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.1...v0.9.2) - 2023-06-03
8
18
 
9
19
  ### What's new
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,146 @@
1
+ # Contributing
2
+
3
+ Thank you so much for considering a contribution to `rails_bootstrap_form`. We love pull requests!
4
+
5
+ We want everyone to feel welcome to contribute. We encourage respectful exchanges of ideas. We govern ourselves with the Contributor Covenant [Code of Conduct](/CODE_OF_CONDUCT.md).
6
+
7
+ There are a number of ways you can contribute to `rails_bootstrap_form`:
8
+
9
+ - Fix a bug or add a new feature
10
+ - Add to the documentation
11
+ - Review pull requests
12
+
13
+ ## Code Contributions
14
+
15
+ Here's a quick guide for code contributions:
16
+
17
+ ### 1. Check if issue or feature is available to work on
18
+
19
+ Make sure no one else is working on the same issue or feature. Search the issues
20
+ and pull requests for anything that looks like the issue or feature you want to
21
+ address. If no one else is working on your issue or feature, carry on with the
22
+ following steps.
23
+
24
+ ### 2. Create an issue, and wait a few days for someone to respond (Optional)
25
+
26
+ If you create an issue for your feature request or bug, it gives the maintainers a chance to comment on your ideas before you invest a lot of work on a contribution. It may save you some re-work compared to simply submitting a pull request. It's up to you whether you submit an issue.
27
+
28
+ ### 3. Fork the repo
29
+
30
+ Fork the project. Optionally, create a branch you want to work on.
31
+
32
+ ### 4. Get it running locally
33
+
34
+ - Install the required dependencies with `bundle install`
35
+ - Run tests via: `bundle exec rake`
36
+
37
+ ### 5. Hack away
38
+
39
+ - Try to keep your changes small. Consider making several smaller pull requests if your changes are extensive.
40
+ - Don't forget to add necessary tests and make sure that all tests run successfully.
41
+ - Update the README if necessary.
42
+ - Add a line to the CHANGELOG for your bug fix or feature.
43
+ - Read the [Coding Guidelines](#coding-guidelines) section and make sure that `bundle exec rubocop --autocorrect` doesn't find any offences.
44
+
45
+ You may find the [demo application](#the-demo-application) useful for development and debugging.
46
+
47
+ ### 6. Make a pull request
48
+
49
+ - If you've never made a pull request (PR) before, read [this](https://help.github.com/articles/about-pull-requests/).
50
+ - If your PR fixes an issues, be sure to put "Fixes #nnn" in the description of the PR (where `nnn` is the issue number). Github will automatically close the issue when the PR is merged.
51
+ - When the PR is submitted, check if Travis CI ran all the tests successfully, and didn't raise any issues.
52
+
53
+ ### 7. Done
54
+
55
+ Somebody will shortly review your pull request and if everything is good, it will be
56
+ merged into the main branch. Eventually the gem will be published with your changes.
57
+
58
+ ### Coding guidelines
59
+
60
+ This project uses [RuboCop](https://github.com/bbatsov/rubocop) to enforce standard Ruby coding guidelines.
61
+
62
+ - Test that your contribution passes with `bundle exec rubocop`.
63
+ - RuboCop is also run as part of the full test suite with `bundle exec rake`.
64
+ - Note the Travis build will fail and your PR cannot be merged if RuboCop finds offences.
65
+
66
+ Note that most editors have plugins to run RuboCop as you type, or when you save a file. You may find it well worth your time to install and configure the RuboCop plugin for your editor. Read the [RuboCop documentation](https://rubocop.readthedocs.io/en/latest/integration_with_other_tools/).
67
+
68
+ ### Supported Versions of Ruby and Rails
69
+
70
+ The goal of `rails_bootstrap_form` is to support all versions of Rails (higher than 7.0) for bug fixes and security issues. We do not test against versions supported for severe security issues. We test against the minimum [version of Ruby required](https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#ruby-versions) for those versions of Rails.
71
+
72
+ The Ruby on Rails support policy is [here](https://guides.rubyonrails.org/maintenance_policy.html).
73
+
74
+ ### The Demo Application
75
+
76
+ There is a demo app in this repository. It shows some of the features of `rails_bootstrap_form`, and provides a base on which to build ad-hoc testing, if you need it.
77
+
78
+ Currently, the demo app is only set up to run for Rails 7, due to the variety of ways to include CSS and JavaScript in a modern Rails application.
79
+ To run the demo app, set up the database and run the server:
80
+
81
+ ```bash
82
+ cd demo
83
+ bundle
84
+ rails db:create
85
+ rails db:migrate
86
+ ```
87
+
88
+ You'll see errors in the browser console about duplicate ids. This is expected, since the demo app has many forms with the same fields in them. Something we can fix in the future, perhaps.
89
+
90
+ To use other supported versions of Rails, you will need to create a `Gemfile` for the Rails version. Then, change the `export BUNDLE_GEMFILE...` line to your gem file. Finally, figure out how to include the assets.
91
+
92
+ If you need to run the Rails server separately, for example, to debug the server, you _must_ run it like this:
93
+
94
+ ```sh
95
+ bundle exec rails s -b 0.0.0.0
96
+ ```
97
+
98
+ If you run just `rails` or even `bin/rails`, the `sprockets-rails` gem won't load and you'll either get error messages, or the assets won't be available to the demo app. At the moment it's a mystery why. PRs to fix this are welcome.
99
+
100
+ Please try to keep the checked-in `.ruby-version` set to the oldest supported version of Ruby. You're welcome and encouraged to try the demo app with other Ruby versions. Just don't check in the `.ruby-version` to GitHub.
101
+
102
+ ## Documentation Contributions
103
+
104
+ Contributions to documentation are always welcome. Even fixing one typo improves the quality of `rails_bootstrap_form`. To make a documentation contribution, follow steps 1-3 of Code Contributions, then make the documentation changes, then make the pull request (step 6 of Code Contributions).
105
+
106
+ If you put `[ci skip]` in the commit message of the most recent commit of the PR, you'll be a good citizen by not causing our CI pipeline to run all the tests when it's not necessary.
107
+
108
+ ## Reviewing Pull Requests
109
+
110
+ We are an entirely volunteer project. Sometimes it's hard for people to find the time to review pull requests. You can help! If you see a pull request that's waiting to be merged, it could be because no one has reviewed it yet. Your review could help move the pull request forward to be merged.
111
+
112
+ ---
113
+
114
+ Thanks to all the [great contributors](https://github.com/shivam091/rails_bootstrap_form/graphs/contributors).
115
+
116
+ ## Troubleshooting
117
+
118
+ ### Models and Database Tables
119
+
120
+ `rails_bootstrap_form` needs few models and tables to support testing. It appears that the necessary tables were created via the `demo/db/schema.rb` file. To support `rich_text_area`, Rails 7 creates some migrations. These migrations had to be run in the existing database (not an empty one) to create a new `schema.rb` that creates the `rails_bootstrap_form` test tables, and the tables needed by Rails 7. The `schema.rb` file was checked in to GitHub.
121
+
122
+ In the future, any new Rails functionality that creates tables would likely have to be prepared the same way:
123
+
124
+ ```bash
125
+ cd demo
126
+ rails db:create
127
+ rails db:migrate
128
+ ```
129
+
130
+ ### RuboCop
131
+
132
+ When you push a branch, RuboCop checks may fail, but locally you can't reproduce the failure. This may be because you're using a different version of RuboCop locally. When you push, the RuboCop tests use the currently available version of RuboCop. If you've been working on the branch for a while, it's likely you have a `Gemfile.lock` that specifies an older version of RuboCop.
133
+
134
+ The first thing to try is to update your `Gemfile.lock` locally:
135
+
136
+ ```bash
137
+ bundle update
138
+ ```
139
+
140
+ Or, if you really want to minimize your work:
141
+
142
+ ```bash
143
+ bundle update --conservative rubocop
144
+ ```
145
+
146
+ This should enable you to reproduce the RuboCop failures locally, and then you can fix them.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_form (0.9.2)
4
+ rails_bootstrap_form (0.9.3)
5
5
  actionpack (~> 7.0)
6
6
  activemodel (~> 7.0)
7
7
 
data/README.md CHANGED
@@ -688,7 +688,7 @@ Here's an example of how you pass the arguments for each form helper:
688
688
  ### check_box
689
689
 
690
690
  Our `check_box` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-check_box).
691
- This helper will render check box and label for you.
691
+ except it don't accept a `block` as an argument and renders check box and label for you.
692
692
 
693
693
  ![check_box](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/5836650c-d536-4f4e-b768-75bca9dd7901)
694
694
 
@@ -1435,7 +1435,7 @@ This generates the following HTML:
1435
1435
 
1436
1436
  ### collection_check_boxes
1437
1437
 
1438
- This helper provides a way to create collection of check boxes. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes) except it don't accept a block as
1438
+ This helper provides a way to create collection of check boxes. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_check_boxes) except it don't accept a `block` as
1439
1439
  an argument and takes care of rendering labels, check boxes, and wrapper for you.
1440
1440
 
1441
1441
  ![collection_check_boxes](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c92f5921-e572-4384-812e-31308e018f66)
@@ -1500,7 +1500,7 @@ This generates the following HTML:
1500
1500
 
1501
1501
  ### collection_radio_buttons
1502
1502
 
1503
- This helper provides a way to create collection of radio buttons. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_radio_buttons) except it don't accept a block as
1503
+ This helper provides a way to create collection of radio buttons. This helper accepts same arguments as [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_radio_buttons) except it don't accept a `block` as
1504
1504
  an argument and takes care of rendering labels, radio button, and wrapper for you.
1505
1505
 
1506
1506
  ![collection_radio_buttons](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/798a8b0c-915a-40b1-9874-dd74f50d3695)
@@ -1850,6 +1850,8 @@ This generates the following HTML:
1850
1850
  </form>
1851
1851
  ```
1852
1852
 
1853
+ _Floating labels gets disabled by `rails_bootstrap_form` automatically for unsupported helpers._
1854
+
1853
1855
  ## Validation and Errors
1854
1856
 
1855
1857
  By default, `rails_bootstrap_form` generations in-line errors which appear below the field.
@@ -0,0 +1,81 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Helpers
7
+ module Choice
8
+ extend ActiveSupport::Concern
9
+
10
+ def self.included(base_class)
11
+ [:check_box, :radio_button].each do |tag_name|
12
+ define_method("#{tag_name}_label") do |attribute, value, options, bootstrap|
13
+ label_options = {
14
+ class: choice_label_classes(attribute, bootstrap, options)
15
+ }
16
+ label_options[:value] = value if tag_name.eql?(:radio_button)
17
+ label_options[:for] = options[:id] if options[:id].present?
18
+
19
+ label_text = label_text(attribute, bootstrap)
20
+
21
+ label(attribute, label_text, label_options)
22
+ end
23
+ end
24
+
25
+ [:check_box, :radio_button].each do |tag_name|
26
+ define_method("bootstrap_#{tag_name}") do |attribute, value, options, bootstrap|
27
+ options[:class] = choice_classes(attribute, options)
28
+
29
+ if tag_name.eql?(:check_box)
30
+ choice_field = check_box_without_bootstrap(attribute, options, value, nil)
31
+ choice_label = check_box_label(attribute, value, options, bootstrap)
32
+ else
33
+ choice_field = radio_button_without_bootstrap(attribute, value, options)
34
+ choice_label = radio_button_label(attribute, value, options, bootstrap)
35
+ end
36
+
37
+ choice_field + choice_label
38
+ end
39
+ end
40
+
41
+ def choice_classes(attribute, options)
42
+ classes = Array("form-check-input") << options[:class]
43
+ classes << "is-invalid" if is_invalid?(attribute)
44
+ classes.flatten.compact
45
+ end
46
+
47
+ def choice_label_classes(attribute, bootstrap, options)
48
+ classes = Array("form-check-label") << bootstrap.additional_label_class
49
+ classes << "required" if is_field_required?(attribute, options)
50
+ classes << "is-invalid" if is_invalid?(attribute)
51
+ classes << bootstrap.hide_class if bootstrap.hide_label?
52
+ classes.flatten.compact
53
+ end
54
+
55
+ def choice_container_classes(bootstrap)
56
+ classes = Array(bootstrap.field_col_wrapper_class)
57
+ classes << field_offset_class(bootstrap.label_col_wrapper_class)
58
+ classes.flatten.compact
59
+ end
60
+
61
+ def choice_wrapper_classes(bootstrap)
62
+ classes = Array("form-check")
63
+ classes << "form-check-inline" if bootstrap.inline?
64
+ classes << "form-switch" if bootstrap.switch?
65
+ classes.flatten.compact
66
+ end
67
+
68
+ def collection_input_checked?(checked, obj, input_value)
69
+ checked == input_value || Array(checked).try(:include?, input_value) ||
70
+ checked == obj || Array(checked).try(:include?, obj)
71
+ end
72
+
73
+ private :choice_classes, :choice_label_classes,
74
+ :choice_container_classes, :choice_wrapper_classes,
75
+ :check_box_label, :radio_button_label,
76
+ :bootstrap_check_box, :bootstrap_radio_button,
77
+ :collection_input_checked?
78
+ end
79
+ end
80
+ end
81
+ end
@@ -11,22 +11,21 @@ module RailsBootstrapForm
11
11
  autoload :Labels
12
12
  autoload :RequiredField
13
13
  autoload :Errors
14
- autoload :CheckBox
15
- autoload :RadioButton
16
14
  autoload :Buttons
15
+ autoload :Choice
17
16
 
18
17
  include HelpText
19
18
  include Labels
20
19
  include RequiredField
21
20
  include Errors
22
- include CheckBox
23
- include RadioButton
24
21
  include Buttons
22
+ include Choice
25
23
 
26
24
  def self.included(base_class)
27
- def collection_input_checked?(checked, obj, input_value)
28
- checked == input_value || Array(checked).try(:include?, input_value) ||
29
- checked == obj || Array(checked).try(:include?, obj)
25
+ def sanitized_tag_name(attribute, value)
26
+ # label's `for` attribute needs to match checkbox/radio button tag's id, IE sanitized value, IE
27
+ # https://github.com/rails/rails/blob/5-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L123-L125
28
+ "#{@object_name}_#{attribute}_#{value.to_s.gsub(/\s/, "_").gsub(/[^-[[:word:]]]/, "").mb_chars.downcase}"
30
29
  end
31
30
 
32
31
  def control_specific_class(field_tag_name)
@@ -52,8 +51,8 @@ module RailsBootstrapForm
52
51
  options.delete(:class) if options[:class].blank?
53
52
  end
54
53
 
55
- private :collection_input_checked?, :control_specific_class, :is_size_valid?,
56
- :add_css_class!, :remove_css_class!
54
+ private :control_specific_class, :is_size_valid?, :add_css_class!,
55
+ :remove_css_class!
57
56
  end
58
57
  end
59
58
  end
@@ -13,12 +13,14 @@ module RailsBootstrapForm
13
13
 
14
14
  collection.each do |object|
15
15
  value = object.send(value_method)
16
+
16
17
  input_options = {
17
18
  bootstrap: {
18
19
  label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
19
20
  inline: bootstrap.inline?
20
21
  },
21
- required: false
22
+ required: false,
23
+ id: sanitized_tag_name(attribute, value)
22
24
  }.deep_merge!(options)
23
25
 
24
26
  if (checked = input_options[:checked])
@@ -35,8 +37,8 @@ module RailsBootstrapForm
35
37
  end
36
38
 
37
39
  class_methods do
38
- def bootstrap_field(field_name)
39
- define_method(field_name) do |attribute, options = {}|
40
+ def bootstrap_field(tag_name)
41
+ define_method(tag_name) do |attribute, options = {}|
40
42
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
41
43
  return super(attribute, options) if bootstrap.disabled?
42
44
 
@@ -46,15 +48,15 @@ module RailsBootstrapForm
46
48
  end
47
49
  end
48
50
 
49
- def bootstrap_select_group(field_name)
50
- define_method(field_name) do |attribute, options = {}, html_options = {}|
51
- options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options)
51
+ def bootstrap_select_group(tag_name)
52
+ define_method(tag_name) do |attribute, options = {}, html_options = {}|
53
+ options = {bootstrap: {field_class: "form-select", floating: false}}.deep_merge!(options)
52
54
 
53
55
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
54
56
  return super(attribute, options, html_options) if bootstrap.disabled?
55
57
 
56
58
  field_wrapper_builder(attribute, bootstrap, options, html_options) do
57
- tag.fieldset(class: control_specific_class(field_name)) do
59
+ tag.fieldset(class: control_specific_class(tag_name)) do
58
60
  super(attribute, options, html_options)
59
61
  end
60
62
  end
@@ -8,11 +8,11 @@ module RailsBootstrapForm
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
- def check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0", &block)
11
+ def check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0")
12
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
13
  return super if bootstrap.disabled?
14
14
 
15
- check_box_html = tag.div(class: check_box_wrapper_classes(bootstrap)) do
15
+ check_box_html = tag.div(class: choice_wrapper_classes(bootstrap)) do
16
16
  concat(bootstrap_check_box(attribute, checked_value, options, bootstrap))
17
17
  concat(help_text(attribute, bootstrap))
18
18
  concat(generate_error(attribute)) if is_invalid?(attribute)
@@ -21,7 +21,7 @@ module RailsBootstrapForm
21
21
  if bootstrap.wrapper
22
22
  tag.div(**field_wrapper_options(bootstrap)) do
23
23
  if bootstrap.layout_horizontal?
24
- tag.div(class: check_box_container_classes(bootstrap)) { check_box_html }
24
+ tag.div(class: choice_container_classes(bootstrap)) { check_box_html }
25
25
  else
26
26
  check_box_html
27
27
  end
@@ -10,16 +10,15 @@ module RailsBootstrapForm
10
10
  included do
11
11
  def collection_check_boxes(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ bootstrap.floating = false
13
14
  return super if bootstrap.disabled?
14
15
 
15
16
  inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap, options) do |attribute, value, options|
16
17
  bootstrap_opts = bootstrap_form_options.scoped(options.delete(:bootstrap))
17
18
 
18
- check_box_html = tag.div(class: check_box_wrapper_classes(bootstrap_opts)) do
19
+ tag.div(class: choice_wrapper_classes(bootstrap_opts)) do
19
20
  bootstrap_check_box(attribute, value, options, bootstrap_opts)
20
21
  end
21
-
22
- check_box_html
23
22
  end
24
23
 
25
24
  if options.delete(:include_hidden) { true }
@@ -10,16 +10,15 @@ module RailsBootstrapForm
10
10
  included do
11
11
  def collection_radio_buttons(attribute, collection, value_method, text_method, options = {}, html_options = {})
12
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
+ bootstrap.floating = false
13
14
  return super if bootstrap.disabled?
14
15
 
15
16
  inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap, options) do |attribute, value, options|
16
17
  bootstrap_opts = bootstrap_form_options.scoped(options.delete(:bootstrap))
17
18
 
18
- bootstrap_radio_html = tag.div(class: radio_button_wrapper_classes(bootstrap_opts)) do
19
+ tag.div(class: choice_wrapper_classes(bootstrap_opts)) do
19
20
  bootstrap_radio_button(attribute, value, options, bootstrap_opts)
20
21
  end
21
-
22
- bootstrap_radio_html
23
22
  end
24
23
 
25
24
  field_wrapper_builder(attribute, bootstrap, options, html_options) do
@@ -9,7 +9,12 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def color_field(attribute, options = {})
12
- options = {bootstrap: {field_class: "form-control form-control-color"}}.deep_merge!(options)
12
+ options = {
13
+ bootstrap: {
14
+ field_class: "form-control form-control-color",
15
+ floating: false
16
+ }
17
+ }.deep_merge!(options)
13
18
 
14
19
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
20
  return super if bootstrap.disabled?
@@ -12,7 +12,7 @@ module RailsBootstrapForm
12
12
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
13
  return super if bootstrap.disabled?
14
14
 
15
- radio_button_html = tag.div(class: radio_button_wrapper_classes(bootstrap)) do
15
+ radio_button_html = tag.div(class: choice_wrapper_classes(bootstrap)) do
16
16
  concat(bootstrap_radio_button(attribute, value, options, bootstrap))
17
17
  concat(help_text(attribute, bootstrap))
18
18
  concat(generate_error(attribute)) if is_invalid?(attribute)
@@ -21,7 +21,7 @@ module RailsBootstrapForm
21
21
  if bootstrap.wrapper
22
22
  tag.div(**field_wrapper_options(bootstrap)) do
23
23
  if bootstrap.layout_horizontal?
24
- tag.div(class: radio_button_container_classes(bootstrap)) { radio_button_html }
24
+ tag.div(class: choice_container_classes(bootstrap)) { radio_button_html }
25
25
  else
26
26
  radio_button_html
27
27
  end
@@ -9,7 +9,7 @@ module RailsBootstrapForm
9
9
 
10
10
  included do
11
11
  def range_field(attribute, options = {})
12
- options = {bootstrap: {field_class: "form-range"}}.deep_merge!(options)
12
+ options = {bootstrap: {field_class: "form-range", floating: false}}.deep_merge!(options)
13
13
 
14
14
  bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap))
15
15
  return super if bootstrap.disabled?
@@ -3,6 +3,6 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- VERSION = "0.9.2".freeze
6
+ VERSION = "0.9.3".freeze
7
7
  REQUIRED_RAILS_VERSION = "~> 7.0".freeze
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_bootstrap_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harshal LADHE (shivam091)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-03 00:00:00.000000000 Z
11
+ date: 2023-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: generator_spec
@@ -63,6 +63,7 @@ files:
63
63
  - ".rspec"
64
64
  - CHANGELOG.md
65
65
  - CODE_OF_CONDUCT.md
66
+ - CONTRIBUTING.md
66
67
  - Gemfile
67
68
  - Gemfile.lock
68
69
  - LICENSE.txt
@@ -146,11 +147,10 @@ files:
146
147
  - lib/rails_bootstrap_form/field_wrapper_builder.rb
147
148
  - lib/rails_bootstrap_form/helpers.rb
148
149
  - lib/rails_bootstrap_form/helpers/buttons.rb
149
- - lib/rails_bootstrap_form/helpers/check_box.rb
150
+ - lib/rails_bootstrap_form/helpers/choice.rb
150
151
  - lib/rails_bootstrap_form/helpers/errors.rb
151
152
  - lib/rails_bootstrap_form/helpers/help_text.rb
152
153
  - lib/rails_bootstrap_form/helpers/labels.rb
153
- - lib/rails_bootstrap_form/helpers/radio_button.rb
154
154
  - lib/rails_bootstrap_form/helpers/required_field.rb
155
155
  - lib/rails_bootstrap_form/input_group_builder.rb
156
156
  - lib/rails_bootstrap_form/inputs.rb
@@ -1,82 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- # -*- frozen_string_literal: true -*-
3
- # -*- warn_indent: true -*-
4
-
5
- module RailsBootstrapForm
6
- module Helpers
7
- module CheckBox
8
- extend ActiveSupport::Concern
9
-
10
- def self.included(base_class)
11
- def check_box_label(attribute, checked_value, options, bootstrap, &block)
12
- unless bootstrap.skip_label?
13
- label_options = {
14
- class: check_box_label_class(attribute, bootstrap, options)
15
- }
16
- label_options[:for] = options[:id] if options[:id].present?
17
-
18
- label_name = if options[:multiple]
19
- check_box_value(attribute, checked_value)
20
- else
21
- attribute
22
- end
23
-
24
- label_text = check_box_label_text(attribute, options, bootstrap, &block)
25
-
26
- label(label_name, label_text, label_options)
27
- end
28
- end
29
-
30
- def check_box_label_text(attribute, options, bootstrap, &block)
31
- block ? capture(&block) : label_text(attribute, bootstrap)
32
- end
33
-
34
- def check_box_value(attribute, value)
35
- # label's `for` attribute needs to match checkbox tag's id,
36
- # IE sanitized value, IE
37
- # https://github.com/rails/rails/blob/5-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L123-L125
38
- "#{attribute}_#{value.to_s.gsub(/\s/, "_").gsub(/[^-[[:word:]]]/, "").mb_chars.downcase}"
39
- end
40
-
41
- def check_box_classes(attribute, options)
42
- classes = Array(options[:class]) << "form-check-input"
43
- classes << "is-invalid" if is_invalid?(attribute)
44
- classes.flatten.compact
45
- end
46
-
47
- def check_box_label_class(attribute, bootstrap, options)
48
- classes = Array("form-check-label") << bootstrap.additional_label_class
49
- classes << "required" if is_field_required?(attribute, options)
50
- classes << "is-invalid" if is_invalid?(attribute)
51
- classes << bootstrap.hide_class if bootstrap.hide_label?
52
- classes.flatten.compact
53
- end
54
-
55
- def check_box_wrapper_classes(bootstrap)
56
- classes = Array("form-check")
57
- classes << "form-switch" if bootstrap.switch?
58
- classes << "form-check-inline" if bootstrap.inline?
59
- classes.flatten.compact
60
- end
61
-
62
- def check_box_container_classes(bootstrap)
63
- classes = Array(bootstrap.field_col_wrapper_class)
64
- classes << field_offset_class(bootstrap.label_col_wrapper_class)
65
- classes.flatten.compact
66
- end
67
-
68
- def bootstrap_check_box(attribute, value, options, bootstrap)
69
- options[:class] = check_box_classes(attribute, options)
70
- check_box_field = check_box_without_bootstrap(attribute, options, value, nil)
71
- check_box_label = check_box_label(attribute, value, options, bootstrap)
72
-
73
- check_box_field + check_box_label
74
- end
75
-
76
- private :check_box_label, :check_box_classes, :check_box_label_class,
77
- :check_box_wrapper_classes, :check_box_container_classes,
78
- :bootstrap_check_box
79
- end
80
- end
81
- end
82
- end
@@ -1,77 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- # -*- frozen_string_literal: true -*-
3
- # -*- warn_indent: true -*-
4
-
5
- module RailsBootstrapForm
6
- module Helpers
7
- module RadioButton
8
- extend ActiveSupport::Concern
9
-
10
- def self.included(base_class)
11
- def radio_button_label(attribute, value, options, bootstrap)
12
- unless bootstrap.skip_label?
13
- label_options = {
14
- value: value,
15
- class: radio_button_label_class(attribute, bootstrap, options)
16
- }
17
- label_options[:for] = options[:id] if options[:id].present?
18
-
19
- label_name = if options[:multiple]
20
- radio_button_value(attribute, checked_value)
21
- else
22
- attribute
23
- end
24
-
25
- label_text = label_text(attribute, bootstrap)
26
-
27
- label(label_name, label_text, label_options)
28
- end
29
- end
30
-
31
- def radio_button_value(attribute, value)
32
- # label's `for` attribute needs to match checkbox tag's id,
33
- # IE sanitized value, IE
34
- # https://github.com/rails/rails/blob/5-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L123-L125
35
- "#{attribute}_#{value.to_s.gsub(/\s/, "_").gsub(/[^-[[:word:]]]/, "").mb_chars.downcase}"
36
- end
37
-
38
- def radio_button_classes(attribute, options)
39
- classes = Array(options[:class]) << "form-check-input"
40
- classes << "is-invalid" if is_invalid?(attribute)
41
- classes.flatten.compact
42
- end
43
-
44
- def radio_button_label_class(attribute, bootstrap, options)
45
- classes = Array("form-check-label") << bootstrap.additional_label_class
46
- classes << "required" if is_field_required?(attribute, options)
47
- classes << "is-invalid" if is_invalid?(attribute)
48
- classes << bootstrap.hide_class if bootstrap.hide_label?
49
- classes.flatten.compact
50
- end
51
-
52
- def radio_button_wrapper_classes(bootstrap)
53
- classes = Array("form-check")
54
- classes << "form-check-inline" if bootstrap.inline?
55
- classes.flatten.compact
56
- end
57
-
58
- def radio_button_container_classes(bootstrap)
59
- classes = Array(bootstrap.field_col_wrapper_class)
60
- classes << field_offset_class(bootstrap.label_col_wrapper_class)
61
- classes.flatten.compact
62
- end
63
-
64
- def bootstrap_radio_button(attribute, value, options, bootstrap)
65
- options[:class] = radio_button_classes(attribute, options)
66
- radio_button_field = radio_button_without_bootstrap(attribute, value, options)
67
- radio_button_label = radio_button_label(attribute, value, options, bootstrap)
68
-
69
- radio_button_field + radio_button_label
70
- end
71
-
72
- private :radio_button_label, :radio_button_classes, :radio_button_label_class,
73
- :radio_button_wrapper_classes, :radio_button_container_classes
74
- end
75
- end
76
- end
77
- end