CarlosIribar

CarlosIribar

Name not found in input core component

Hi! I’m new in Phoenix and Liveview. I’m trying to create a form using a changeset but I don’t know why the input core component can’t find the name, id, value, etc key.

Here is my form:

<.simple_form :let={f} for={@changeset |> dbg()} id="promo-form" phx-change="validate" phx-submit="save">
    <.input field={{f, :first_name} |> dbg()} type="text" label="First Name" />
    <.input field={{f, :email}} type="email" label="Email" phx-debounce="blur" />
    <:actions>
      <.button phx-disable-with="Sending...">Send Promo</.button>
    </:actions>
  </.simple_form>

And here is the error:
key :name not found in: %{changed: nil, given: %{changed: nil, field: {%Phoenix.HTML.Form{source: #Ecto.Changeset<action: nil, changes: %{}, errors: [first_name: {“can’t be blank”, [validation: :required]}, email: {“can’t be blank”, [validation: :required]}], data: #Pento.Promo.Recipient<>, valid?: false>, impl: Phoenix.HTML.FormData.Ecto.Changeset, id: “promo-form”, name: “recipient”, data: %Pento.Promo.Recipient{email: nil, first_name: nil}, hidden: , params: %{}, errors: , options: [method: “post”, id: “promo-form”, multipart: false, “phx-change”: “validate”, “phx-submit”: “save”], index: nil, action: nil}, :first_name}, label: “First Name”, type: “text”}, errors: , field: {%Phoenix.HTML.Form{source: #Ecto.Changeset<action: nil, changes: %{}, errors: [first_name: {“can’t be blank”, [validation: :required]}, email: {“can’t be blank”, [validation: :required]}], data: #Pento.Promo.Recipient<>, valid?: false>, impl: Phoenix.HTML.FormData.Ecto.Changeset, id: “promo-form”, name: “recipient”, data: %Pento.Promo.Recipient{email: nil, first_name: nil}, hidden: , params: %{}, errors: , options: [method: “post”, id: “promo-form”, multipart: false, “phx-change”: “validate”, “phx-submit”: “save”], index: nil, action: nil}, :first_name}, id: nil, inner_block: , label: “First Name”, multiple: false, prompt: nil, rest: %{}, type: “text”}

The core component:

def input(assigns) do
    ~H"""
    <div phx-feedback-for={@name}>
      <.label for={@field.id}><%= @label %></.label>
      <input
        type={@type}
        name={@name}
        id={@id}
...

I don’t know if this is because my changeset is schemaless because I this this component working to register a user for example

defmodule Pento.Promo.Recipient do
  import Ecto.Changeset

  @types %{email: :string, first_name: :string}
  defstruct [:email, :first_name]

  def changeset(%__MODULE__{} = user, attrs) do
    {user, @types}
    |> cast(attrs, Map.keys(@types))
    |> validate_required([:first_name, :email])
    |> validate_format(:email, ~r/@/)
  end
end

Marked As Solved

tomkonidas

tomkonidas

Try passing in your input fields like:

field={f[:key_on_changeset]}

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement