hannes
hannes
AEAsh Elixir
Created by hannes on 2/5/2023 in #support
Calculations and AshPhoenix.Form
Thanks for the quick reply! It works! 🙂
12 replies
AEAsh Elixir
Created by hannes on 2/5/2023 in #support
Calculations and AshPhoenix.Form
Screenshot of the form
12 replies
AEAsh Elixir
Created by hannes on 2/5/2023 in #support
Calculations and AshPhoenix.Form
I already got it working with the following helper but I'm wondering if this is the right way:
defp vacation_days_hint(%AshPhoenix.Form{} = form) do
with {:ok, contract} <- Ash.Changeset.apply_attributes(form.source, force?: true),
{:ok, contract} <- MyApp.Users.load(contract, [:emp_percent, :vac_days_eff]),
%Decimal{} <- contract.vac_days_eff,
%Decimal{} <- contract.emp_percent do
"#{format(contract.vac_days_eff, :day)} at #{format(contract.emp_percent, :percent)}"
else
_ -> nil
end
end
defp vacation_days_hint(%AshPhoenix.Form{} = form) do
with {:ok, contract} <- Ash.Changeset.apply_attributes(form.source, force?: true),
{:ok, contract} <- MyApp.Users.load(contract, [:emp_percent, :vac_days_eff]),
%Decimal{} <- contract.vac_days_eff,
%Decimal{} <- contract.emp_percent do
"#{format(contract.vac_days_eff, :day)} at #{format(contract.emp_percent, :percent)}"
else
_ -> nil
end
end
12 replies