fluxbit_view_components 0.4.2 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 762b3796b8dfaa6244369146383b4994f3d5e0c3ba81226606f2a8e2e89b5cb8
4
- data.tar.gz: 98299ec772265f75887e33f74a9d4249dcc18e1548e97ca684ba4bec7a75278a
3
+ metadata.gz: 98187d5ac8174cfe0b38638e43b70e8076ec32068cab920e5829105e0e903f6a
4
+ data.tar.gz: 1e7c9b50861f506bb56407ecdd008988a96c9b8d3f79f75e43fbae7f2642c989
5
5
  SHA512:
6
- metadata.gz: d736f9bc7abfa18e62843b64960de28fe7aec3ece62c90343683548ab821168ce3fa7c3c374592cf71dbc951a0cbf726c9501f1adf550725046b47f123199bb5
7
- data.tar.gz: 30c713c9c039c11e5aa0b3e0b10e13874ca92939c6ed765ac636322c9662a31da92d274af1de33923551bca92a182133996fdf7996eb3de4e369012d56acc30f
6
+ metadata.gz: 426024fbf92e4dd34587a9f14057a541e5f00cb501578026c940ffcc98739398cded786b733c36aa0d1d4de2292ce56b7700e9b93d630c4b15a9e58f9098a1e6
7
+ data.tar.gz: 688a8bec19c6def98088f4e59dc8bd96f46c7fc7818612e799bb77f2f44ebced4dc2055d77b7afcad78b6bbd1b5e0d9c16859fcf4ba62866ff472a15955f4c63
@@ -6,11 +6,7 @@
6
6
  @other_label || (other_label if other_label?)
7
7
  end %>
8
8
 
9
- <% if @form.present? && @attribute.present? %>
10
- <%= @form.check_box(@attribute, **@props) %>
11
- <% else %>
12
- <%= check_box_tag(@name, **@props) %>
13
- <% end %>
9
+ <%= checkbox_without_wrapper %>
14
10
 
15
11
  <span class="<%= toggle_class %>"></span>
16
12
  <%= if @invert_label
@@ -50,6 +50,7 @@ class Fluxbit::Form::ToggleComponent < Fluxbit::Form::FieldComponent
50
50
  @invert_label = options(@props.delete(:invert_label), collection: [ true, false ], default: @@invert_label)
51
51
 
52
52
  add to: @props, first_element: true, class: styles[:input]
53
+ @props[:class] = remove_class(@props.delete(:remove_class) || "", @props[:class])
53
54
  end
54
55
 
55
56
  def valid_color(color)
@@ -78,4 +79,25 @@ class Fluxbit::Form::ToggleComponent < Fluxbit::Form::FieldComponent
78
79
  styles[:toggle][:active][(@props[:disabled] ? :off : :on)]
79
80
  ].compact.join(" ")
80
81
  end
82
+
83
+ # Renders the checkbox without Rails' field_with_errors wrapper
84
+ # We handle errors through help_text instead
85
+ def checkbox_without_wrapper
86
+ return check_box_tag(@name, **@props) unless @form.present? && @attribute.present?
87
+
88
+ # Temporarily remove errors to prevent field_with_errors wrapper
89
+ if @object&.errors&.any? && @object.errors.include?(@attribute)
90
+ # Store the errors for this attribute
91
+ attribute_errors = @object.errors.where(@attribute).to_a
92
+ # Delete them temporarily
93
+ @object.errors.delete(@attribute)
94
+ # Render checkbox without wrapper
95
+ checkbox_html = @form.check_box(@attribute, **@props)
96
+ # Restore the errors
97
+ attribute_errors.each { |error| @object.errors.add(@attribute, error.type, **error.options) }
98
+ checkbox_html
99
+ else
100
+ @form.check_box(@attribute, **@props)
101
+ end
102
+ end
81
103
  end
@@ -1,5 +1,5 @@
1
1
  module Fluxbit
2
2
  module ViewComponents
3
- VERSION = "0.4.2"
3
+ VERSION = "0.4.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluxbit_view_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Molina