Trouble with relationships and form

I have the following:
update :post_task do
argument :task, :map do
allow_nil? false
end

change manage_relationship(:task, :created_tasks, type: :create)
end
update :post_task do
argument :task, :map do
allow_nil? false
end

change manage_relationship(:task, :created_tasks, type: :create)
end
and I want to have a form to post a task. What should the ash form init look like ? Currently I have
socket.assigns.current_user |> AshPhoenix.Form.for_update(:post_task, as: "task")
socket.assigns.current_user |> AshPhoenix.Form.for_update(:post_task, as: "task")
But this is giving me "task is required" error I'm sure I must be doing something wrong and it has to do with the form init. Could someone help ?
9 Replies
sevenseacat
sevenseacat4mo ago
can you share the error, because I don't think it'scoming from that
Quentin
QuentinOP4mo ago
This is my form for reference:
<.form for={@form} id="task" phx-change="validate" phx-submit="save">
<.input field={@form[:title]} type="text" label="Title" required />
<.input field={@form[:price]} type="number" label="Price" required />
<.input field={@form[:description]} type="textarea" label="Description" required />

<.button phx-disable-with="Saving..." variant="primary">Save Task</.button>
<.button navigate={return_path(@return_to, @task)}>Cancel</.button>
</.form>
<.form for={@form} id="task" phx-change="validate" phx-submit="save">
<.input field={@form[:title]} type="text" label="Title" required />
<.input field={@form[:price]} type="number" label="Price" required />
<.input field={@form[:description]} type="textarea" label="Description" required />

<.button phx-disable-with="Saving..." variant="primary">Save Task</.button>
<.button navigate={return_path(@return_to, @task)}>Cancel</.button>
</.form>
@Rebecca Le The error is "task is missing" "task is required" sorry, in the form errors
sevenseacat
sevenseacat4mo ago
right, because your form doesn't have any task fields in it
Quentin
QuentinOP4mo ago
Should I use inputs_for ? It feels odd that I need to do a user update form when I'm trying to create a task
sevenseacat
sevenseacat4mo ago
indeed, that is kind of weird and I'm not sure why you'd do it that way usually you'd have a form to create a task and then use relate_actor to relate it to a user
Quentin
QuentinOP4mo ago
ah I never heard about relate_actor , maybe I'll check this out I kinda wanna understand how to make my setup work without it, though I'm mostly following the relationship docs in the ash docs what if my relationship isn't about the actor
sevenseacat
sevenseacat4mo ago
then yes, you'd probably use add_form to add a task form to the parent form, and use inputs_for to iterate over the (one) task and render fields for it
Quentin
QuentinOP4mo ago
okay cool, I think I'm missing the add_form part

Did you find this page helpful?