-
-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: boolean group field on actions (#2767)
* fix: boolean group field on actions * lint * drop record dependency * lint * performance tweak * fix when empty or unselect all * keep comment * fix dummy action * fix actions spec
- Loading branch information
Showing
5 changed files
with
63 additions
and
29 deletions.
There are no files selected for viewing
33 changes: 13 additions & 20 deletions
33
app/components/avo/fields/boolean_group_field/edit_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/components/avo/fields/boolean_group_field/edit_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::Fields::BooleanGroupField::EditComponent < Avo::Fields::EditComponent | ||
def initialize(...) | ||
super(...) | ||
|
||
# Initilize here to avoid multiple calls to @field.get_html for each option. | ||
@classes = "w-4 h-4 rounded checked:bg-primary-400 focus:checked:!bg-primary-400" \ | ||
"#{@field.get_html(:classes, view: view, element: :input)}" | ||
@data = @field.get_html(:data, view: view, element: :input) | ||
@style = @field.get_html(:style, view: view, element: :input) | ||
@form_scope = @form.object_name | ||
end | ||
|
||
# Get the state of each checkboxe from either the form that returns a validation error or from the model itself. | ||
def checked?(id) | ||
if params[@form_scope].present? && params[@form_scope][@field.id.to_s].present? | ||
params[@form_scope][@field.id.to_s].include?(id.to_s) | ||
elsif @field.value.present? | ||
@field.value[id.to_s] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters