Would nested forms / embedded resources be causing this? (I’ve tried including fields that are not nested, and they also don’t appear in AshPhoenix.Form.params(socket.assigns.form))
(Again, this is only if socket.assigns.form is the form assigned on mount. If I’ve interacted with the form via a validate function or something (passing params from the phx-change action) then params are present)
A specific question: Would you expect a form to have params if it’s straight out of AshPhoenix.Form.for_update(socket.assigns.current_user, :update_settings) ?
Here is my simplified code if it helps. I’ve also pasted a gist (look in handle_event("choose_profile_photo" for the URL) to give some dbg content.
@impl true
def mount(_params, session, socket) do
form = AshPhoenix.Form.for_update(socket.assigns.current_user, :update_settings)
socket
|> assign(:form, form)
|> ok()
end
def render(assigns) do
~H"""
<div>
<.form
:let={f}
for={@form}
id="account-form"
phx-submit="save"
phx-change="validate"
class="max-w-2xl space-y-4"
>
<.error :if={Enum.any?(@form.source.errors)}>
Oops, something went wrong! Please check the errors below. %>
</.error>
<.inputs_for :let={settings} field={f[:settings]}>
<div>
<.label>First Name</.label>
<.input field={settings[:first_name]} />
</div>
<div>
<.label>Profile Photo ID</.label>
<.input field={settings[:profile_photo_id]} />
</div>
<div>
<.label>Profile Photo</.label>
<div class="p-4 border border-gray-200 rounded shadow-md">
<.live_component
module={WinkWeb.EditorComponents.FilePicker}
id="profile-photo-picker"
files_context={@files_context}
selected_file={@form.source.data.settings.profile_photo_id}
file_chosen_callback="choose_profile_photo"
file_position="profile"
allowed_types={["asset"]}
current_view="Assets"
/>
</div>
</div>
</.inputs_for>
<.button type="submit">Save Changes</.button>
</.form>
</div>
"""
end
@impl true
def handle_event("choose_profile_photo", %{"file-id" => file_id}, socket) do
params = AshPhoenix.Form.params(socket.assigns.form)
dbg(params)
# params #=> %{"_form_type" => "update", "id" => "47f9713d-499a-4079-b35b-adba01397a0a"}
dbg(socket.assigns.form)
# gist - https://gist.github.com/alexslade/2ea996d74394b3a344cf0f72e8a0c892
socket
|> noreply()
end
actions do
...
update :update_settings do
accept [:settings, :email]
end
...
end


















