Losing entries for nested forms on validate

To reproduce: - Have form for update action with manage_relationship(:resource, type: :direct_control). - Have a button to add new form:
def handle_event("add-form", %{"path" => path}, socket) do
form = AshPhoenix.Form.add_form(socket.assigns.edit_form, path, params: %{})

{:noreply, assign(socket, :edit_form, form)}
end
def handle_event("add-form", %{"path" => path}, socket) do
form = AshPhoenix.Form.add_form(socket.assigns.edit_form, path, params: %{})

{:noreply, assign(socket, :edit_form, form)}
end
- click button, form is added, everything works fine. - make a change in the form, phx-change event is handled:
def handle_event("update_edit_form", params, socket) do
{:noreply, update(socket, :edit_form, &AshPhoenix.Form.validate(&1, params))}
end
def handle_event("update_edit_form", params, socket) do
{:noreply, update(socket, :edit_form, &AshPhoenix.Form.validate(&1, params))}
end
- the nested forms disappear!
Solution:
I think you're missing pattern matching the actual params out
Jump to solution
3 Replies
ZachDaniel
ZachDaniel3mo ago
def handle_event("update_edit_form", %{"form" => params}, socket) do
{:noreply, update(socket, :edit_form, &AshPhoenix.Form.validate(&1, params))}
end
def handle_event("update_edit_form", %{"form" => params}, socket) do
{:noreply, update(socket, :edit_form, &AshPhoenix.Form.validate(&1, params))}
end
Solution
ZachDaniel
ZachDaniel3mo ago
I think you're missing pattern matching the actual params out
rtorresware
rtorreswareOP3mo ago
that works but now the fields that are not nested do not work. I must be missing something related to the component helpers yup, that was it, thanks!

Did you find this page helpful?