Skip to content

Commit

Permalink
enhancement: add target to save button (#3620)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob authored Jan 30, 2025
1 parent 5e41f9a commit ba6578f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
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

0 comments on commit ba6578f

Please sign in to comment.