Revert "fix: when validating, use empty starting point for forms"

This reverts commit a658a8085b.
This commit is contained in:
Zach Daniel 2022-06-28 23:56:11 -04:00
parent a658a8085b
commit 5c3f3bcb90

View file

@ -847,7 +847,7 @@ defmodule AshPhoenix.Form do
end
new_forms =
Enum.reduce(form_params, %{}, fn {index, params}, forms ->
Enum.reduce(form_params, forms, fn {index, params}, forms ->
case Enum.find(form.forms[key] || [], &matcher.(&1, params, form, key, index)) do
nil ->
create_action =
@ -1516,6 +1516,29 @@ defmodule AshPhoenix.Form do
|> Phoenix.HTML.Form.input_value(field)
end
@doc """
Toggles the form to be ignored or not ignored.
To set this manually in an html form, use the field `:_ignored` and set it
to the string "true". Any other value will not result in the form being ignored.
"""
@spec ignore(t()) :: t()
def ignore(form) do
if ignored?(form) do
%{form | params: Map.delete(form.params, "_ignore")}
else
%{form | params: Map.put(form.params, "_ignore", "true")}
end
end
@doc """
Returns true if the form is ignored
"""
@spec ignored?(t()) :: boolean
def ignored?(form) do
form.params["_ignore"] == "true"
end
@doc """
Returns the parameters from the form that would be submitted to the action.
@ -1534,6 +1557,9 @@ defmodule AshPhoenix.Form do
only_touched? = Keyword.get(opts, :only_touched?, true)
filter = opts[:filter] || fn _ -> true end
if form.params["_hidden"] do
raise "Cannot hide the top level form"
else
form_keys =
form.form_keys
|> Keyword.keys()
@ -1552,7 +1578,8 @@ defmodule AshPhoenix.Form do
if hidden? do
hidden = hidden_fields(form)
hidden_stringified = hidden |> Map.new(fn {field, value} -> {to_string(field), value} end)
hidden_stringified =
hidden |> Map.new(fn {field, value} -> {to_string(field), value} end)
Map.merge(hidden_stringified, params)
else
@ -1660,6 +1687,7 @@ defmodule AshPhoenix.Form do
with_set_params
end
end
end
defp only_touched(form_keys, true, form) do
Enum.filter(form_keys, fn {key, _} ->