mruoss

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

zachdaniel

Creator of Ash

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

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

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.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49084 226
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
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement