rails_bootstrap_form 0.9.0 → 0.9.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: 15ea5c9f97b548a1fbadb720b875c2a0a784ea6184e77b62af1191865bcef46c
4
- data.tar.gz: 70f4b371a945958580eb8883868a799deb9b189454a1c8bf97ef263905dd0a39
3
+ metadata.gz: 4cc018cfa787b152387078681629abadc1794699ef4151423db7fad244560be7
4
+ data.tar.gz: 4e932a41a3c992a79f766b868d04b655b4fb3aafabb08559caa8714189ac25d0
5
5
  SHA512:
6
- metadata.gz: 82b6509a781a1acd0ac837b1bd51900a2fa023bc1a55870905c25509fc48d674d1ee164ca309c8cf8446dae4364f815bf639ecab14b4c205c60cca0edd2e0a4b
7
- data.tar.gz: f2e4dd5bcd9a4f0f4aa5763d22bc9003118b8f8ad3e56f56c16dc30defd86ea95d877d6b0fdeaca54ffc11eeb32358bf3dd5a388c7165e966c4d9f366d709fef
6
+ metadata.gz: 6738ad4f1381fe2ef85aa87e87b825ac0b0d96a3131f5727a5550361945cf99a9223fbed1b4018f139e89d39c9ab679df3a57b43e8e66dccfd1adb11af4610b6
7
+ data.tar.gz: c6e9250a1ea90b92398a2e3834450fbf6bdcc27f3ab8a5189c394795d53548caca48371f55e91b786bd9c2d05acb2702021d31b8a1fe5f6debaf9b1574611ced
data/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ 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.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.9.0...v0.9.1) - 2023-06-
8
+
9
+ ### What's new
10
+
11
+ - Allow user to configure `options[:multiple]` for `collection_check_boxes`.
12
+ - Added option `inline` to control inline rendering of `collection_check_boxes` and `collection_radio_buttons`.
13
+
14
+ ### What's changed
15
+
16
+ - `wrapper[:class]` will now be appended to existing field wrapper CSS classes ([#29](https://github.com/shivam091/rails_bootstrap_form/issues/29))
17
+
7
18
  ## [0.9.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.8.3...v0.9.0) - 2023-05-31
8
19
 
9
20
  ### 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.9.0)
4
+ rails_bootstrap_form (0.9.1)
5
5
  actionpack (~> 7.0)
6
6
  activemodel (~> 7.0)
7
7
 
data/README.md CHANGED
@@ -836,7 +836,6 @@ Our `fields_for` helper accepts the same arguments as the [default Rails helper]
836
836
  <%= form.check_box :terms, required: true %>
837
837
  <%= form.primary "Register" %>
838
838
  <% end %>
839
-
840
839
  ```
841
840
 
842
841
  This generates the following HTML:
@@ -1412,7 +1411,7 @@ an argument and takes care of rendering labels, check boxes, and wrapper for you
1412
1411
  ![collection_check_boxes](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/c92f5921-e572-4384-812e-31308e018f66)
1413
1412
 
1414
1413
  ```erb
1415
- <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap: {layout: :horizontal}, onchange: "this.form.submit();"}, {} %>
1414
+ <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, {bootstrap: {layout: :horizontal, inline: true}, onchange: "this.form.submit();"}, {} %>
1416
1415
  ```
1417
1416
 
1418
1417
  This generates the following HTML:
@@ -1477,7 +1476,7 @@ an argument and takes care of rendering labels, radio button, and wrapper for yo
1477
1476
  ![collection_radio_buttons](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/798a8b0c-915a-40b1-9874-dd74f50d3695)
1478
1477
 
1479
1478
  ```erb
1480
- <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id, bootstrap: {layout: :horizontal}}, {} %>
1479
+ <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id, bootstrap: {layout: :horizontal, inline: true}}, {} %>
1481
1480
  ```
1482
1481
 
1483
1482
  This generates the following HTML:
@@ -1858,6 +1857,30 @@ This generates the following HTML:
1858
1857
  </form>
1859
1858
  ```
1860
1859
 
1860
+ Inline errors are also supported if the field is wrapped inside of input group and has floating label:
1861
+
1862
+ ![floating_inline_errors](https://github.com/shivam091/rails_bootstrap_form/assets/7858927/89deb618-3f06-463b-91fb-60c50794387c)
1863
+
1864
+ ```erb
1865
+ <%= form.text_field :expected_ctc, bootstrap: {floating: true, prepend: "$", append: "0.0"} %>
1866
+ ```
1867
+
1868
+ This generates the following HTML:
1869
+
1870
+ ```html
1871
+ <div class="mb-3">
1872
+ <div class="input-group has-validation">
1873
+ <span class="input-group-text">$</span>
1874
+ <div class="form-floating is-invalid">
1875
+ <input class="form-control is-invalid" aria-required="true" required="required" placeholder="Expected CTC" type="text" value="" name="user[expected_ctc]" id="user_expected_ctc">
1876
+ <label class="form-label required is-invalid" for="user_expected_ctc">Expected CTC</label>
1877
+ </div>
1878
+ <span class="input-group-text">0.0</span>
1879
+ <div class="invalid-feedback">can't be blank</div>
1880
+ </div>
1881
+ </div>
1882
+ ```
1883
+
1861
1884
  ## Required Fields
1862
1885
 
1863
1886
  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.
@@ -12,9 +12,14 @@
12
12
  <%= form.date_field :birth_date %>
13
13
  <%= form.range_field :excellence %>
14
14
  <%= form.url_field :blog_url %>
15
- <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id} %>
15
+ <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id, bootstrap: {inline: true}} %>
16
16
  <%= form.color_field :favorite_color %>
17
- <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name %>
17
+ <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, multiple: true, bootstrap: {inline: true} %>
18
+ <%= form.number_field :expected_ctc, bootstrap: {prepend: "$", append: "0.0"} %>
19
+ <%= form.date_select :interview_date %>
20
+ <%= form.time_select :interview_time %>
21
+ <%= form.datetime_select :interview_datetime %>
22
+ <%= form.weekday_select :weekly_off %>
18
23
  <%= form.fields_for :address, include_id: false do |address_form| %>
19
24
  <%= address_form.text_area :street %>
20
25
  <%= address_form.text_field :state %>
@@ -12,9 +12,14 @@
12
12
  <%= form.date_field :birth_date %>
13
13
  <%= form.range_field :excellence %>
14
14
  <%= form.url_field :blog_url %>
15
- <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id} %>
15
+ <%= form.collection_radio_buttons :fruit_id, ::Fruit.all, :id, :name, {checked: form.object.fruit_id, bootstrap: {inline: true}} %>
16
16
  <%= form.color_field :favorite_color %>
17
- <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name %>
17
+ <%= form.collection_check_boxes :skill_ids, ::Skill.all, :id, :name, multiple: true, bootstrap: {inline: true} %>
18
+ <%= form.number_field :expected_ctc, bootstrap: {prepend: "$", append: "0.0"} %>
19
+ <%= form.date_select :interview_date %>
20
+ <%= form.time_select :interview_time %>
21
+ <%= form.datetime_select :interview_datetime %>
22
+ <%= form.weekday_select :weekly_off %>
18
23
  <%= form.fields_for :address, include_id: false do |address_form| %>
19
24
  <%= address_form.text_area :street %>
20
25
  <%= address_form.text_field :state %>
@@ -48,19 +48,23 @@ module RailsBootstrapForm
48
48
  end
49
49
 
50
50
  def field_wrapper_options(bootstrap_options)
51
+ wrapper_options = bootstrap_options.wrapper
52
+
51
53
  {}.tap do |option|
52
54
  option[:class] = field_wrapper_classes(bootstrap_options)
53
- end.merge(bootstrap_options.wrapper)
55
+ option.merge!(wrapper_options.except(:class)) if wrapper_options.is_a?(Hash)
56
+ end
54
57
  end
55
58
 
56
59
  def field_wrapper_classes(bootstrap_options)
57
60
  classes = []
58
61
  classes << "row" if bootstrap_options.layout_horizontal?
59
- classes << form_wrapper_default_class(bootstrap_options)
62
+ classes << field_wrapper_default_class(bootstrap_options)
63
+ classes << bootstrap_options.wrapper[:class]
60
64
  classes.flatten.compact
61
65
  end
62
66
 
