diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8867b55..57ed3fa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -44,3 +44,5 @@ jobs: bundle exec rake db:migrate - name: Run test cases run: bundle exec rake + # - name: Rubocop + # run: bundle exec rubocop --autocorrect diff --git a/CHANGELOG.md b/CHANGELOG.md index 66f41d3..857ac1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ You can find recent releases with docs in GitHub: https://github.com/shivam091/rails_bootstrap_form/releases +## [0.9.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.2...v0.9.3) - 2023-06-04 + +### What's changed + +- Disabled floating labels for unsupported helpers + +### What's fixed + +- `id` of check box field when used in collection and don't has multiple select. (`collection_check_boxes` with `multiple: false`) + ## [0.9.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.1...v0.9.2) - 2023-06-03 ### What's new diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..c57a28c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,146 @@ +# Contributing + +Thank you so much for considering a contribution to `rails_bootstrap_form`. We love pull requests! + +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). + +There are a number of ways you can contribute to `rails_bootstrap_form`: + +- Fix a bug or add a new feature +- Add to the documentation +- Review pull requests + +## Code Contributions + +Here's a quick guide for code contributions: + +### 1. Check if issue or feature is available to work on + +Make sure no one else is working on the same issue or feature. Search the issues +and pull requests for anything that looks like the issue or feature you want to +address. If no one else is working on your issue or feature, carry on with the +following steps. + +### 2. Create an issue, and wait a few days for someone to respond (Optional) + +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. + +### 3. Fork the repo + +Fork the project. Optionally, create a branch you want to work on. + +### 4. Get it running locally + +- Install the required dependencies with `bundle install` +- Run tests via: `bundle exec rake` + +### 5. Hack away + +- Try to keep your changes small. Consider making several smaller pull requests if your changes are extensive. +- Don't forget to add necessary tests and make sure that all tests run successfully. +- Update the README if necessary. +- Add a line to the CHANGELOG for your bug fix or feature. +- Read the [Coding Guidelines](#coding-guidelines) section and make sure that `bundle exec rubocop --autocorrect` doesn't find any offences. + +You may find the [demo application](#the-demo-application) useful for development and debugging. + +### 6. Make a pull request + +- If you've never made a pull request (PR) before, read [this](https://help.github.com/articles/about-pull-requests/). +- 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. +- When the PR is submitted, check if Travis CI ran all the tests successfully, and didn't raise any issues. + +### 7. Done + +Somebody will shortly review your pull request and if everything is good, it will be +merged into the main branch. Eventually the gem will be published with your changes. + +### Coding guidelines + +This project uses [RuboCop](https://github.com/bbatsov/rubocop) to enforce standard Ruby coding guidelines. + +- Test that your contribution passes with `bundle exec rubocop`. +- RuboCop is also run as part of the full test suite with `bundle exec rake`. +- Note the Travis build will fail and your PR cannot be merged if RuboCop finds offences. + +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/). + +### Supported Versions of Ruby and Rails + +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. + +The Ruby on Rails support policy is [here](https://guides.rubyonrails.org/maintenance_policy.html). + +### The Demo Application + +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. + +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. +To run the demo app, set up the database and run the server: + +```bash +cd demo +bundle +rails db:create +rails db:migrate +``` + +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. + +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. + +If you need to run the Rails server separately, for example, to debug the server, you _must_ run it like this: + +```sh +bundle exec rails s -b 0.0.0.0 +``` + +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. + +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. + +## Documentation Contributions + +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). + +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. + +## Reviewing Pull Requests + +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. + +--- + +Thanks to all the [great contributors](https://github.com/shivam091/rails_bootstrap_form/graphs/contributors). + +## Troubleshooting + +### Models and Database Tables + +`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. + +In the future, any new Rails functionality that creates tables would likely have to be prepared the same way: + +```bash +cd demo +rails db:create +rails db:migrate +``` + +### RuboCop + +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. + +The first thing to try is to update your `Gemfile.lock` locally: + +```bash +bundle update +``` + +Or, if you really want to minimize your work: + +```bash +bundle update --conservative rubocop +``` + +This should enable you to reproduce the RuboCop failures locally, and then you can fix them. diff --git a/Gemfile.lock b/Gemfile.lock index 063a5a9..c0b5eee 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - rails_bootstrap_form (0.9.2) + rails_bootstrap_form (0.9.3) actionpack (~> 7.0) activemodel (~> 7.0) diff --git a/README.md b/README.md index f11da80..245dfb3 100644 --- a/README.md +++ b/README.md @@ -688,7 +688,7 @@ Here's an example of how you pass the arguments for each form helper: ### check_box 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). -This helper will render check box and label for you. +except it don't accept a `block` as an argument and renders check box and label for you. ![check_box](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/5836650c-d536-4f4e-b768-75bca9dd7901) @@ -1435,7 +1435,7 @@ This generates the following HTML: ### collection_check_boxes -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 +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 an argument and takes care of rendering labels, check boxes, and wrapper for you. ![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: ### collection_radio_buttons -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 +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 an argument and takes care of rendering labels, radio button, and wrapper for you. ![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: ``` +_Floating labels gets disabled by `rails_bootstrap_form` automatically for unsupported helpers._ + ## Validation and Errors By default, `rails_bootstrap_form` generations in-line errors which appear below the field. diff --git a/lib/rails_bootstrap_form/helpers.rb b/lib/rails_bootstrap_form/helpers.rb index 88967fb..8f93c7c 100644 --- a/lib/rails_bootstrap_form/helpers.rb +++ b/lib/rails_bootstrap_form/helpers.rb @@ -11,22 +11,21 @@ module Helpers autoload :Labels autoload :RequiredField autoload :Errors - autoload :CheckBox - autoload :RadioButton autoload :Buttons + autoload :Choice include HelpText include Labels include RequiredField include Errors - include CheckBox - include RadioButton include Buttons + include Choice def self.included(base_class) - def collection_input_checked?(checked, obj, input_value) - checked == input_value || Array(checked).try(:include?, input_value) || - checked == obj || Array(checked).try(:include?, obj) + def sanitized_tag_name(attribute, value) + # label's `for` attribute needs to match checkbox/radio button tag's id, IE sanitized value, IE + # https://github.com/rails/rails/blob/5-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L123-L125 + "#{@object_name}_#{attribute}_#{value.to_s.gsub(/\s/, "_").gsub(/[^-[[:word:]]]/, "").mb_chars.downcase}" end def control_specific_class(field_tag_name) @@ -52,8 +51,8 @@ def remove_css_class!(options, css_class) options.delete(:class) if options[:class].blank? end - private :collection_input_checked?, :control_specific_class, :is_size_valid?, - :add_css_class!, :remove_css_class! + private :control_specific_class, :is_size_valid?, :add_css_class!, + :remove_css_class! end end end diff --git a/lib/rails_bootstrap_form/helpers/check_box.rb b/lib/rails_bootstrap_form/helpers/check_box.rb deleted file mode 100644 index c1f4906..0000000 --- a/lib/rails_bootstrap_form/helpers/check_box.rb +++ /dev/null @@ -1,82 +0,0 @@ -# -*- encoding: utf-8 -*- -# -*- frozen_string_literal: true -*- -# -*- warn_indent: true -*- - -module RailsBootstrapForm - module Helpers - module CheckBox - extend ActiveSupport::Concern - - def self.included(base_class) - def check_box_label(attribute, checked_value, options, bootstrap, &block) - unless bootstrap.skip_label? - label_options = { - class: check_box_label_class(attribute, bootstrap, options) - } - label_options[:for] = options[:id] if options[:id].present? - - label_name = if options[:multiple] - check_box_value(attribute, checked_value) - else - attribute - end - - label_text = check_box_label_text(attribute, options, bootstrap, &block) - - label(label_name, label_text, label_options) - end - end - - def check_box_label_text(attribute, options, bootstrap, &block) - block ? capture(&block) : label_text(attribute, bootstrap) - end - - def check_box_value(attribute, value) - # label's `for` attribute needs to match checkbox tag's id, - # IE sanitized value, IE - # https://github.com/rails/rails/blob/5-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L123-L125 - "#{attribute}_#{value.to_s.gsub(/\s/, "_").gsub(/[^-[[:word:]]]/, "").mb_chars.downcase}" - end - - def check_box_classes(attribute, options) - classes = Array(options[:class]) << "form-check-input" - classes << "is-invalid" if is_invalid?(attribute) - classes.flatten.compact - end - - def check_box_label_class(attribute, bootstrap, options) - classes = Array("form-check-label") << bootstrap.additional_label_class - classes << "required" if is_field_required?(attribute, options) - classes << "is-invalid" if is_invalid?(attribute) - classes << bootstrap.hide_class if bootstrap.hide_label? - classes.flatten.compact - end - - def check_box_wrapper_classes(bootstrap) - classes = Array("form-check") - classes << "form-switch" if bootstrap.switch? - classes << "form-check-inline" if bootstrap.inline? - classes.flatten.compact - end - - def check_box_container_classes(bootstrap) - classes = Array(bootstrap.field_col_wrapper_class) - classes << field_offset_class(bootstrap.label_col_wrapper_class) - classes.flatten.compact - end - - def bootstrap_check_box(attribute, value, options, bootstrap) - options[:class] = check_box_classes(attribute, options) - check_box_field = check_box_without_bootstrap(attribute, options, value, nil) - check_box_label = check_box_label(attribute, value, options, bootstrap) - - check_box_field + check_box_label - end - - private :check_box_label, :check_box_classes, :check_box_label_class, - :check_box_wrapper_classes, :check_box_container_classes, - :bootstrap_check_box - end - end - end -end diff --git a/lib/rails_bootstrap_form/helpers/choice.rb b/lib/rails_bootstrap_form/helpers/choice.rb new file mode 100644 index 0000000..4b8174b --- /dev/null +++ b/lib/rails_bootstrap_form/helpers/choice.rb @@ -0,0 +1,81 @@ +# -*- encoding: utf-8 -*- +# -*- frozen_string_literal: true -*- +# -*- warn_indent: true -*- + +module RailsBootstrapForm + module Helpers + module Choice + extend ActiveSupport::Concern + + def self.included(base_class) + [:check_box, :radio_button].each do |tag_name| + define_method("#{tag_name}_label") do |attribute, value, options, bootstrap| + label_options = { + class: choice_label_classes(attribute, bootstrap, options) + } + label_options[:value] = value if tag_name.eql?(:radio_button) + label_options[:for] = options[:id] if options[:id].present? + + label_text = label_text(attribute, bootstrap) + + label(attribute, label_text, label_options) + end + end + + [:check_box, :radio_button].each do |tag_name| + define_method("bootstrap_#{tag_name}") do |attribute, value, options, bootstrap| + options[:class] = choice_classes(attribute, options) + + if tag_name.eql?(:check_box) + choice_field = check_box_without_bootstrap(attribute, options, value, nil) + choice_label = check_box_label(attribute, value, options, bootstrap) + else + choice_field = radio_button_without_bootstrap(attribute, value, options) + choice_label = radio_button_label(attribute, value, options, bootstrap) + end + + choice_field + choice_label + end + end + + def choice_classes(attribute, options) + classes = Array("form-check-input") << options[:class] + classes << "is-invalid" if is_invalid?(attribute) + classes.flatten.compact + end + + def choice_label_classes(attribute, bootstrap, options) + classes = Array("form-check-label") << bootstrap.additional_label_class + classes << "required" if is_field_required?(attribute, options) + classes << "is-invalid" if is_invalid?(attribute) + classes << bootstrap.hide_class if bootstrap.hide_label? + classes.flatten.compact + end + + def choice_container_classes(bootstrap) + classes = Array(bootstrap.field_col_wrapper_class) + classes << field_offset_class(bootstrap.label_col_wrapper_class) + classes.flatten.compact + end + + def choice_wrapper_classes(bootstrap) + classes = Array("form-check") + classes << "form-check-inline" if bootstrap.inline? + classes << "form-switch" if bootstrap.switch? + classes.flatten.compact + end + + def collection_input_checked?(checked, obj, input_value) + checked == input_value || Array(checked).try(:include?, input_value) || + checked == obj || Array(checked).try(:include?, obj) + end + + private :choice_classes, :choice_label_classes, + :choice_container_classes, :choice_wrapper_classes, + :check_box_label, :radio_button_label, + :bootstrap_check_box, :bootstrap_radio_button, + :collection_input_checked? + end + end + end +end diff --git a/lib/rails_bootstrap_form/helpers/radio_button.rb b/lib/rails_bootstrap_form/helpers/radio_button.rb deleted file mode 100644 index f5f9a97..0000000 --- a/lib/rails_bootstrap_form/helpers/radio_button.rb +++ /dev/null @@ -1,77 +0,0 @@ -# -*- encoding: utf-8 -*- -# -*- frozen_string_literal: true -*- -# -*- warn_indent: true -*- - -module RailsBootstrapForm - module Helpers - module RadioButton - extend ActiveSupport::Concern - - def self.included(base_class) - def radio_button_label(attribute, value, options, bootstrap) - unless bootstrap.skip_label? - label_options = { - value: value, - class: radio_button_label_class(attribute, bootstrap, options) - } - label_options[:for] = options[:id] if options[:id].present? - - label_name = if options[:multiple] - radio_button_value(attribute, checked_value) - else - attribute - end - - label_text = label_text(attribute, bootstrap) - - label(label_name, label_text, label_options) - end - end - - def radio_button_value(attribute, value) - # label's `for` attribute needs to match checkbox tag's id, - # IE sanitized value, IE - # https://github.com/rails/rails/blob/5-0-stable/actionview/lib/action_view/helpers/tags/base.rb#L123-L125 - "#{attribute}_#{value.to_s.gsub(/\s/, "_").gsub(/[^-[[:word:]]]/, "").mb_chars.downcase}" - end - - def radio_button_classes(attribute, options) - classes = Array(options[:class]) << "form-check-input" - classes << "is-invalid" if is_invalid?(attribute) - classes.flatten.compact - end - - def radio_button_label_class(attribute, bootstrap, options) - classes = Array("form-check-label") << bootstrap.additional_label_class - classes << "required" if is_field_required?(attribute, options) - classes << "is-invalid" if is_invalid?(attribute) - classes << bootstrap.hide_class if bootstrap.hide_label? - classes.flatten.compact - end - - def radio_button_wrapper_classes(bootstrap) - classes = Array("form-check") - classes << "form-check-inline" if bootstrap.inline? - classes.flatten.compact - end - - def radio_button_container_classes(bootstrap) - classes = Array(bootstrap.field_col_wrapper_class) - classes << field_offset_class(bootstrap.label_col_wrapper_class) - classes.flatten.compact - end - - def bootstrap_radio_button(attribute, value, options, bootstrap) - options[:class] = radio_button_classes(attribute, options) - radio_button_field = radio_button_without_bootstrap(attribute, value, options) - radio_button_label = radio_button_label(attribute, value, options, bootstrap) - - radio_button_field + radio_button_label - end - - private :radio_button_label, :radio_button_classes, :radio_button_label_class, - :radio_button_wrapper_classes, :radio_button_container_classes - end - end - end -end diff --git a/lib/rails_bootstrap_form/inputs/base.rb b/lib/rails_bootstrap_form/inputs/base.rb index 199fbde..10cc16b 100644 --- a/lib/rails_bootstrap_form/inputs/base.rb +++ b/lib/rails_bootstrap_form/inputs/base.rb @@ -13,12 +13,14 @@ def inputs_collection(attribute, collection, value_method, text_method, bootstra collection.each do |object| value = object.send(value_method) + input_options = { bootstrap: { label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method), inline: bootstrap.inline? }, - required: false + required: false, + id: sanitized_tag_name(attribute, value) }.deep_merge!(options) if (checked = input_options[:checked]) @@ -35,8 +37,8 @@ def inputs_collection(attribute, collection, value_method, text_method, bootstra end class_methods do - def bootstrap_field(field_name) - define_method(field_name) do |attribute, options = {}| + def bootstrap_field(tag_name) + define_method(tag_name) do |attribute, options = {}| bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap)) return super(attribute, options) if bootstrap.disabled? @@ -46,15 +48,15 @@ def bootstrap_field(field_name) end end - def bootstrap_select_group(field_name) - define_method(field_name) do |attribute, options = {}, html_options = {}| - options = {bootstrap: {field_class: "form-select"}}.deep_merge!(options) + def bootstrap_select_group(tag_name) + define_method(tag_name) do |attribute, options = {}, html_options = {}| + options = {bootstrap: {field_class: "form-select", floating: false}}.deep_merge!(options) bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap)) return super(attribute, options, html_options) if bootstrap.disabled? field_wrapper_builder(attribute, bootstrap, options, html_options) do - tag.fieldset(class: control_specific_class(field_name)) do + tag.fieldset(class: control_specific_class(tag_name)) do super(attribute, options, html_options) end end diff --git a/lib/rails_bootstrap_form/inputs/check_box.rb b/lib/rails_bootstrap_form/inputs/check_box.rb index 32323a9..f00ae4a 100644 --- a/lib/rails_bootstrap_form/inputs/check_box.rb +++ b/lib/rails_bootstrap_form/inputs/check_box.rb @@ -8,11 +8,11 @@ module CheckBox extend ActiveSupport::Concern included do - def check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0", &block) + def check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0") bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap)) return super if bootstrap.disabled? - check_box_html = tag.div(class: check_box_wrapper_classes(bootstrap)) do + check_box_html = tag.div(class: choice_wrapper_classes(bootstrap)) do concat(bootstrap_check_box(attribute, checked_value, options, bootstrap)) concat(help_text(attribute, bootstrap)) concat(generate_error(attribute)) if is_invalid?(attribute) @@ -21,7 +21,7 @@ def check_box(attribute, options = {}, checked_value = "1", unchecked_value = "0 if bootstrap.wrapper tag.div(**field_wrapper_options(bootstrap)) do if bootstrap.layout_horizontal? - tag.div(class: check_box_container_classes(bootstrap)) { check_box_html } + tag.div(class: choice_container_classes(bootstrap)) { check_box_html } else check_box_html end diff --git a/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb b/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb index b310cfe..d2449f7 100644 --- a/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb +++ b/lib/rails_bootstrap_form/inputs/collection_check_boxes.rb @@ -10,16 +10,15 @@ module CollectionCheckBoxes included do def collection_check_boxes(attribute, collection, value_method, text_method, options = {}, html_options = {}) bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap)) + bootstrap.floating = false return super if bootstrap.disabled? inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap, options) do |attribute, value, options| bootstrap_opts = bootstrap_form_options.scoped(options.delete(:bootstrap)) - check_box_html = tag.div(class: check_box_wrapper_classes(bootstrap_opts)) do + tag.div(class: choice_wrapper_classes(bootstrap_opts)) do bootstrap_check_box(attribute, value, options, bootstrap_opts) end - - check_box_html end if options.delete(:include_hidden) { true } diff --git a/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb b/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb index d266b62..c06d459 100644 --- a/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb +++ b/lib/rails_bootstrap_form/inputs/collection_radio_buttons.rb @@ -10,16 +10,15 @@ module CollectionRadioButtons included do def collection_radio_buttons(attribute, collection, value_method, text_method, options = {}, html_options = {}) bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap)) + bootstrap.floating = false return super if bootstrap.disabled? inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap, options) do |attribute, value, options| bootstrap_opts = bootstrap_form_options.scoped(options.delete(:bootstrap)) - bootstrap_radio_html = tag.div(class: radio_button_wrapper_classes(bootstrap_opts)) do + tag.div(class: choice_wrapper_classes(bootstrap_opts)) do bootstrap_radio_button(attribute, value, options, bootstrap_opts) end - - bootstrap_radio_html end field_wrapper_builder(attribute, bootstrap, options, html_options) do diff --git a/lib/rails_bootstrap_form/inputs/color_field.rb b/lib/rails_bootstrap_form/inputs/color_field.rb index 744db40..565a7f2 100644 --- a/lib/rails_bootstrap_form/inputs/color_field.rb +++ b/lib/rails_bootstrap_form/inputs/color_field.rb @@ -9,7 +9,12 @@ module ColorField included do def color_field(attribute, options = {}) - options = {bootstrap: {field_class: "form-control form-control-color"}}.deep_merge!(options) + options = { + bootstrap: { + field_class: "form-control form-control-color", + floating: false + } + }.deep_merge!(options) bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap)) return super if bootstrap.disabled? diff --git a/lib/rails_bootstrap_form/inputs/radio_button.rb b/lib/rails_bootstrap_form/inputs/radio_button.rb index 2b52e78..b9cc1fa 100644 --- a/lib/rails_bootstrap_form/inputs/radio_button.rb +++ b/lib/rails_bootstrap_form/inputs/radio_button.rb @@ -12,7 +12,7 @@ def radio_button(attribute, value, options = {}) bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap)) return super if bootstrap.disabled? - radio_button_html = tag.div(class: radio_button_wrapper_classes(bootstrap)) do + radio_button_html = tag.div(class: choice_wrapper_classes(bootstrap)) do concat(bootstrap_radio_button(attribute, value, options, bootstrap)) concat(help_text(attribute, bootstrap)) concat(generate_error(attribute)) if is_invalid?(attribute) @@ -21,7 +21,7 @@ def radio_button(attribute, value, options = {}) if bootstrap.wrapper tag.div(**field_wrapper_options(bootstrap)) do if bootstrap.layout_horizontal? - tag.div(class: radio_button_container_classes(bootstrap)) { radio_button_html } + tag.div(class: choice_container_classes(bootstrap)) { radio_button_html } else radio_button_html end diff --git a/lib/rails_bootstrap_form/inputs/range_field.rb b/lib/rails_bootstrap_form/inputs/range_field.rb index c9282f1..7fa2107 100644 --- a/lib/rails_bootstrap_form/inputs/range_field.rb +++ b/lib/rails_bootstrap_form/inputs/range_field.rb @@ -9,7 +9,7 @@ module RangeField included do def range_field(attribute, options = {}) - options = {bootstrap: {field_class: "form-range"}}.deep_merge!(options) + options = {bootstrap: {field_class: "form-range", floating: false}}.deep_merge!(options) bootstrap = bootstrap_form_options.scoped(options.delete(:bootstrap)) return super if bootstrap.disabled? diff --git a/lib/rails_bootstrap_form/version.rb b/lib/rails_bootstrap_form/version.rb index 5d9ed4e..ce1f53d 100644 --- a/lib/rails_bootstrap_form/version.rb +++ b/lib/rails_bootstrap_form/version.rb @@ -3,6 +3,6 @@ # -*- warn_indent: true -*- module RailsBootstrapForm - VERSION = "0.9.2".freeze + VERSION = "0.9.3".freeze REQUIRED_RAILS_VERSION = "~> 7.0".freeze end diff --git a/spec/rails_bootstrap_form_spec.rb b/spec/rails_bootstrap_form_spec.rb index 3267aa7..08cc6ff 100644 --- a/spec/rails_bootstrap_form_spec.rb +++ b/spec/rails_bootstrap_form_spec.rb @@ -6,7 +6,7 @@ RSpec.describe RailsBootstrapForm do it "has a valid version number" do - expect(RailsBootstrapForm::VERSION).to eq("0.9.2") + expect(RailsBootstrapForm::VERSION).to eq("0.9.3") end it "has a valid rails version number" do