bootstrap_concerns 0.5.6 → 0.5.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c462b0648718081a4f8a1bd1669b1c3e3f9707ff2b5320f71fcefaabc7481cb
4
- data.tar.gz: 3b51a9f3f0612d7fd98507ccc5b3718bfbff2cf404d32939a926a0f009da9c23
3
+ metadata.gz: 707af3be707adde6b5fd86783f9d950253315464cd906e6a65057537f13cc9ff
4
+ data.tar.gz: c072837ef9eb4547bf7a460b6ba94d18e3ef7b18b7b5749c84ef6fe295725973
5
5
  SHA512:
6
- metadata.gz: 72ae80b00c79d9bd8429cb4bec74545d877a1c414e8482dc9d3e4146d0aa40cb3e78b5871712506e222a0885e4470f374bfc8efbdff955c17394a952759aa548
7
- data.tar.gz: 7172244a7b5e848aa726e9bc2c8407ee86dc20c7a3a2a2a7f02bd52af80ca9752298ac0430c0184d64d745024616e92bd7122ba8586bdcfa880116b6c2c27301
6
+ metadata.gz: 8869c35220c6cb217d9532ca0ab6517860071e001b3a74fd1f527811d804fb7cfe9bca893dc8a7c2e7a9c426259254cd45572315275113931f1299f0c71586f7
7
+ data.tar.gz: 937efce856f940a04d3dc37a1503a32f36fd0b43b70a39af46e2680083e265e58e0f86536047a89716f264dee0b972c457b92812b798f61a67db407b9edca83b
@@ -7,6 +7,8 @@ module BootstrapConcerns
7
7
  FORM_SELECT_BASE_CLASS = "form-select".freeze
8
8
  REQUIRED_CLASS = "required".freeze
9
9
 
10
+ delegate :content_tag, :concat, to: :@template, private: true
11
+
10
12
  def bs_button(value = nil, options = {}, &)
11
13
  normalized_options = value.is_a?(Hash) ? value : options
12
14
  normalized_options.deep_merge!(Option.options_with_button_class(normalized_options))
@@ -53,11 +55,21 @@ module BootstrapConcerns
53
55
  end
54
56
 
55
57
  def bs_form_group(method, type, *args)
56
- options = args.find { it.is_a?(Hash) && it.has_key?(:required) }.to_h
57
-
58
- @template.content_tag(:div, class: ComponentsHelper::MARGIN) do
59
- @template.concat bs_label(method, options.slice(:required))
60
- @template.concat public_send("bs_#{type}", method, *args)
58
+ options = args.find { it.is_a?(Hash) && it.key?(:required) }.to_h
59
+ input_group = args.find { it.is_a?(Hash) && it[:input_group] } || {}
60
+ input_group_flag = input_group[:input_group].present?
61
+
62
+ content_tag(:div, class: ComponentsHelper::MARGIN) do
63
+ concat bs_label(method, options.slice(:required))
64
+ if input_group_flag
65
+ concat(content_tag(:div, class: "input-group") do
66
+ public_send("bs_#{type}", method, *args)
67
+ end)
68
+ concat error_message(method, outside: true)
69
+ else
70
+ concat(public_send("bs_#{type}", method, *args))
71
+ concat error_message(method)
72
+ end
61
73
  end
62
74
  end
63
75
 
@@ -165,6 +177,14 @@ module BootstrapConcerns
165
177
 
166
178
  private
167
179
 
180
+ def error_message(method, outside: false)
181
+ return "".html_safe if object.errors[method].blank?
182
+
183
+ classes = ["invalid-feedback"]
184
+ classes << "d-block" if outside
185
+ content_tag(:div, object.errors[method].join(", "), class: classes.join(" "))
186
+ end
187
+
168
188
  def options_with_form_check_input_class(options)
169
189
  Option.options_with_base_class(options, FORM_CHECK_INPUT_BASE_CLASS)
170
190
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_concerns
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Brooks