rails_bootstrap_form 0.8.2 → 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: e02719566479d775dbcff16d248f1a2498c34a71000c192202d45656b5412343
4
- data.tar.gz: 26b36857096e847a7c2fc43c83ff3dff3b49f76d6d3b053bbefb3f98a8fa01d0
3
+ metadata.gz: 44eed939f6f6924e6ff02b2330cf0372a6efdbeb2a379b19fc8b3eb740c6dd3b
4
+ data.tar.gz: b1600e611eaa19725e924b01136bddf59c385b046a744c4d7d97fb1a44d7123b
5
5
  SHA512:
6
- metadata.gz: 4e17627f2bdb97af7c136d211428695bc853490d3f7fd2c65fb29de6199c8744782852c2c92b72f40c134f2c4285ef76684e5574644fda4ea77e59dd8e7c27f1
7
- data.tar.gz: 85218ad2ab4b9bf3a22f478dcdf150930453d4326e51807f3018278df3c0d3e93d30b99af1e04b52f47765f5626f5899b8c26d7156a8b3a94aadf7886b536d94
6
+ metadata.gz: 6641be855874886a07007ac392040b8cf82b3715315d2e072f20682f372df948fdfa66fe106075a928cb550fdfe7aba678f5d7135ad3993da8785c67642f99e9
7
+ data.tar.gz: 303a8dc7b296790fab32aa5079a57f0e782898e1c4c2e53da450bb21020bf424c949a6432a77374fc7cfabf8d2ad43679ce50ad24ecfb2a3091239e4f02659c1
data/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ 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
+
7
13
  ## [0.8.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.8.1...v0.8.2) - 2023-05-28
8
14
 
9
15
  ### What's fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_form (0.8.2)
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,6 @@
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)
3
4
  [![Gem Version](https://badge.fury.io/rb/rails_bootstrap_form.svg)](https://badge.fury.io/rb/rails_bootstrap_form)
4
5
 
5
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.
@@ -806,6 +807,143 @@ This generates the following HTML:
806
807
  </div>
807
808
  ```
808
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
+
809
947
  ### file_field
810
948
 
811
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,10 +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.fetch(:bootstrap_form, {})}
46
- field_options.deep_merge!(field_options) if field_options.respond_to?(:deep_merge!)
47
- 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
48
48
  end
49
49
 
50
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.2".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.2
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