bootstrap_form 5.2.0 → 5.2.1

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: 3d296af534429e0065b8f5aef6254dd12455e6317fd36f684b060b3c425c03e8
4
- data.tar.gz: aa02bc3031975302dbe4d556a1fcaa6751e2b4cbb961e737fa23b80516904ea2
3
+ metadata.gz: 9bea3ab95f979a7fc02d2c2a5dff3bae3ca536c6e277a86d11361c3e3bd72e59
4
+ data.tar.gz: 80fa55a6cbcd89ae0b52ebc8135d8b9f38b25b321bdbe492983db46c866c1e7d
5
5
  SHA512:
6
- metadata.gz: 0a402ef41606092aa37ec284382f754aea85d73dfc16b8b065ea130c6d47910d061afac644a0b0d38f1269f0c53caa2f987c8b5d4ce9dfa6105811919a40bc8f
7
- data.tar.gz: 546e5dbb15379578c5f06a4d6d40a362bd08d9dc4049cd4a7140cc7b29f459bfc8f914d8e114125d398be8b323102d4912653d589e008441eb288dda71fb0ebd
6
+ metadata.gz: a97b0ddfb9afcfb847b27ea4853c4f3b99bb0c72a0366d4d1a0a3fac217f0693090c96ea03c51e3a07e66cfe3c8c4576be8618eb3b48401c6d6f326e35619fa7
7
+ data.tar.gz: 3d79f681187a5fa0cab604ced1919229cdbdd101cc8f91c4261a115b82fa5589c3037b8b0c6d6208ce17affe964397a8fc33a9483a82a5c74efd22c9224eb582
data/CHANGELOG.md CHANGED
@@ -7,6 +7,8 @@ https://github.com/bootstrap-ruby/bootstrap_form/releases
7
7
  ## Diffs
8
8
 
