mruoss
Form fields for `TypedStruct` action arguments
Hey there, I’m playing with Ash and TypedStructs. I defined an update action on a resource which takes a TypedStruct as argunent:
With SessionsByInterval being the TypedStruct:
update :set_sessions do
argument :sessions, SessionsByInterval, allow_nil?: false
end
Now in LiveView, I’d like to create a form for this action. How do I render this form? If I use <.inputs_for on @form[:sessions], I get a AshPhoenix.Form.NoFormConfigured.
Marked As Solved
zachdaniel
Ah, yeah so that logic for nested forms currently only works for embedded resources, not for simple map types like that. We’d need to add support for that in AshPhoenix.
Other than that you have some options, like:
<.input ... name={@form.name <> "[sessions][0][name]"} id={@form.id <> "_sessions_0_name"}, ....>
Which really isn’t ideal. We could add this to AshPhoenix but its not super trivial, so converting your TypedStruct into embedded resources is probably the best way to go for now.
Also Liked
mruoss
Thanks a lot for the fast reply.
Yeah at some point I figured it might not be doable/simple. In my case it was easiest to just ditch the TypedStruct and make its fields separate args to the action.
Last Post!
mruoss
Thanks a lot for the fast reply.
Yeah at some point I figured it might not be doable/simple. In my case it was easiest to just ditch the TypedStruct and make its fields separate args to the action.
Popular in Questions
Other popular topics
Latest Ash Threads
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
- #forms
- #api
- #metaprogramming
- #security
- #hex









