rails_bootstrap_form 0.8.1 → 0.8.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: 166829fc1aa39488cd3e86d83cc4639c817a4e76d93b92446994628e37918517
4
- data.tar.gz: a3e57d3932e375cf5ac5f0015254bf5764ae890b2ae929ff4144ebd2aa0052ae
3
+ metadata.gz: 44eed939f6f6924e6ff02b2330cf0372a6efdbeb2a379b19fc8b3eb740c6dd3b
4
+ data.tar.gz: b1600e611eaa19725e924b01136bddf59c385b046a744c4d7d97fb1a44d7123b
5
5
  SHA512:
6
- metadata.gz: 8be846d6efeb07efb8fd98a3bdea75bce5c6c891066c80253438695030dfc606d251aa9fe07fb7c5b0e3956436e238bd64817952aa2592dd87f79e05c6753ff5
7
- data.tar.gz: 5dc1fa8c0807972eae199880e8d76fc07c63b7f1f58643e56790046eeb0e08fe2dad1935dc9e7c2ef44cadceb339c640cab74a041ec9021be742fd927bde36cf
6
+ metadata.gz: 6641be855874886a07007ac392040b8cf82b3715315d2e072f20682f372df948fdfa66fe106075a928cb550fdfe7aba678f5d7135ad3993da8785c67642f99e9
7
+ data.tar.gz: 303a8dc7b296790fab32aa5079a57f0e782898e1c4c2e53da450bb21020bf424c949a6432a77374fc7cfabf8d2ad43679ce50ad24ecfb2a3091239e4f02659c1
data/CHANGELOG.md CHANGED
@@ -4,6 +4,30 @@ 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.8.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.8.2...v0.8.3) - 2023-05-29
8
+
9
+ ### What's new
10
+
11
+ - Added support to specify `bootstrap_form` option on `fields_for` helper
12
+
13
+ ## [0.8.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.8.1...v0.8.2) - 2023-05-28
14
+
15
+ ### What's fixed
16
+
17
+ - Fixed error causing `fields_for` to fail when object is passed in method.
18
+
19
+ ## [0.8.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.8.0...v0.8.1) - 2023-05-28
20
+
21
+ ### What's new
22
+
23
+ - Updated README
24
+ - Added support to add `required` class to label depending on field's `required` option
25
+ - Added specs for `Labels`, `HelpText`, `InputGroupBuilder`, and `inline` form layout
26
+
27
+ ### What's changed
28
+ - Replaced `div` by `fieldset` for dropdowns of `date_select`, `time_select`, and `datetime_select`
29
+ - Removed block parameter from `collection_check_boxes` and `collection_radio_buttons`
30
+
7
31
  ## [0.8.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.7.2...v0.8.0) - 2023-05-26
8
32
 
9
33
  ### What's new
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_form (0.8.1)
4
+ rails_bootstrap_form (0.8.3)
5
5
  actionpack (~> 7.0)
6
6
  activemodel (~> 7.0)
7
7
 
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # RailsBootstrapForm
2
2
 