63
- def form_wrapper_default_class(bootstrap_options)
67
+ def field_wrapper_default_class(bootstrap_options)
64
68
  bootstrap_options.layout_inline? ? "col-12" : "mb-3"
65
69
  end
66
70
 
@@ -99,7 +103,7 @@ module RailsBootstrapForm
99
103
  (bootstrap_options.floating? && !bootstrap_options.layout_horizontal?) || bootstrap_options.layout_inline?
100
104
  end
101
105
 
102
- private :field_wrapper, :field_wrapper_classes, :form_wrapper_default_class,
106
+ private :field_wrapper, :field_wrapper_classes, :field_wrapper_default_class,
103
107
  :field_css_options, :floating_label_classes
104
108
  end
105
109
  end
@@ -28,9 +28,12 @@ module RailsBootstrapForm
28
28
  end
29
29
 
30
30
  def check_box_wrapper_options(bootstrap_options)
31
+ wrapper_options = bootstrap_options.wrapper
32
+
31
33
  {}.tap do |option|
32
- option[:class] = check_box_wrapper_class(bootstrap_options)
33
- end.merge(bootstrap_options.wrapper)
34
+ option[:class] = check_box_wrapper_classes(bootstrap_options)
35
+ option.merge!(wrapper_options.except(:class)) if wrapper_options.is_a?(Hash)
36
+ end
34
37
  end
35
38
 
36
39
  def check_box_label_text(attribute, options, bootstrap_options, &block)
@@ -58,13 +61,14 @@ module RailsBootstrapForm
58
61
  classes.flatten.compact
59
62
  end
60
63
 
61
- def check_box_wrapper_class(bootstrap_options)
64
+ def check_box_wrapper_classes(bootstrap_options)
62
65
  classes = Array("form-check")
63
66
  classes << "form-switch" if bootstrap_options.switch?
64
67
  classes << "form-check-inline" if bootstrap_options.inline?
65
68
  if (bootstrap_options.layout_vertical? && !bootstrap_options.inline?)
66
69
  classes << "mb-3"
67
70
  end
71
+ classes << bootstrap_options.wrapper[:class]
68
72
  classes.flatten.compact
69
73
  end
70
74
 
@@ -75,7 +79,7 @@ module RailsBootstrapForm
75
79
  end
76
80
 
77
81
  private :check_box_label, :check_box_classes, :check_box_label_class,
78
- :check_box_wrapper_class, :check_box_container_classes
82
+ :check_box_wrapper_classes, :check_box_container_classes
79
83
  end
80
84
  end
81
85
  end
@@ -29,9 +29,12 @@ module RailsBootstrapForm
29
29
  end
30
30
 
31
31
  def radio_button_wrapper_options(bootstrap_options)
32
+ wrapper_options = bootstrap_options.wrapper
33
+
32
34
  {}.tap do |option|
33
- option[:class] = radio_button_wrapper_class(bootstrap_options)
34
- end.merge(bootstrap_options.wrapper)
35
+ option[:class] = radio_button_wrapper_classes(bootstrap_options)
36
+ option.merge!(wrapper_options.except(:class)) if wrapper_options.is_a?(Hash)
37
+ end
35
38
  end
36
39
 
37
40
  def radio_button_value(attribute, value)
@@ -55,12 +58,13 @@ module RailsBootstrapForm
55
58
  classes.flatten.compact
56
59
  end
57
60
 
58
- def radio_button_wrapper_class(bootstrap_options)
61
+ def radio_button_wrapper_classes(bootstrap_options)
59
62
  classes = Array("form-check")
60
63
  classes << "form-check-inline" if bootstrap_options.inline?
61
64
  if (bootstrap_options.layout_vertical? && !bootstrap_options.inline?)
62
65
  classes << "mb-3"
63
66
  end
67
+ classes << bootstrap_options.wrapper[:class]
64
68
  classes.flatten.compact
65
69
  end
66
70
 
@@ -71,7 +75,7 @@ module RailsBootstrapForm
71
75
  end
72
76
 
73
77
  private :radio_button_label, :radio_button_classes, :radio_button_label_class,
74
- :radio_button_wrapper_class, :radio_button_container_classes
78
+ :radio_button_wrapper_classes, :radio_button_container_classes
75
79
  end
76
80
  end
77
81
  end
@@ -7,6 +7,32 @@ module RailsBootstrapForm
7
7
  module Base
8
8
  extend ActiveSupport::Concern
9
9
 
10
+ included do
11
+ def inputs_collection(attribute, collection, value_method, text_method, bootstrap_options, options = {})
12
+ inputs = ActiveSupport::SafeBuffer.new
13
+
14
+ collection.each do |object|
15
+ input_options = {
16
+ bootstrap: {
17
+ label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
18
+ help_text: false,
19
+ inline: bootstrap_options.inline?
20
+ }
21
+ }.deep_merge!(options)
22
+
23
+ if (checked = input_options[:checked])
24
+ input_options[:checked] = collection_input_checked?(checked, object, object.send(value_method))
25
+ end
26
+
27
+ input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
28
+
29
+ inputs << yield(attribute, input_value, input_options)
30
+ end
31
+
32
+ inputs
33
+ end
34
+ end
35
+
10
36
  class_methods do
11
37
  def bootstrap_field(field_name)
12
38
  define_method(field_name) do |attribute, options = {}|
@@ -22,7 +22,7 @@ module RailsBootstrapForm
22
22
  check_box_html = tag.div(**check_box_wrapper_options(bootstrap_options)) do
23
23
  concat(check_box_field)
24
24
  concat(check_box_label)
25
- concat(check_box_help_text) unless bootstrap_options.inline?
25
+ concat(check_box_help_text)
26
26
  concat(generate_error(attribute)) if (is_invalid?(attribute) && !bootstrap_options.inline?)
27
27
  end
28
28
 
@@ -12,20 +12,8 @@ module RailsBootstrapForm
12
12
  bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
13
  return super if bootstrap_options.disabled?
14
14
 
15
- options[:multiple] = true
16
-
17
- inputs = ActiveSupport::SafeBuffer.new
18
-
19
- collection.each do |object|
20
- input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
21
- input_options = {
22
- bootstrap: {
23
- label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
24
- inline: true
25
- }
26
- }.deep_merge!(options)
27
-
28
- inputs << check_box(attribute, input_options, input_value, nil)
15
+ inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap_options, options) do |attribute, value, options|
16
+ check_box(attribute, options, value, nil)
29
17
  end
30
18
 
31
19
  if options.delete(:include_hidden) { true }
@@ -12,22 +12,8 @@ module RailsBootstrapForm
12
12
  bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap))
13
13
  return super if bootstrap_options.disabled?
14
14
 
15
- inputs = ActiveSupport::SafeBuffer.new
16
-
17
- collection.each do |object|
18
- input_value = value_method.respond_to?(:call) ? value_method.call(object) : object.send(value_method)
19
- input_options = {
20
- bootstrap: {
21
- label_text: text_method.respond_to?(:call) ? text_method.call(object) : object.send(text_method),
22
- inline: true
23
- }
24
- }.deep_merge!(options)
25
-
26
- if (checked = input_options[:checked])
27
- input_options[:checked] = collection_input_checked?(checked, object, object.send(value_method))
28
- end
29
-
30
- inputs << radio_button(attribute, input_value, input_options)
15
+ inputs = inputs_collection(attribute, collection, value_method, text_method, bootstrap_options, options) do |attribute, value, options|
16
+ radio_button(attribute, value, options)
31
17
  end
32
18
 
33
19
  field_wrapper_builder(attribute, bootstrap_options, options, html_options) do
@@ -22,7 +22,7 @@ module RailsBootstrapForm
22
22
  radio_button_html = tag.div(**radio_button_wrapper_options(bootstrap_options)) do
23
23
  concat(radio_button_field)
24
24
  concat(radio_button_label)
25
- concat(radio_button_help_text) unless bootstrap_options.inline?
25
+ concat(radio_button_help_text)
26
26
  concat(generate_error(attribute)) if (is_invalid?(attribute) && !bootstrap_options.inline?)
27
27
  end
28
28
 
@@ -3,6 +3,6 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- VERSION = "0.9.0".freeze
6
+ VERSION = "0.9.1".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.9.0
4
+ version: 0.9.1
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-31 00:00:00.000000000 Z
11
+ date: 2023-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: generator_spec