rails_bootstrap_form 0.9.3 → 0.9.4
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 +18 -0
- data/Gemfile.lock +1 -1
- data/README.md +80 -19
- data/lib/generators/rails_bootstrap_form/templates/install.rb +1 -1
- data/lib/rails_bootstrap_form/field_wrapper_builder.rb +1 -5
- data/lib/rails_bootstrap_form/helpers/choice.rb +12 -10
- data/lib/rails_bootstrap_form/helpers.rb +6 -7
- data/lib/rails_bootstrap_form/inputs/base.rb +1 -1
- data/lib/rails_bootstrap_form/inputs/static_field.rb +1 -1
- 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: c769ec63a2b3c1a8abaeaa8f8a8d11f7b473e71c69d7eb4fda3a4d200b9106e7
|
4
|
+
data.tar.gz: a477abf8d26482d15d9eb6a1a4dae62be453823def408d9958961945d81cfe97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6394304b9d69627c1032d8392a6cb586964f9dce3e0d948aeaf0854303ae222f26f9a357e4df40f41c4f42e4d381140d27cf3cb65b2d1582c2a0f8400895be72
|
7
|
+
data.tar.gz: fb8f1d8a37574de977551917b2e0b1577c2240d6443f48e7ac9d65fff3ca97939eaea6c97f54e88eb5d1322aed18c4336b4d6f440594b8089372d5185013ef6d
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,24 @@ 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.4](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.3...v0.9.4) - 2023-06-17
|
8
|
+
|
9
|
+
### What's new
|
10
|
+
|
11
|
+
- Added specs for field helpers.
|
12
|
+
|
13
|
+
### What's changed
|
14
|
+
|
15
|
+
- Change to take `additional_field_class` precedence over HTML `class` ([#42](https://github.com/shivam091/rails_bootstrap_form/issues/42))
|
16
|
+
- Change to `collection_check_boxes` and `collection_radio buttons` to render inline `check boxes` and
|
17
|
+
`radio buttons`, respectively when form layout is inline. ([#43](https://github.com/shivam091/rails_bootstrap_form/issues/43))
|
18
|
+
|
19
|
+
### What's fixed
|
20
|
+
|
21
|
+
- Fixed bug causing `skip_label` option not to work in `radio_button` and `check_box` ([#37](https://github.com/shivam091/rails_bootstrap_form/issues/37))
|
22
|
+
- Fixed bug causing `additional_field_class` to apply on `radio_button` and `check_box` ([#40](https://github.com/shivam091/rails_bootstrap_form/issues/40))
|
23
|
+
- Fixed bug causing `bootstrap` options to not set on `static_field` ([#41](https://github.com/shivam091/rails_bootstrap_form/issues/41))
|
24
|
+
|
7
25
|
## [0.9.3](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.2...v0.9.3) - 2023-06-04
|
8
26
|
|
9
27
|
### What's changed
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[](https://badge.fury.io/rb/rails_bootstrap_form)
|
5
5
|
|
6
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.
|
7
|
-
`
|
7
|
+
`rails_bootstrap_form`'s form helpers generate the form field and its label along with all the Bootstrap mark-up required for proper Bootstrap display.
|
8
8
|
|
9
9
|
## Minimum Requirements
|
10
10
|
|
@@ -28,7 +28,7 @@ for setting up `application.scss` and `application.js`.
|
|
28
28
|
Add the `rails_bootstrap_form` gem to your `Gemfile`:
|
29
29
|
|
30
30
|
```ruby
|
31
|
-
gem "rails_bootstrap_form", "~> 0.
|
31
|
+
gem "rails_bootstrap_form", "~> 0.9.4"
|
32
32
|
```
|
33
33
|
|
34
34
|
Then:
|
@@ -64,7 +64,7 @@ Example:
|
|
64
64
|
# config/initializers/rails_bootstrap_form.rb
|
65
65
|
RailsBootstrapForm.configure do |config|
|
66
66
|
# to make forms non-compliant with W3C.
|
67
|
-
config.default_form_attributes = {
|
67
|
+
config.default_form_attributes = {novalidate: true}
|
68
68
|
end
|
69
69
|
```
|
70
70
|
|
@@ -72,7 +72,7 @@ The current configuration options are:
|
|
72
72
|
|
73
73
|
| Option | Default value | Description |
|
74
74
|
|---------------------------|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
75
|
-
| `default_form_attributes` | | Set this option to `{
|
75
|
+
| `default_form_attributes` | | Set this option to `{novalidate: true}` to instruct `rails_bootstrap_form` to skip all HTML 5 validation. |
|
76
76
|
|
77
77
|
## Usage
|
78
78
|
|
@@ -161,7 +161,6 @@ Here's a list of all possible options you can pass via `bootstrap` option that c
|
|
161
161
|
| `disabled` | An option to disable **rails_bootstrap_form** helpers. Default rails form builder element is rendered when set to `true` | `false` |
|
162
162
|
| `layout` | Controls layout of form and field helpers. It can be `vertical` `horizontal`, or `inline`. | `vertical` |
|
163
163
|
| `field_class` | A CSS class that will be applied to all form fields. | `form-control` |
|
164
|
-
| `additional_field_class` | An additional CSS class that will be added along with the existing css classes of field helpers. | `nil` |
|
165
164
|
| `help_text` | Describes help text for the HTML field. Help text is automatically read from translation file. If you want to customize it, you can pass a string. You can also set it `false` if you do not want help text displayed. | `nil` |
|
166
165
|
| `label_text` | An option to customize automatically generated label text. | `nil` |
|
167
166
|
| `skip_label` | An option to control whether the label is to be displayed or not. | `false` |
|
@@ -183,7 +182,7 @@ Here's a list of all possible options you can pass via `bootstrap` option that c
|
|
183
182
|
| `field_col_wrapper_class` | A CSS class for field column when layout is `horizontal`. | `col-sm-10` |
|
184
183
|
| `render_as_button` | An option to render submit button using `<button type="submit">` instead of `<input type="submit">`. | `false` |
|
185
184
|
|
186
|
-
Options
|
185
|
+
Options defined on the form level will apply to all field helpers. Options defined on field helpers takes precedence over form-level options.
|
187
186
|
Here's an example of a form where one field uses different layout:
|
188
187
|
|
189
188
|

|
@@ -235,9 +234,15 @@ You can completely disable bootstrap and use default form builder by passing `di
|
|
235
234
|
<%= form.text_field :username, bootstrap: {disabled: true} %>
|
236
235
|
```
|
237
236
|
|
237
|
+
This generates the following HTML:
|
238
|
+
|
239
|
+
```html
|
240
|
+
<input type="text" name="user[username]" id="user_username">
|
241
|
+
```
|
242
|
+
|
238
243
|
### Disabling wrapper
|
239
244
|
|
240
|
-
In some cases, you may need to disable the default wrapper. You can do this by passing
|
245
|
+
In some cases, you may need to disable the default wrapper. You can do this by passing `wrapper: false` option:
|
241
246
|
|
242
247
|

|
243
248
|
|
@@ -252,6 +257,53 @@ This generates the following HTML:
|
|
252
257
|
<input class="form-control" aria-required="true" required="required" type="text" name="user[name]" id="user_name">
|
253
258
|
```
|
254
259
|
|
260
|
+
### Add additional CSS class
|
261
|
+
|
262
|
+
You can use `additional_field_class` option at form or field level to add extra CSS classes to the fields.
|
263
|
+
|
264
|
+
```erb
|
265
|
+
<%= form.text_field :name, autocomplete: "new-name", bootstrap: {additional_field_class: "custom-class"} %>
|
266
|
+
```
|
267
|
+
|
268
|
+
This generates the following HTML:
|
269
|
+
|
270
|
+
```html
|
271
|
+
<div class="mb-3">
|
272
|
+
<label class="form-label required" for="user_name">Name</label>
|
273
|
+
<input autocomplete="new-name" class="form-control custom-class" aria-required="true" required="required" type="text" name="user[name]" id="user_name">
|
274
|
+
</div>
|
275
|
+
```
|
276
|
+
|
277
|
+
You can also use HTML `class` attribute to add additional CSS class to the single field:
|
278
|
+
|
279
|
+
```erb
|
280
|
+
<%= form.text_field :name, autocomplete: "new-name", class: "custom-class" %>
|
281
|
+
```
|
282
|
+
|
283
|
+
This generates the following HTML:
|
284
|
+
|
285
|
+
```html
|
286
|
+
<div class="mb-3">
|
287
|
+
<label class="form-label required" for="user_name">Name</label>
|
288
|
+
<input autocomplete="new-name" class="form-control custom-class" aria-required="true" required="required" type="text" name="user[name]" id="user_name">
|
289
|
+
</div>
|
290
|
+
```
|
291
|
+
|
292
|
+
Here `additional_field_class` option takes precedance over HTML `class` attribute:
|
293
|
+
|
294
|
+
```erb
|
295
|
+
<%= form.text_field :name, autocomplete: "new-name", bootstrap: {additional_field_class: "custom-class"}, class: "html-class" %>
|
296
|
+
```
|
297
|
+
|
298
|
+
This generates the following HTML:
|
299
|
+
|
300
|
+
```html
|
301
|
+
<div class="mb-3">
|
302
|
+
<label class="form-label required" for="user_name">Name</label>
|
303
|
+
<input autocomplete="new-name" class="form-control custom-class" aria-required="true" required="required" type="text" name="user[name]" id="user_name">
|
304
|
+
</div>
|
305
|
+
```
|
306
|
+
|
255
307
|
## Supported Form Helpers
|
256
308
|
|
257
309
|
This gem wraps most of the form field helpers. Here's the current list:
|
@@ -274,7 +326,7 @@ url_field week_field weekday_select
|
|
274
326
|
|
275
327
|
### Vertical Layout
|
276
328
|
|
277
|
-
This layout is default layout for the form in which labels are above the fields
|
329
|
+
This layout is default layout for the form in which labels are above the fields. In this layout, labels and fields take 100% of the width.
|
278
330
|
|
279
331
|
Here's an example of how it looks like:
|
280
332
|
|
@@ -308,7 +360,7 @@ This generates the following HTML:
|
|
308
360
|
|
309
361
|
If you want to align label and field side by side, you can use horizontal layout for the form.
|
310
362
|
You can optionally override `label_col_wrapper_class` and `field_col_wrapper_class` (they default to `col-sm-2` and `col-sm-10`) at either form level
|
311
|
-
or field
|
363
|
+
or field level if want to customize space between label and field.
|
312
364
|
|
313
365
|
Here's an example of how it looks like by default:
|
314
366
|
|
@@ -341,7 +393,7 @@ This generates the following HTML:
|
|
341
393
|
</form>
|
342
394
|
```
|
343
395
|
|
344
|
-
The `label_col_wrapper_class` and `field_col_wrapper_class` css classes can also be
|
396
|
+
The `label_col_wrapper_class` and `field_col_wrapper_class` css classes can also be customized per control:
|
345
397
|
|
346
398
|

|
347
399
|
|
@@ -454,7 +506,7 @@ This generates the following HTML:
|
|
454
506
|
</div>
|
455
507
|
```
|
456
508
|
|
457
|
-
To hide a label, you can set `hide_label` option
|
509
|
+
To hide a label, you can set `hide_label: true` option. This adds the `visually-hidden` class, which keeps your labels accessible
|
458
510
|
to those using screen readers.
|
459
511
|
|
460
512
|

|
@@ -472,7 +524,7 @@ This generates the following HTML:
|
|
472
524
|
</div>
|
473
525
|
```
|
474
526
|
|
475
|
-
To skip a label, you can set `skip_label` option
|
527
|
+
To skip a label, you can set `skip_label: true` option. This will not render label in a field wrapper.
|
476
528
|
|
477
529
|

|
478
530
|
|
@@ -552,7 +604,7 @@ This generates the following HTML:
|
|
552
604
|
</div>
|
553
605
|
```
|
554
606
|
|
555
|
-
You can also disable help text by setting `help_text` option
|
607
|
+
You can also disable help text by setting `help_text: false` option:
|
556
608
|
|
557
609
|

|
558
610
|
|
@@ -707,7 +759,7 @@ This generates the following HTML:
|
|
707
759
|
</div>
|
708
760
|
```
|
709
761
|
|
710
|
-
You can set `switch` option
|
762
|
+
You can set `switch: true` option if you want check box to look like switches.
|
711
763
|
|
712
764
|

|
713
765
|
|
@@ -845,7 +897,7 @@ This generates the following HTML:
|
|
845
897
|
|
846
898
|
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).
|
847
899
|
|
848
|
-
`rails_bootstrap_form` allows us to set `bootstrap` option just like `bootstrap_form_for` and `bootstrap_form_with`. By setting this option on fields_for
|
900
|
+
`rails_bootstrap_form` allows us to set `bootstrap` 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 nested form:
|
849
901
|
|
850
902
|

|
851
903
|
|
@@ -1441,7 +1493,7 @@ an argument and takes care of rendering labels, check boxes, and wrapper for you
|
|
1441
1493
|

|
1442
1494
|
|
1443
1495
|
```erb
|
1444
|
-
<%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap: {layout: :horizontal, inline: true}, onchange: "this.form.submit();"}, {} %>
|
1496
|
+
<%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {multiple: true, bootstrap: {layout: :horizontal, inline: true}, onchange: "this.form.submit();"}, {} %>
|
1445
1497
|
```
|
1446
1498
|
|
1447
1499
|
This generates the following HTML:
|
@@ -1498,6 +1550,8 @@ This generates the following HTML:
|
|
1498
1550
|
</div>
|
1499
1551
|
```
|
1500
1552
|
|
1553
|
+
_If form layout is inline, `collection_check_boxes` always render `inline` check boxes._
|
1554
|
+
|
1501
1555
|
### collection_radio_buttons
|
1502
1556
|
|
1503
1557
|
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
|
@@ -1538,6 +1592,8 @@ This generates the following HTML:
|
|
1538
1592
|
</div>
|
1539
1593
|
```
|
1540
1594
|
|
1595
|
+
_If form layout is inline, `collection_check_boxes` always render `inline` check boxes._
|
1596
|
+
|
1541
1597
|
## Date Helpers
|
1542
1598
|
|
1543
1599
|
The multiple selects that the date and time helpers (`date_select`, `time_select`, `datetime_select`) generate are wrapped inside a `fieldset.rails-bootstrap-forms-[date|time|datetime]-select` tag.
|
@@ -1710,7 +1766,7 @@ This generates the following HTML:
|
|
1710
1766
|
## Submit Buttons
|
1711
1767
|
|
1712
1768
|
`rails_bootstrap_form` allows to easily create submit button for the form. `rails_bootstrap_form` supports three color variants for submit buttons: `secondary`, `primary`, and `danger`. Submit buttons are supported in `vertical`, `horizontal`, and `inline` layout.
|
1713
|
-
Submit buttons in inline form are wrapped inside `div.col-12` to properly
|
1769
|
+
Submit buttons in inline form are wrapped inside `div.col-12` to properly align on small width devices.
|
1714
1770
|
|
1715
1771
|

|
1716
1772
|
|
@@ -1743,7 +1799,7 @@ This generates the following HTML:
|
|
1743
1799
|
<input type="submit" name="commit" value="Register" class="register-button btn btn-primary" data-disable-with="Register">
|
1744
1800
|
```
|
1745
1801
|
|
1746
|
-
To render submit helper as a button helper, you can set `render_as_button` option
|
1802
|
+
To render submit helper as a button helper, you can set `render_as_button: true` option or pass a block.
|
1747
1803
|
|
1748
1804
|

|
1749
1805
|
|
@@ -1786,6 +1842,8 @@ This generates the following HTML:
|
|
1786
1842
|
</div>
|
1787
1843
|
```
|
1788
1844
|
|
1845
|
+
_`static_field` supports all the bootstrap options which are supported by `text_field`._
|
1846
|
+
|
1789
1847
|
## Floating Labels
|
1790
1848
|
|
1791
1849
|
The `floating` option can be used to enable Bootstrap floating labels. This option is supported on text fields, text areas and dropdowns. Here's an example:
|
@@ -1850,7 +1908,7 @@ This generates the following HTML:
|
|
1850
1908
|
</form>
|
1851
1909
|
```
|
1852
1910
|
|
1853
|
-
|
1911
|
+
_`rails_bootstrap_form` automatically disables floating labels for unsupported helpers._
|
1854
1912
|
|
1855
1913
|
## Validation and Errors
|
1856
1914
|
|
@@ -1913,6 +1971,9 @@ This generates the following HTML:
|
|
1913
1971
|
</div>
|
1914
1972
|
```
|
1915
1973
|
|
1974
|
+
The `has-validation` CSS class is added to an input group when the field has errors.
|
1975
|
+
The `is-invalid` CSS class is added to floating label container when field with floating label has errors.
|
1976
|
+
|
1916
1977
|
## Required Fields
|
1917
1978
|
|
1918
1979
|
A label that is associated with a mandatory field is automatically annotated with a `required` CSS class. `rails_bootstrap_form` provides styling for required fields.
|
@@ -72,11 +72,7 @@ module RailsBootstrapForm
|
|
72
72
|
def field_css_options(attribute, bootstrap, options, html_options)
|
73
73
|
css_options = (html_options || options)
|
74
74
|
|
75
|
-
field_classes = Array(options[:class]
|
76
|
-
field_classes << [
|
77
|
-
bootstrap.field_class,
|
78
|
-
bootstrap.additional_field_class
|
79
|
-
]
|
75
|
+
field_classes = Array(bootstrap.field_class) << [bootstrap.additional_field_class || options[:class]]
|
80
76
|
field_classes << "is-invalid" if is_invalid?(attribute)
|
81
77
|
if is_size_valid?(bootstrap)
|
82
78
|
field_classes << "#{bootstrap.field_class}-#{bootstrap.size}"
|
@@ -10,21 +10,23 @@ module RailsBootstrapForm
|
|
10
10
|
def self.included(base_class)
|
11
11
|
[:check_box, :radio_button].each do |tag_name|
|
12
12
|
define_method("#{tag_name}_label") do |attribute, value, options, bootstrap|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
unless bootstrap.skip_label?
|
14
|
+
label_options = {
|
15
|
+
class: choice_label_classes(attribute, bootstrap, options)
|
16
|
+
}
|
17
|
+
label_options[:value] = value if tag_name.eql?(:radio_button)
|
18
|
+
label_options[:for] = options[:id] if options[:id].present?
|
18
19
|
|
19
|
-
|
20
|
+
label_text = label_text(attribute, bootstrap)
|
20
21
|
|
21
|
-
|
22
|
+
label(attribute, label_text, label_options)
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
[:check_box, :radio_button].each do |tag_name|
|
26
28
|
define_method("bootstrap_#{tag_name}") do |attribute, value, options, bootstrap|
|
27
|
-
options[:class] = choice_classes(attribute, options)
|
29
|
+
options[:class] = choice_classes(attribute, bootstrap, options)
|
28
30
|
|
29
31
|
if tag_name.eql?(:check_box)
|
30
32
|
choice_field = check_box_without_bootstrap(attribute, options, value, nil)
|
@@ -38,8 +40,8 @@ module RailsBootstrapForm
|
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
41
|
-
def choice_classes(attribute, options)
|
42
|
-
classes = Array("form-check-input") << options[:class]
|
43
|
+
def choice_classes(attribute, bootstrap, options)
|
44
|
+
classes = Array("form-check-input") << [bootstrap.additional_field_class || options[:class]]
|
43
45
|
classes << "is-invalid" if is_invalid?(attribute)
|
44
46
|
classes.flatten.compact
|
45
47
|
end
|
@@ -45,14 +45,13 @@ module RailsBootstrapForm
|
|
45
45
|
options[:class] = the_class if the_class.present?
|
46
46
|
end
|
47
47
|
|
48
|
-
def remove_css_class!(options, css_class)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
48
|
+
# def remove_css_class!(options, css_class)
|
49
|
+
# the_class = options[:class].to_s.split(" ")
|
50
|
+
# options[:class] = (the_class - [css_class]).compact.join(" ")
|
51
|
+
# options.delete(:class) if options[:class].blank?
|
52
|
+
# end
|
53
53
|
|
54
|
-
private :control_specific_class, :is_size_valid?, :add_css_class
|
55
|
-
:remove_css_class!
|
54
|
+
private :control_specific_class, :is_size_valid?, :add_css_class!
|
56
55
|
end
|
57
56
|
end
|
58
57
|
end
|
@@ -17,7 +17,7 @@ module RailsBootstrapForm
|
|
17
17
|
input_options = {
|
18
18
|
bootstrap: {
|
19
19
|
label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
|
20
|
-
inline: bootstrap.inline?
|
20
|
+
inline: (bootstrap.inline? || bootstrap.layout_inline?)
|
21
21
|
},
|
22
22
|
required: false,
|
23
23
|
id: sanitized_tag_name(attribute, value)
|
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.
|
4
|
+
version: 0.9.4
|
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-
|
11
|
+
date: 2023-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: generator_spec
|