9
9
  - [Pending Release](https://github.com/bootstrap-ruby/bootstrap_form/compare/v5.2.0...HEAD)
10
+ - [5.2.1](https://github.com/bootstrap-ruby/bootstrap_form/compare/v5.2.0...v5.2.1)
11
+ [Issues](https://github.com/bootstrap-ruby/bootstrap_form/issues?q=closed%3A2023-05-20T23%3A59..2023-05-23T10%3A00)
10
12
  - [5.2.0](https://github.com/bootstrap-ruby/bootstrap_form/compare/v5.1.0...v5.2.0)
11
13
  [Issues](https://github.com/bootstrap-ruby/bootstrap_form/issues?q=closed%3A2022-06-25T17%3A22..2023-05-20T23%3A59)
12
14
  - [5.1.0](https://github.com/bootstrap-ruby/bootstrap_form/compare/v5.0.0...v5.1.0)
data/README.md CHANGED
@@ -125,8 +125,6 @@ This generates:
125
125
 
126
126
  ### bootstrap_form_with
127
127
 
128
- Note that `form_with` in Rails 5.1 does not add IDs to form elements and labels by default, which are both important to Bootstrap markup. This behaviour is corrected in Rails 5.2.
129
-
130
128
  To get started, just use the `bootstrap_form_with` helper in place of `form_with`. Here's an example:
131
129
 
132
130
  ![Example 2](demo/doc/screenshots/bootstrap/readme/02_example.png "Example 2")
@@ -200,7 +198,7 @@ date_field password_field time_field
200
198
  date_select phone_field time_select
201
199
  datetime_field radio_button time_zone_select
202
200
  datetime_local_field range_field url_field
203
- datetime_select rich_text_area (Rails 6+) week_field
201
+ datetime_select rich_text_area week_field
204
202
  ```
205
203
 
206
204
  By default, the helpers generate a `label` tag, and an `input`, `select`, or `textarea` tag, by calling the Rails `label` helper, and then the Rails helper with the same name as the `bootstrap_form` helper.
@@ -753,7 +751,7 @@ This generates:
753
751
  ```html
754
752
  <div class="mb-3">
755
753
  <label class="form-label" for="user_excellence">Excellence</label>
756
- <input class="form-control" id="user_excellence" name="user[excellence]" type="range">
754
+ <input class="form-range" id="user_excellence" name="user[excellence]" type="range">
757
755
  </div>
758
756
  ```
759
757
 
@@ -946,8 +944,6 @@ will be rendered as
946
944
 
947
945
  ## Rich Text Areas AKA Trix Editor
948
946
 
949
- If you're using Rails 6, `bootstrap_form` supports the `rich_text_area` helper.
950
-
951
947
  ![Example 34](demo/doc/screenshots/bootstrap/readme/34_example.png "Example 34")
952
948
  ```erb
953
949
  <%= f.rich_text_area(:life_story) %>
@@ -1369,18 +1365,29 @@ Rails normally wraps fields with validation errors in a `div.field_with_errors`,
1369
1365
  By default, fields that have validation errors will be outlined in red and the
1370
1366
  error will be displayed below the field. Here's an example:
1371
1367
 
1368
+ ![Example 44](demo/doc/screenshots/bootstrap/readme/44_example.png "Example 44")
1369
+ ```erb
1370
+ <%= bootstrap_form_for(@user_with_error) do |f| %>
1371
+ <%= f.email_field :email %>
1372
+ <% end %>
1373
+ ```
1374
+
1375
+ Generated HTML:
1376
+
1372
1377
  ```html
1373
- <div class="mb-3">
1374
- <label class="form-label form-control-label" for="user_email">Email</label>
1375
- <input class="form-control is-invalid" id="user_email" name="user[email]" type="email" value="">
1376
- <small class="invalid-feedback">can't be blank</small>
1377
- </div>
1378
+ <form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
1379
+ <div class="mb-3">
1380
+ <label class="form-label required" for="user_email">Email</label>
1381
+ <input aria-required="true" class="form-control is-invalid" id="user_email" name="user[email]" required="required" type="email" value="steve.example.com">
1382
+ <div class="invalid-feedback">is invalid</div>
1383
+ </div>
1384
+ </form>
1378
1385
  ```
1379
1386
 
1380
1387
  You can turn off inline errors for the entire form like this:
1381
1388
 
1382
1389
  ```erb
1383
- <%= bootstrap_form_for(@user, inline_errors: false) do |f| %>
1390
+ <%= bootstrap_form_for(@user_with_error, inline_errors: false) do |f| %>
1384
1391
  ...
1385
1392
  <% end %>
1386
1393
  ```
@@ -1390,12 +1397,24 @@ You can turn off inline errors for the entire form like this:
1390
1397
  You can also display validation errors in the field's label; just turn
1391
1398
  on the `:label_errors` option. Here's an example:
1392
1399
 
1400
+ ![Example 45](demo/doc/screenshots/bootstrap/readme/45_example.png "Example 45")
1393
1401
  ```erb
1394
- <%= bootstrap_form_for(@user, label_errors: true) do |f| %>
1395
- ...
1402
+ <%= bootstrap_form_for(@user_with_error, label_errors: true) do |f| %>
1403
+ <%= f.email_field :email %>
1396
1404
  <% end %>
1397
1405
  ```
1398
1406
 
1407
+ Generated HTML:
1408
+
1409
+ ```html
1410
+ <form accept-charset="UTF-8" action="/users" class="new_user" id="new_user" method="post">
1411
+ <div class="mb-3">
1412
+ <label class="form-label required text-danger" for="user_email">Email is invalid</label>
1413
+ <input aria-required="true" class="form-control is-invalid" id="user_email" name="user[email]" required="required" type="email" value="steve.example.com">
1414
+ </div>
1415
+ </form>
1416
+ ```
1417
+
1399
1418
  By default, turning on `:label_errors` will also turn off
1400
1419
  `:inline_errors`. If you want both turned on, you can do that too:
1401
1420
 
@@ -1411,7 +1430,7 @@ To display an error message with an error summary, you can use the
1411
1430
  `alert_message` helper. This won't output anything unless a model validation
1412
1431
  has failed.
1413
1432
 
1414
- ![Example 44](demo/doc/screenshots/bootstrap/readme/44_example.png "Example 44")
1433
+ ![Example 46](demo/doc/screenshots/bootstrap/readme/46_example.png "Example 46")
1415
1434
  ```erb
1416
1435
  <%= bootstrap_form_for @user_with_error do |f| %>
1417
1436
  <%= f.alert_message "Please fix the errors below." %>
@@ -1434,7 +1453,7 @@ Which outputs:
1434
1453
 
1435
1454
  You can turn off the error summary like this:
1436
1455
 
1437
- ![Example 45](demo/doc/screenshots/bootstrap/readme/45_example.png "Example 45")
1456
+ ![Example 47](demo/doc/screenshots/bootstrap/readme/47_example.png "Example 47")
1438
1457
  ```erb
1439
1458
  <%= bootstrap_form_for @user_with_error do |f| %>
1440
1459
  <%= f.alert_message "Please fix the errors below.", error_summary: false %>
@@ -1451,7 +1470,7 @@ This generates:
1451
1470
 
1452
1471
  To output a simple unordered list of errors, use the `error_summary` helper.
1453
1472
 
1454
- ![Example 46](demo/doc/screenshots/bootstrap/readme/46_example.png "Example 46")
1473
+ ![Example 48](demo/doc/screenshots/bootstrap/readme/48_example.png "Example 48")
1455
1474
  ```erb
1456
1475
  <%= bootstrap_form_for @user_with_error do |f| %>
1457
1476
  <%= f.error_summary %>
@@ -1473,7 +1492,7 @@ Which outputs:
1473
1492
 
1474
1493
  If you want to display a custom inline error for a specific attribute not represented by a form field, use the `errors_on` helper.
1475
1494
 
1476
- ![Example 47](demo/doc/screenshots/bootstrap/readme/47_example.png "Example 47")
1495
+ ![Example 49](demo/doc/screenshots/bootstrap/readme/49_example.png "Example 49")
1477
1496
  ```erb
1478
1497
  <%= bootstrap_form_for @user_with_error do |f| %>
1479
1498
  <%= f.errors_on :email %>
@@ -1490,7 +1509,7 @@ Which outputs:
1490
1509
 
1491
1510
  You can hide the attribute name like this:
1492
1511
 
1493
- ![Example 48](demo/doc/screenshots/bootstrap/readme/48_example.png "Example 48")
1512
+ ![Example 50](demo/doc/screenshots/bootstrap/readme/50_example.png "Example 50")
1494
1513
  ```erb
1495
1514
  <%= bootstrap_form_for @user_with_error do |f| %>
1496
1515
  <%= f.errors_on :email, hide_attribute_name: true %>
@@ -1507,7 +1526,7 @@ Which outputs:
1507
1526
 
1508
1527
  You can also use a custom class for the wrapping div, like this:
1509
1528
 
1510
- ![Example 49](demo/doc/screenshots/bootstrap/readme/49_example.png "Example 49")
1529
+ ![Example 51](demo/doc/screenshots/bootstrap/readme/51_example.png "Example 51")
1511
1530
  ```erb
1512
1531
  <%= bootstrap_form_for @user_with_error do |f| %>
1513
1532
  <%= f.errors_on :email, custom_class: 'custom-error' %>
@@ -1542,7 +1561,7 @@ ActiveModel::Validations::PresenceValidator.
1542
1561
 
1543
1562
  In cases where this behaviour is undesirable, use the `required` option to force the class to be present or absent:
1544
1563
 
1545
- ![Example 50](demo/doc/screenshots/bootstrap/readme/50_example.png "Example 50")
1564
+ ![Example 52](demo/doc/screenshots/bootstrap/readme/52_example.png "Example 52")
1546
1565
  ```erb
1547
1566
  <%= f.password_field :login, label: "New Username", required: true %>
1548
1567
  <%= f.password_field :password, label: "New Password", required: false %>
@@ -1565,7 +1584,7 @@ This generates:
1565
1584
 
1566
1585
  Adding a form control for a `belongs_to` field will automatically pick up the associated presence validator.
1567
1586
 
1568
- ![Example 51](demo/doc/screenshots/bootstrap/readme/51_example.png "Example 51")
1587
+ ![Example 53](demo/doc/screenshots/bootstrap/readme/53_example.png "Example 53")
1569
1588
  ```erb
1570
1589
  <%= bootstrap_form_for(@address, url: '/address') do |f| %>
1571
1590
  <%= f.collection_select :user_id, @users, :id, :email, include_blank: "Select a value" %>
@@ -12,7 +12,7 @@ module BootstrapForm
12
12
  end
13
13
 
14
14
  def association_error?(name)
15
- object.class.reflections.any? do |association_name, a|
15
+ object.class.try(:reflections)&.any? do |association_name, a|
16
16
  next unless a.is_a?(ActiveRecord::Reflection::BelongsToReflection)
17
17
  next unless a.foreign_key == name.to_s
18
18
 
@@ -31,7 +31,7 @@ module BootstrapForm
31
31
  end
32
32
 
33
33
  def required_association?(target, attribute)
34
- target.reflections.find do |name, a|
34
+ target.try(:reflections)&.find do |name, a|
35
35
  next unless a.is_a?(ActiveRecord::Reflection::BelongsToReflection)
36
36
  next unless a.foreign_key == attribute.to_s
37
37
 
@@ -65,7 +65,7 @@ module BootstrapForm
65
65
 
66
66
  def get_error_messages(name)
67
67
  messages = object.errors[name]
68
- object.class.reflections.each do |association_name, a|
68
+ object.class.try(:reflections)&.each do |association_name, a|
69
69
  next unless a.is_a?(ActiveRecord::Reflection::BelongsToReflection)
70
70
  next unless a.foreign_key == name.to_s
71
71
 
@@ -33,7 +33,7 @@ module BootstrapForm
33
33
  include BootstrapForm::Inputs::PhoneField
34
34
  include BootstrapForm::Inputs::RadioButton
35
35
  include BootstrapForm::Inputs::RangeField
36
- include BootstrapForm::Inputs::RichTextArea if Rails::VERSION::MAJOR >= 6
36
+ include BootstrapForm::Inputs::RichTextArea
37
37
  include BootstrapForm::Inputs::SearchField
38
38
  include BootstrapForm::Inputs::Select
39
39
  include BootstrapForm::Inputs::TelephoneField
@@ -6,8 +6,8 @@ module BootstrapForm
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  class_methods do
9
- def bootstrap_field(field_name)
10
- define_method "#{field_name}_with_bootstrap" do |name, options={}|
9
+ def bootstrap_field(field_name, control_class: nil)
10
+ define_method "#{field_name}_with_bootstrap" do |name, options={ control_class: control_class }.compact|
11
11
  form_group_builder(name, options) do
12
12
  prepend_and_append_input(name, options) do
13
13
  options[:placeholder] ||= name if options[:floating]
@@ -7,7 +7,7 @@ module BootstrapForm
7
7
  include Base
8
8
 
9
9
  included do
10
- bootstrap_field :range_field
10
+ bootstrap_field :range_field, control_class: "form-range"
11
11
  end
12
12
  end
13
13
  end
@@ -25,7 +25,7 @@ module BootstrapForm
25
25
  autoload :PhoneField
26
26
  autoload :RadioButton
27
27
  autoload :RangeField
28
- autoload :RichTextArea if Rails::VERSION::MAJOR >= 6
28
+ autoload :RichTextArea
29
29
  autoload :SearchField
30
30
  autoload :Select
31
31
  autoload :TelephoneField
@@ -1,4 +1,4 @@
1
1
  module BootstrapForm
2
- VERSION = "5.2.0".freeze
2
+ VERSION = "5.2.1".freeze
3
3
  REQUIRED_RAILS_VERSION = ">= 6.0".freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Potenza
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-05-20 00:00:00.000000000 Z
12
+ date: 2023-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack