Skip to content

Commit

Permalink
Add ability to disable default form wrapper (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
spohlenz authored Nov 13, 2024
1 parent dc8e987 commit bcd5124
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/views/trestle/resource/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
<%= resource_turbo_frame(instance) do %>
<%= trestle_form_for instance, url: admin.actions.include?(:update) ? admin.instance_path(instance, action: :update) : "#", method: :patch do |f| %>
<%= render partial: "form", layout: modal_request? ? "modal" : "layout" %>
<%= render partial: "form", layout: modal_request? ? "modal" : "layout", locals: { wrapper: admin.form.wrapper? } %>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/trestle/resource/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
<%= resource_turbo_frame(instance) do %>
<%= trestle_form_for instance, url: admin.path(:create), method: :post do |f| %>
<%= render partial: "form", layout: modal_request? ? "modal" : "layout" %>
<%= render partial: "form", layout: modal_request? ? "modal" : "layout", locals: { wrapper: admin.form.wrapper? } %>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/trestle/resource/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
<%= resource_turbo_frame(instance) do %>
<%= trestle_form_for instance, url: admin.actions.include?(:update) ? admin.instance_path(instance, action: :update) : "#", method: :patch do |f| %>
<%= render partial: "form", layout: modal_request? ? "modal" : "layout" %>
<%= render partial: "form", layout: modal_request? ? "modal" : "layout", locals: { wrapper: admin.form.wrapper? } %>
<% end %>
<% end %>
4 changes: 4 additions & 0 deletions lib/trestle/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def modal?
options[:modal]
end

def wrapper?
options.fetch(:wrapper, true)
end

def dialog?
Trestle.deprecator.warn("`Trestle::Form#dialog?` is deprecated. Please use `modal?` instead.")
options[:modal]
Expand Down
9 changes: 9 additions & 0 deletions spec/trestle/form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@

it { is_expected.to be_modal }
end

context "without options[:wrapper]" do
it { is_expected.to be_wrapper }
end

context "with options[:wrapper] = false" do
subject(:form) { Trestle::Form.new(wrapper: false) }
it { is_expected.not_to be_wrapper }
end
end

0 comments on commit bcd5124

Please sign in to comment.