improvement: helper functions around ignoring forms

This commit is contained in:
Zach Daniel 2022-06-28 22:31:44 -04:00
parent a554cd9a07
commit 42fec6fab4

View file

@ -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.