Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: add saveButton stimulus target to save button #3620

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/components/avo/resource_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Avo::ResourceComponent < Avo::BaseComponent
include Avo::Concerns::ChecksAssocAuthorization
include Avo::Concerns::RequestMethods
include Avo::Concerns::HasResourceStimulusControllers

attr_reader :fields_by_panel
attr_reader :has_one_panels
Expand Down Expand Up @@ -190,14 +191,18 @@ def render_delete_button(control)
def render_save_button(control)
return unless can_see_the_save_button?

data_attributes = {
turbo_confirm: @resource.confirm_on_save ? t("avo.are_you_sure") : nil
}

add_stimulus_attributes_for(@resource, data_attributes, "saveButton")

a_button color: :primary,
style: :primary,
loading: true,
type: :submit,
icon: "avo/save",
data: {
turbo_confirm: @resource.confirm_on_save ? t("avo.are_you_sure") : nil
} do
data: data_attributes do
control.label
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/avo/concerns/has_resource_stimulus_controllers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def stimulus_data_attributes
attributes
end

def add_stimulus_attributes_for(entity, attributes)
def add_stimulus_attributes_for(entity, attributes, target_name = nil)
entity.get_stimulus_controllers.split(" ").each do |controller|
attributes["#{controller}-target"] = "#{@field.id.to_s.underscore}_#{@field.type.to_s.underscore}_wrapper".camelize(:lower)
attributes["#{controller}-target"] = target_name || "#{@field.id.to_s.underscore}_#{@field.type.to_s.underscore}_wrapper".camelize(:lower)
end
end
end
Expand Down
Loading