I’ve been playing with Phoenix for a while now and I’ve encountered a problem that I simply don’t understand, so I decided to ask for help.
The entirety of the code base can be found here
The core of the issue is here, the error:
Request: GET /users/two_factor
** (exit) an exception was raised:
** (KeyError) key :name not found in: %{__changed__: nil, __given__: %{__changed__: nil, field: {%Phoenix.HTML.Form{source: :user, impl: Phoenix.HTML.FormData.Atom, id: "verify-2fa-auth", name: "user", data: %{}, hidden: [], params: %{}, errors: [], options: [as: nil, id: "verify-2fa-auth", multipart: false, "phx-submit": "verify"], index: nil, action: nil}, :verification}, type: "text"}, errors: [], field: {%Phoenix.HTML.Form{source: :user, impl: Phoenix.HTML.FormData.Atom, id: "verify-2fa-auth", name: "user", data: %{}, hidden: [], params: %{}, errors: [], options: [as: nil, id: "verify-2fa-auth", multipart: false, "phx-submit": "verify"], index: nil, action: nil}, :verification}, id: nil, inner_block: [], label: nil, multiple: false, prompt: nil, rest: %{required: true}, type: "text"}
(another_test 0.1.0) lib/another_test_web/components/core_components.ex:399: anonymous fn/2 in AnotherTestWeb.CoreComponents."input (overridable 1)"/1
(another_test 0.1.0) /home/bmorriso/local-repo/livesaastestagain/another_test/lib/another_test_web/live/user_two_factor_live.ex:24: AnotherTestWeb.UserTwoFactorLive.render/1
(elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 0.19.1) lib/phoenix_live_view/diff.ex:383: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 0.19.1) lib/phoenix_live_view/diff.ex:537: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 0.19.1) lib/phoenix_live_view/diff.ex:383: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 0.19.1) lib/phoenix_live_view/diff.ex:537: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 0.19.1) lib/phoenix_live_view/diff.ex:383: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 0.19.1) lib/phoenix_live_view/diff.ex:537: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 0.19.1) lib/phoenix_live_view/diff.ex:383: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 0.19.1) lib/phoenix_live_view/diff.ex:537: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 0.19.1) lib/phoenix_live_view/diff.ex:383: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 0.19.1) lib/phoenix_live_view/diff.ex:537: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.14.3) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
The code for this view: (Full source code here defmodule)
<.simple_form :let={f} for={:user} id="verify-2fa-auth" phx-submit="verify">
<.input field={{f, :verification}} type="text" required />
<:actions>
<.button class="w-full" phx-disable-with="Sending...">Verify</.button>
</:actions>
</.simple_form>
The core_components.ex (full source code here)
def input(assigns) do
~H"""
<div phx-feedback-for={@name} class="space-y-2">
<.label for={@id}><%= @label %></.label>
<input
type={@type}
name={@name}
id={@id || @name}
value={Phoenix.HTML.Form.normalize_value(@type, @value)}
class={[
"block w-full p-2.5 bg-gray-50 text-sm rounded-lg border border-gray-300 text-gray-900",
"focus:ring-4 focus:ring-blue-500/5 focus:border-blue-500",
"dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500/5 dark:focus:border-blue-500",
"phx-no-feedback:border-gray-300 phx-no-feedback:focus:border-blue-500 phx-no-feedback:focus:ring-blue-500/5",
"phx-no-feedback:dark:border-gray-600 phx-no-feedback:dark:focus:border-blue-500 phx-no-feedback:dark:focus:ring-blue-500/5",
@errors != [] &&
"text-red-900 placeholder-red-700 border-red-500 focus:ring-red-500 focus:border-red-500 dark:text-red-500 dark:placeholder-red-500 dark:border-red-500"
]}
{@rest}
/>
<.error :for={msg <- @errors}><%= msg %></.error>
</div>
"""
end
Thank you for your time.