mirror of
https://github.com/ash-project/ash_phoenix.git
synced 2024-09-20 07:12:49 +12:00
fix: when validating, use empty starting point for forms
This commit is contained in:
parent
de3ad424a3
commit
a658a8085b
1 changed files with 121 additions and 149 deletions
|
@ -847,7 +847,7 @@ defmodule AshPhoenix.Form do
|
|||
end
|
||||
|
||||
new_forms =
|
||||
Enum.reduce(form_params, forms, fn {index, params}, forms ->
|
||||
Enum.reduce(form_params, %{}, fn {index, params}, forms ->
|
||||
case Enum.find(form.forms[key] || [], &matcher.(&1, params, form, key, index)) do
|
||||
nil ->
|
||||
create_action =
|
||||
|
@ -1516,29 +1516,6 @@ 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.
|
||||
|
||||
|
@ -1557,9 +1534,6 @@ 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()
|
||||
|
@ -1578,8 +1552,7 @@ 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
|
||||
|
@ -1687,7 +1660,6 @@ defmodule AshPhoenix.Form do
|
|||
with_set_params
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp only_touched(form_keys, true, form) do
|
||||
Enum.filter(form_keys, fn {key, _} ->
|
||||
|
|
Loading…
Reference in a new issue