Passing validation arguments for the Form's underlying actions

How do I pass arguments in this line? I can't seem to find an example in the docs. AshPhoenix.Form.validate(socket.assigns.form, params) If action :create requires user_id as an argument, is it simply passed by including it in the params? like %{user_id: "12345"}
4 Replies
ZachDaniel
ZachDaniel3y ago
Yep! You can also add the prepare_source argument to set the argument value. prepare_source: fn changeset -> Ash.Changeset.set_argument(changeset, :user_id, user_id) end) You may also need to add force?: true to the submit if user_id is a required argument.
Jason
JasonOP3y ago
Thank you!
ZachDaniel
ZachDaniel3y ago
If you want to associate to the current user, you could also pass the actor option when creating the form, and in the action use change relate_actor(:relationship_name)
Jason
JasonOP3y ago
Cool. Thanks!

Did you find this page helpful?