Ash FrameworkAF
Ash Framework3y ago
12 replies
Blibs

Manually adding argument to action in form before calling AshPhoenix.Form.submit

I'm using AshPhoenix.Form to handle creation of a resource in LIveView.

In my resource, I added this action:

    create :my_create do
      argument :images, {:array, :map}, allow_nil?: false

      change fn changeset, %{actor: actor} ->
        Ash.Changeset.after_action(changeset, fn changeset ->
          ...
          changeset
        end)
      end
    end


That action now needs to receive a list of images which is a list of maps.

That list is created during the "submit" event after I consume images uploaded:

images =
      consume_uploaded_entries(socket, :images, fn %{path: path}, entry ->
        data = File.read!(path)

        {:ok, %{data: data, client_type: entry.client_type, uuid: entry.uuid}}
      end)

...
# Want to add images to the form as an argument here

case AshPhoenix.Form.submit(form) do
...


So, what I need now is to add the images variable as the :images argument of my :my_create action to my form before calling AshPhoenix.Form.submit.

Is there a way to do that?
Was this page helpful?