improvement: add set_params option

This commit is contained in:
Zach Daniel 2022-06-10 13:13:50 -04:00
parent 45db36d350
commit d9f2ed5e9a

View file

@ -1510,6 +1510,7 @@ defmodule AshPhoenix.Form do
indexed_lists? = opts[:indexed_lists?] || not is_nil(indexer) || false indexed_lists? = opts[:indexed_lists?] || not is_nil(indexer) || false
transform = opts[:transform] transform = opts[:transform]
produce = opts[:produce] produce = opts[:produce]
set_params = opts[:set_params]
only_touched? = Keyword.get(opts, :only_touched?, true) only_touched? = Keyword.get(opts, :only_touched?, true)
filter = opts[:filter] || fn _ -> true end filter = opts[:filter] || fn _ -> true end
@ -1608,11 +1609,18 @@ defmodule AshPhoenix.Form do
untransformed_params untransformed_params
end end
if transform do with_set_params =
Map.new(with_produced_params, transform) if set_params do
Map.merge(with_produced_params, set_params.(form))
else else
with_produced_params with_produced_params
end end
if transform do
Map.new(with_set_params, transform)
else
with_set_params
end
end end
defp only_touched(form_keys, true, form) do defp only_touched(form_keys, true, form) do