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
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
I was wrong
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









