rails_bootstrap_form 0.8.1 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/Gemfile.lock +1 -1
- data/README.md +141 -1
- data/lib/rails_bootstrap_form/bootstrap_form_builder.rb +4 -3
- data/lib/rails_bootstrap_form/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44eed939f6f6924e6ff02b2330cf0372a6efdbeb2a379b19fc8b3eb740c6dd3b
|
4
|
+
data.tar.gz: b1600e611eaa19725e924b01136bddf59c385b046a744c4d7d97fb1a44d7123b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# RailsBootstrapForm
|
2
2
|
|
3
|
+
[](https://github.com/shivam091/rails_bootstrap_form/actions/workflows/main.yml)
|
4
|
+
[](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.
|
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
|
+

|
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
|
+

|
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
|
-
|
45
|
-
|
46
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2023-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: generator_spec
|