Skip to content

Commit

Permalink
Use to_form :action as changeset action when passed
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Feb 5, 2024
1 parent bb07b9f commit 59fc8ff
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/phoenix_ecto/html.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
if Code.ensure_loaded?(Phoenix.HTML) do
defimpl Phoenix.HTML.FormData, for: Ecto.Changeset do
def to_form(changeset, opts) do
{action, changeset} =
case Keyword.fetch(opts, :action) do
{:ok, action} -> {action, Map.put(changeset, :action, action)}
:error -> {nil, changeset}
end

%{params: params, data: data} = changeset
{name, opts} = Keyword.pop(opts, :as)

Expand All @@ -11,6 +17,7 @@ if Code.ensure_loaded?(Phoenix.HTML) do
source: changeset,
impl: __MODULE__,
id: id,
action: action,
name: name,
errors: form_for_errors(changeset),
data: data,
Expand Down

0 comments on commit 59fc8ff

Please sign in to comment.