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.

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.

1 Like

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.

1 Like