rapidfsub

rapidfsub

Prepare_params vs. transform_params in ash_phoenix?

* `:prepare_params` - A 2-argument function that receives the params map and the :validate atom and should return prepared params. Called before the form is validated.
* `:transform_params` - A function for post-processing the form parameters before they are used for changeset validation/submission. Use a 3-argument function to pattern match on the [`AshPhoenix.Form`](https://hexdocs.pm/ash_phoenix/AshPhoenix.Form.html) struct. 

prepare_params is called before the "form validation, and transform_params is called before "changeset validation.
But I don’t get what’s different between “form validation” and “changeset validation”.

Marked As Solved

zachdaniel

zachdaniel

Creator of Ash

prepare_params happens just before we handle nested forms, and gets called w/ all top level params, so is the simplest place to modify params.

transform_params is a bit more complex as it allows distinguishing between “is this a nested form” and pattern matching on the form struct who’s params you are modifying.

When in doubt, use prepare_params as a simple callback to modify the params the user submitted before handled by the form.

Also Liked

zachdaniel

zachdaniel

Creator of Ash

I was wrong :smiley: transform_params is the preferred approach. Misremembered my own implementation. We’ll update the docs. @sevenseacat reminded me of that.

Sorry for misleading you earlier! Neither one is called for nested forms automatically.

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement