Skip to content

Commit ba6578f

Browse files
authored
enhancement: add target to save button (#3620)
1 parent 5e41f9a commit ba6578f

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

app/components/avo/resource_component.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
class Avo::ResourceComponent < Avo::BaseComponent
22
include Avo::Concerns::ChecksAssocAuthorization
33
include Avo::Concerns::RequestMethods
4+
include Avo::Concerns::HasResourceStimulusControllers
45

56
attr_reader :fields_by_panel
67
attr_reader :has_one_panels
@@ -190,14 +191,18 @@ def render_delete_button(control)
190191
def render_save_button(control)
191192
return unless can_see_the_save_button?
192193

194+
data_attributes = {
195+
turbo_confirm: @resource.confirm_on_save ? t("avo.are_you_sure") : nil
196+
}
197+
198+
add_stimulus_attributes_for(@resource, data_attributes, "saveButton")
199+
193200
a_button color: :primary,
194201
style: :primary,
195202
loading: true,
196203
type: :submit,
197204
icon: "avo/save",
198-
data: {
199-
turbo_confirm: @resource.confirm_on_save ? t("avo.are_you_sure") : nil
200-
} do
205+
data: data_attributes do
201206
control.label
202207
end
203208
end

lib/avo/concerns/has_resource_stimulus_controllers.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def stimulus_data_attributes
3838
attributes
3939
end
4040

41-
def add_stimulus_attributes_for(entity, attributes)
41+
def add_stimulus_attributes_for(entity, attributes, target_name = nil)
4242
entity.get_stimulus_controllers.split(" ").each do |controller|
43-
attributes["#{controller}-target"] = "#{@field.id.to_s.underscore}_#{@field.type.to_s.underscore}_wrapper".camelize(:lower)
43+
attributes["#{controller}-target"] = target_name || "#{@field.id.to_s.underscore}_#{@field.type.to_s.underscore}_wrapper".camelize(:lower)
4444
end
4545
end
4646
end

0 commit comments

Comments
 (0)