3
+ [![Ruby](https://github.com/shivam091/rails_bootstrap_form/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/shivam091/rails_bootstrap_form/actions/workflows/main.yml)
4
+ [![Gem Version](https://badge.fury.io/rb/rails_bootstrap_form.svg)](https://badge.fury.io/rb/rails_bootstrap_form)
5
+
3
6
  **rails_bootstrap_form** is a Rails form builder that makes it super easy to integrate [Bootstrap 5](https://getbootstrap.com/) forms into your Rails application.
4
7
  `rails_bootstrap_forms`'s form helpers generate the form field and its label along with all the Bootstrap mark-up required for proper Bootstrap display.
5
8
 
@@ -25,7 +28,7 @@ for setting up `application.scss` and `application.js`.
25
28
  Add the `rails_bootstrap_form` gem to your `Gemfile`:
26
29
 
27
30
  ```ruby
28
- gem "rails_bootstrap_form", "~> 0.8.1"
31
+ gem "rails_bootstrap_form", "~> 0.8.2"
29
32
  ```
30
33
 
31
34
  Then:
@@ -804,6 +807,143 @@ This generates the following HTML:
804
807
  </div>
805
808
  ```
806
809
 
810
+ ### fields_for
811
+
812
+ Our `fields_for` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-fields_for).
813
+
814
+ `rails_bootstrap_form` allows us to set `bootstrap_form` option just like `bootstrap_form_for` and `bootstrap_form_with`. By setting this option on fields_for, it applies to all the fields defined for that form:
815
+
816
+ ![fields_for](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/f515302f-a92a-4b5c-a444-af91cbb00dff)
817
+
818
+ ```erb
819
+ <%= bootstrap_form_for @user do |form| %>
820
+ <%= form.email_field :email, autocomplete: "new-email" %>
821
+ <%= form.password_field :password, autocomplete: "new-password", bootstrap_form: {layout: :horizontal} %>
822
+ <%= form.phone_field :mobile_number %>
823
+ <%= form.fields_for :address, include_id: false, bootstrap_form: {layout: :horizontal} do |address_form| %>
824
+ <%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
825
+ {include_blank: "Select Country"} %>
826
+ <% end %>
827
+ <%= form.check_box :terms, required: true %>
828
+ <%= form.primary "Register" %>
829
+ <% end %>
830
+
831
+ ```
832
+
833
+ This generates the following HTML:
834
+
835
+ ```html
836
+ <form role="form" novalidate="novalidate" class="new_user" id="new_user" action="/users" accept-charset="UTF-8" method="post">
837
+ <div class="mb-3">
838
+ <label class="form-label required" for="user_email">Email address</label>
839
+ <input autocomplete="new-email" class="form-control" aria-required="true" required="required" type="email" name="user[email]" id="user_email">
840
+ <div class="form-text text-muted">Please use official email address</div>
841
+ </div>
842
+ <div class="row mb-3">
843
+ <label class="col-form-label col-sm-2 required" for="user_password">Password</label>
844
+ <div class="col-sm-10">
845
+ <input autocomplete="new-password" class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
846
+ </div>
847
+ </div>
848
+ <div class="mb-3">
849
+ <label class="form-label required" for="user_mobile_number">Mobile number</label>
850
+ <input class="form-control" aria-required="true" required="required" type="tel" name="user[mobile_number]" id="user_mobile_number">
851
+ </div>
852
+ <div class="row mb-3">
853
+ <label class="col-form-label col-sm-2 required" for="user_address_attributes_country_id">Country</label>
854
+ <div class="col-sm-10">
855
+ <select class="form-select" aria-required="true" required="required" name="user[address_attributes][country_id]" id="user_address_attributes_country_id">
856
+ <option value="">Select Country</option>
857
+ <option value="1">India</option>
858
+ <option value="2">Ireland</option>
859
+ <option value="3">United States</option>
860
+ <option value="4">United Kingdom</option>
861
+ <option value="5">Spain</option>
862
+ <option value="6">France</option>
863
+ <option value="7">Canada</option>
864
+ </select>
865
+ </div>
866
+ </div>
867
+ <div class="form-check mb-3">
868
+ <input name="user[terms]" type="hidden" value="0" autocomplete="off">
869
+ <input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
870
+ <label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
871
+ <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
872
+ </div>
873
+ <input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
874
+ </form>
875
+ ```
876
+
877
+ By setting `bootstrap_form` option on `bootstrap_form_for` or `bootstrap_form_with`, this option also applies to all the fields defined in fields_for block:
878
+
879
+ ![fields_for_horizontal](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/cb75e76b-e8a3-48f1-83a1-9eb150aa2466)
880
+
881
+ ```erb
882
+ <%= bootstrap_form_for @user, bootstrap_form: {layout: :horizontal} do |form| %>
883
+ <%= form.email_field :email, autocomplete: "new-email" %>
884
+ <%= form.password_field :password, autocomplete: "new-password" %>
885
+ <%= form.phone_field :mobile_number %>
886
+ <%= form.fields_for :address, include_id: false do |address_form| %>
887
+ <%= address_form.select :country_id, options_for_select(::Country.pluck(:name, :id), address_form.object.country_id),
888
+ {include_blank: "Select Country"} %>
889
+ <% end %>
890
+ <%= form.check_box :terms, required: true %>
891
+ <%= form.primary "Register" %>
892
+ <% end %>
893
+ ```
894
+
895
+ This generates the following HTML:
896
+
897
+ ```html
898
+ <form role="form" novalidate="novalidate" class="new_user" id="new_user" action="/users" accept-charset="UTF-8" method="post">
899
+ <div class="row mb-3">
900
+ <label class="col-form-label col-sm-2 required" for="user_email">Email address</label>
901
+ <div class="col-sm-10">
902
+ <input autocomplete="new-email" class="form-control" aria-required="true" required="required" type="email" name="user[email]" id="user_email">
903
+ <div class="form-text text-muted">Please use official email address</div>
904
+ </div>
905
+ </div>
906
+ <div class="row mb-3">
907
+ <label class="col-form-label col-sm-2 required" for="user_password">Password</label>
908
+ <div class="col-sm-10">
909
+ <input autocomplete="new-password" class="form-control" aria-required="true" required="required" type="password" name="user[password]" id="user_password">
910
+ </div>
911
+ </div>
912
+ <div class="row mb-3">
913
+ <label class="col-form-label col-sm-2 required" for="user_mobile_number">Mobile number</label>
914
+ <div class="col-sm-10">
915
+ <input class="form-control" aria-required="true" required="required" type="tel" name="user[mobile_number]" id="user_mobile_number">
916
+ </div>
917
+ </div>
918
+ <div class="row mb-3">
919
+ <label class="col-form-label col-sm-2 required" for="user_address_attributes_country_id">Country</label>
920
+ <div class="col-sm-10">
921
+ <select class="form-select" aria-required="true" required="required" name="user[address_attributes][country_id]" id="user_address_attributes_country_id">
922
+ <option value="">Select Country</option>
923
+ <option value="1">India</option>
924
+ <option value="2">Ireland</option>
925
+ <option value="3">United States</option>
926
+ <option value="4">United Kingdom</option>
927
+ <option value="5">Spain</option>
928
+ <option value="6">France</option>
929
+ <option value="7">Canada</option>
930
+ </select>
931
+ </div>
932
+ </div>
933
+ <div class="row mb-3">
934
+ <div class="col-sm-10 offset-sm-2">
935
+ <div class="form-check">
936
+ <input name="user[terms]" type="hidden" value="0" autocomplete="off">
937
+ <input required="required" class="form-check-input" type="checkbox" value="1" name="user[terms]" id="user_terms">
938
+ <label class="form-check-label required" for="user_terms">I accept terms and conditions</label>
939
+ <div class="form-text text-muted">You must first accept terms and conditions in order to continue</div>
940
+ </div>
941
+ </div>
942
+ </div>
943
+ <input type="submit" name="commit" value="Register" class="btn btn-primary" data-disable-with="Register">
944
+ </form>
945
+ ```
946
+
807
947
  ### file_field
808
948
 
809
949
  Our `file_field` helper accepts the same arguments as the [default Rails helper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-file_field).
@@ -41,9 +41,10 @@ module RailsBootstrapForm
41
41
  end
42
42
 
43
43
  def fields_for_options(record_object, fields_options)
44
- field_options = record_object if record_object.is_a?(Hash) && record_object.extractable_options?
45
- field_options = {bootstrap_form: options[:bootstrap_form]}.deep_merge!(field_options)
46
- field_options
44
+ fields_options = record_object if record_object.is_a?(Hash) && record_object.extractable_options?
45
+ bootstrap_options = {bootstrap_form: options.fetch(:bootstrap_form, {})}
46
+ fields_options = bootstrap_options.deep_merge!(fields_options)
47
+ fields_options
47
48
  end
48
49
 
49
50
  private :apply_default_form_options, :fields_for_options, :apply_default_form_classes
@@ -3,6 +3,6 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- VERSION = "0.8.1".freeze
6
+ VERSION = "0.8.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.8.1
4
+ version: 0.8.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-05-28 00:00:00.000000000 Z
11
+ date: 2023-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: generator_spec