mirror of
https://github.com/ash-project/ash_phoenix.git
synced 2024-09-20 07:12:49 +12:00
improvement: helper functions around ignoring forms
This commit is contained in:
parent
a554cd9a07
commit
42fec6fab4
1 changed files with 23 additions and 0 deletions
|
@ -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.
|
||||
|
||||
|
|
Loading…
Reference in a new issue